private async Task deleteAll() { if (await Application.Current.MainPage.DisplayAlert("Clear", "Are you sure you want to clear all messages?", "Yes", "No")) { try { IsLoading = true; var items = NotificationItems?.ToList(); if (items != null) { for (int i = items.Count - 1; i >= 0; i--) { await setNotificationStatusAsync(items[i], NotificationStatus.Deleted); } } } catch (Exception ex) { LoggerService.Instance.Log("ERROR: Notifications.deleteAll: " + ex); } finally { IsLoading = false; } } }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { NotificationItems.Clear(); var notificationItems = await App.Database.GetNotificationItemsAsync(); foreach (var item in notificationItems) { NotificationItems.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public override async Task Logout() { if (NotificationItems != null) { lock (syncRoot) if (NotificationItems != null) { NotificationItems.Clear(); OnPropertyChanged(nameof(NotificationItemsCount)); OnPropertyChanged(nameof(UnreadNotificationsCount)); } } SelectedItem = null; await base.Logout(); }
private async Task loadItems() { var collection = await NotificationClient.Get(); if ((collection != null) && (collection.Entries != null)) { if (NotificationItems == null) { NotificationItems = new ObservableCollection <Notification>(); } await NotificationItems.UpdateItems(collection.Entries.OrderByDescending(q => q.Created)); await NotificationItems.SortByDate(); OnPropertyChanged(nameof(NotificationItemsCount)); OnPropertyChanged(nameof(UnreadNotificationsCount)); } }
private async Task setNotificationStatusAsync(Notification item, NotificationStatus status) { try { if ((item != null) && (item.Status != status)) { var response = await NotificationClient.SetStatus(item.ID, status); if ((response != null) && response.Success) { item.Status = status; if (item.Status == NotificationStatus.Deleted) { if (NotificationItems != null) { lock (syncRoot) if (NotificationItems != null) { NotificationItems.Remove(item); } } if (item.Equals(SelectedItem)) { SelectedItem = null; } } OnPropertyChanged(nameof(NotificationItemsCount)); OnPropertyChanged(nameof(UnreadNotificationsCount)); } } } catch (Exception ex) { //XXX : Handle error LoggerService.Instance.Log("ERROR: Notifications.setNotificationStatusAsync: " + ex); } }
private async Task GetRequiredRecord() { IsRefreshing = true; var agentContext = await _agentProvider.GetContextAsync(); //ISearchQuery credentialsQuery = ListOffersAsync var listCredentials = await _credentialService.ListOffersAsync(agentContext); var listProofRequests = await _proofService.ListRequestedAsync(agentContext); IList <NotificationItem> notificationItemList = new List <NotificationItem>(); //old version of notification //IList<CredOfferViewModel> credOfferViewModels = new List<CredOfferViewModel>(); foreach (var item in listCredentials) { CredOfferViewModel credOfferViewModel = _scope.Resolve <CredOfferViewModel>(new NamedParameter("credentialOffer", item)); NotificationItem notificationItem = new NotificationItem() { NotificationType = "Credential Offer", NotificationTitle = credOfferViewModel.CredentialName, NotificationContent = "You've received a credentital offer.", ItemViewModel = credOfferViewModel, IssuedDate = credOfferViewModel.IssuedDate }; var connection = await _connectionService.GetAsync(agentContext, item.ConnectionId); notificationItem.OrganizeAlias = connection.Alias; //old version of notification //credOfferViewModels.Add(credOfferViewModel); notificationItemList.Add(notificationItem); } //old version of notification //IList<ProofRequestViewModel> proofRequestViewModels = new List<ProofRequestViewModel>(); foreach (var item in listProofRequests) { ProofRequestViewModel proofRequestVm = _scope.Resolve <ProofRequestViewModel>(new NamedParameter("proofRequestRecord", item)); NotificationItem notificationItem = new NotificationItem() { NotificationType = "Proof Request", NotificationTitle = proofRequestVm.ProofRequestObject.Name, NotificationContent = "You've received a request for proof of credential.", ItemViewModel = proofRequestVm, IssuedDate = proofRequestVm.IssuedDate }; var connection = await _connectionService.GetAsync(agentContext, item.ConnectionId); notificationItem.OrganizeAlias = connection.Alias; //old version of notification //proofRequestViewModels.Add(proofRequestVm); notificationItemList.Add(notificationItem); } //old version of notification //_proofRequestVms.Clear(); //_proofRequestVms.InsertRange(proofRequestViewModels); //_credentialOfferVms.Clear(); //_credentialOfferVms.InsertRange(credOfferViewModels); //--end old version of notification var orderList = notificationItemList.OrderBy(item => item.IssuedDate); NotificationItems.Clear(); NotificationItems.InsertRange(orderList); IsRefreshing = false; }