mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
changes for new messaging
This commit is contained in:
parent
7c1549bb95
commit
480f954433
4 changed files with 44 additions and 60 deletions
21
src/App/Services/MobileBroadcasterMessagingService.cs
Normal file
21
src/App/Services/MobileBroadcasterMessagingService.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.Domain;
|
||||
|
||||
namespace Bit.App.Services
|
||||
{
|
||||
public class MobileBroadcasterMessagingService : IMessagingService
|
||||
{
|
||||
private readonly IBroadcasterService _broadcasterService;
|
||||
|
||||
public MobileBroadcasterMessagingService(IBroadcasterService broadcasterService)
|
||||
{
|
||||
_broadcasterService = broadcasterService;
|
||||
}
|
||||
|
||||
public void Send(string subscriber, object arg = null)
|
||||
{
|
||||
var message = new Message { Command = subscriber, Data = arg };
|
||||
_broadcasterService.Send(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
using Bit.Core.Abstractions;
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Services
|
||||
{
|
||||
public class MobileBroadcasterService : IBroadcasterService
|
||||
{
|
||||
public void Send<T>(T message, string id = null)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
throw new NotSupportedException("Cannot send a message to all subscribers.");
|
||||
}
|
||||
MessagingCenter.Send(Application.Current, id, message);
|
||||
}
|
||||
|
||||
public void Subscribe<T>(string id, Action<T> messageCallback)
|
||||
{
|
||||
MessagingCenter.Subscribe<Application, T>(Application.Current, id,
|
||||
(sender, message) => messageCallback(message));
|
||||
}
|
||||
|
||||
public void Unsubscribe(string id)
|
||||
{
|
||||
MessagingCenter.Unsubscribe<Application, object>(Application.Current, id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using Bit.Core.Abstractions;
|
||||
|
||||
namespace Bit.App.Services
|
||||
{
|
||||
public class MobileMessagingService : IMessagingService
|
||||
{
|
||||
public void Send<T>(string subscriber, T arg = default(T))
|
||||
{
|
||||
Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, subscriber, arg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,29 +35,33 @@ namespace Bit.App.Services
|
|||
|
||||
public void Init()
|
||||
{
|
||||
_broadcasterService.Subscribe<Tuple<int, bool>>("showDialogResolve", (details) =>
|
||||
_broadcasterService.Subscribe("showDialogResolve", (message) =>
|
||||
{
|
||||
var dialogId = details.Item1;
|
||||
var confirmed = details.Item2;
|
||||
if(_showDialogResolves.ContainsKey(dialogId))
|
||||
if(message.Command == "")
|
||||
{
|
||||
var resolveObj = _showDialogResolves[dialogId].Item1;
|
||||
resolveObj.TrySetResult(confirmed);
|
||||
}
|
||||
|
||||
// Clean up old tasks
|
||||
var deleteIds = new HashSet<int>();
|
||||
foreach(var item in _showDialogResolves)
|
||||
{
|
||||
var age = DateTime.UtcNow - item.Value.Item2;
|
||||
if(age.TotalMilliseconds > DialogPromiseExpiration)
|
||||
var details = message.Data as Tuple<int, bool>;
|
||||
var dialogId = details.Item1;
|
||||
var confirmed = details.Item2;
|
||||
if(_showDialogResolves.ContainsKey(dialogId))
|
||||
{
|
||||
deleteIds.Add(item.Key);
|
||||
var resolveObj = _showDialogResolves[dialogId].Item1;
|
||||
resolveObj.TrySetResult(confirmed);
|
||||
}
|
||||
|
||||
// Clean up old tasks
|
||||
var deleteIds = new HashSet<int>();
|
||||
foreach(var item in _showDialogResolves)
|
||||
{
|
||||
var age = DateTime.UtcNow - item.Value.Item2;
|
||||
if(age.TotalMilliseconds > DialogPromiseExpiration)
|
||||
{
|
||||
deleteIds.Add(item.Key);
|
||||
}
|
||||
}
|
||||
foreach(var id in deleteIds)
|
||||
{
|
||||
_showDialogResolves.Remove(id);
|
||||
}
|
||||
}
|
||||
foreach(var id in deleteIds)
|
||||
{
|
||||
_showDialogResolves.Remove(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue