Esempio n. 1
0
        /// <summary>
        /// Persist User properties.
        /// </summary>
        public async Task PersistUser()
        {
            if (User == null)
            {
                return;
            }

            await _store.Insert(User);

            await _store.Persist();
        }
Esempio n. 2
0
        /// <summary>
        /// Discover new matching friends from the backend.
        /// </summary>
        public async Task DiscoverFriendsAsync(List <LocalContact> contacts)
        {
            //Find unassociated contacts
            var contactsFromFriends  = Friends.Select(f => f.LocalContact);
            var unassociatedContacts = contacts
                                       .Except(contactsFromFriends, new ContactComparer(ContactComparer.CompareBy.PhoneNumber)).ToList();

            var friends = await _friendsService
                          .FetchFriends(unassociatedContacts.Select(f => f.NormalizedPhoneNumber));

            if (friends == null)
            {
                return;
            }

            foreach (var friend in friends)
            {
                if (Friends.Contains(friend, new FriendsComparer()))
                {
                    continue;
                }

                friend.LocalContact = unassociatedContacts
                                      .SingleOrDefault(c => c.NormalizedPhoneNumber == friend.PhoneNumber);

                //Persist friend
                await _keyValueStore.Insert(friend);

                Friends.Add(friend);

                //Persist chatbook
                var chatbook = new ChatBook()
                {
                    FriendKey = friend.Key
                };
                await _realmStore.AddAsync(chatbook);

                OnPropertyChanged(nameof(Friends));
            }
        }
Esempio n. 3
0
        private async Task Persist()
        {
            await _store.Insert(this);

            await _store.Persist();
        }