public void ClearMessages() { if (ReatimeListener != null) { ReatimeListener.Remove(); ReatimeListener = null; } this.messages = new ObservableCollection <Message>(); }
public static async Task SetCurrentAsync(IDocumentReference?doc) { if (doc?.Id != Current?.Doc.Id || doc is null) { listener?.Remove(); if (doc is null) { if (DonorUser.Current is null) { Current = null; previousUID = null; CurrentUpdated?.Invoke(null); CurrentChanged?.Invoke(null); return; } else { var bundleCollection = DonorUser.Current.Doc.Collection("DonationBundles"); DonationBundle bundle = new DonationBundle { StripeStatus = StripeStatus.Pending, GiftAidState = DonorUser.Current.GiftAidEnabled ? GiftAidState.Unclaimed : GiftAidState.Ineligible, Amount = 0, UserConfirmed = false }; doc = await bundleCollection.AddAsync(bundle); await DonorUser.Current.Doc.UpdateAsync(new { CurrentDonationBundle = doc }); } } listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot)); } }
private static void MonitorOwnUserProfile(Firebase.CloudFirestore.DocumentReference refer) { if (_listener != null) { _listener.Remove(); } _listener = refer.AddSnapshotListener((changedSnapshot, error) => { var data = changedSnapshot.Data[new NSString("isNeedNotification")] as NSNumber; if (data.BoolValue) { var userProfile = LoadSaveData <UserProfile>(changedSnapshot.Data); App.NotifyCloudDataChanged(userProfile); } }); }
public static void SetCurrent(string?uid) { if (uid != Current?.UID) { listener?.Remove(); if (string.IsNullOrEmpty(uid)) { Current = null; previousUID = null; CurrentUpdated?.Invoke(null); CurrentChanged?.Invoke(null); return; } var doc = Firestore.Collection("Users").Document(uid !); listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot)); } }
// Get notes data to be shown in TableView async Task GetNotes() { // Stop listening for changes from Firebase Cloud Firestore pendingChangesListener?.Remove(); pendingChangesListener?.Dispose(); pendingChangesListener = null; notes.Clear(); var notesQuery = await notesCollection.OrderedBy("lastModified", true) .GetDocumentsAsync(); foreach (var note in notesQuery.Documents) { // When you create a new note, sometimes the data hasn't // been written in Firestore yet, so, we keep listening // until the data is written. if (note.Metadata.HasPendingWrites) { pendingChangesListener = note.Reference.AddSnapshotListener(DataSavedOnFirestore); return; } var data = note.Data; var title = data ["title"]?.ToString(); var content = data ["content"]?.ToString(); var created = data ["created"] as NSDate; var lastModified = data ["lastModified"] as NSDate; notes.Add(new Note { Id = note.Id, Title = title, Content = content, Created = AppDelegate.GetFormattedDate(created), LastModified = AppDelegate.GetFormattedDate(lastModified) }); } InvokeOnMainThread(() => TableView.ReloadData()); }
public override void Destroy() { base.Destroy(); _registration.Remove(); }