public virtual async Task MarkAllAsRead() { foreach (var notification in _allRemoteNotifications) { notification.Read = true; } NotificationsUpdated?.Invoke(this, new NotificationsEventArgs(_allRemoteNotifications)); }
public virtual async Task MarkAsUnread(Notification notification) { if (!notification.Read) { return; } notification.Read = false; NotificationsUpdated?.Invoke(this, new NotificationsEventArgs(notification)); }
public virtual async Task AddOrUpdateNotification(Notification notification) { if (_surpressedNotifications.Contains(notification.Id)) { return; } Notification existing = null; bool isNew = false; lock (_lock) { existing = _allRemoteNotifications.FirstOrDefault(x => x.Id == notification.Id); isNew = existing == null; if (isNew) { _allRemoteNotifications.Add(notification); lock (_toastLock) _toastNotifications.Add(notification); new Timer(s => DismissToastNotification(notification), null, DefaultToastPopTimerPeriod, Timeout.Infinite); } else { existing.Description = notification.Description; existing.ActionLinks = notification.ActionLinks; existing.ProgressPercent = notification.ProgressPercent; existing.ProgressDescription = notification.ProgressDescription; existing.Read = existing.Read || notification.Read; existing.Severity = notification.Severity; existing.Title = notification.Title; existing.CreatedUtc = notification.CreatedUtc; existing.UpdatedUtc = notification.UpdatedUtc; } } if (isNew) { NotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification)); ToastNotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification)); } else { NotificationsUpdated?.Invoke(this, new NotificationsEventArgs(existing)); } }