Example #1
0
        private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
        {
            Current = snapshot?.ToObject <DonorUser>();
            CurrentUpdated?.Invoke(Current);
            if (previousUID != Current?.UID)
            {
                previousUID = Current?.UID;
                CurrentChanged?.Invoke(Current);
                CrossFirebasePushNotification.Current.UnsubscribeAll();
                if (!(Current is null))
                {
                    CrossFirebasePushNotification.Current.Subscribe("Urgent_Project");
                }
            }
            _ = DonationBundle.SetCurrentAsync(Current?.CurrentDonationBundle);
            if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
            {
                SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
            }
            var newTopics = Current?.DonatedProjectUIDs.Select(x => "Project_" + x)
                            .Where(x => !CrossFirebasePushNotification.Current.SubscribedTopics.Contains(x));

            if (newTopics?.Any() ?? false)
            {
                CrossFirebasePushNotification.Current.Subscribe(newTopics.ToArray());
            }
            System.Diagnostics.Debug.WriteLine(string.Join(", ", CrossFirebasePushNotification.Current.SubscribedTopics));
        }
Example #2
0
        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));
            }
        }