Refresh UI notifications automatically on update (#1680)

* Refresh UI notifications automatically on update

* make notif timeago live

* pass cancellation token

* Update InvoiceEventData.cs
This commit is contained in:
Andrew Camilleri
2020-06-24 10:23:16 +02:00
committed by GitHub
parent 8230a408ac
commit dc5d8a6cb7
9 changed files with 148 additions and 44 deletions

View File

@@ -20,15 +20,17 @@ namespace BTCPayServer.Services.Notifications
private readonly ApplicationDbContextFactory _factory;
private readonly UserManager<ApplicationUser> _userManager;
private readonly IMemoryCache _memoryCache;
private readonly EventAggregator _eventAggregator;
private readonly Dictionary<string, INotificationHandler> _handlersByNotificationType;
private readonly Dictionary<Type, INotificationHandler> _handlersByBlobType;
public NotificationManager(ApplicationDbContextFactory factory, UserManager<ApplicationUser> userManager,
IMemoryCache memoryCache, IEnumerable<INotificationHandler> handlers)
IMemoryCache memoryCache, IEnumerable<INotificationHandler> handlers, EventAggregator eventAggregator)
{
_factory = factory;
_userManager = userManager;
_memoryCache = memoryCache;
_eventAggregator = eventAggregator;
_handlersByNotificationType = handlers.ToDictionary(h => h.NotificationType);
_handlersByBlobType = handlers.ToDictionary(h => h.NotificationBlobType);
}
@@ -52,6 +54,8 @@ namespace BTCPayServer.Services.Notifications
public void InvalidateNotificationCache(string userId)
{
_memoryCache.Remove(GetNotificationsCacheId(userId));
_eventAggregator.Publish(new UserNotificationsUpdatedEvent() {UserId = userId});
}
private static string GetNotificationsCacheId(string userId)