示例#1
0
        public async Task AcquirePhoneContacts(Boolean sort)
        {
            var permission = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Contacts);

            if (permission.Equals(PermissionStatus.Granted))
            {
                PhoneContacts.Clear();
                List <string> contactNumbers = new List <string>();
                var           contacts       = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();

                if (sort)
                {
                    contacts = contacts.OrderBy(c => c.Name).ToList();
                }
                string[] splitParam = new string[] { "stringValue=" };
                foreach (Contact c in contacts)
                {
                    // TODO: look at this logic again
                    // Contact.Number contains string listed below:
                    // <CNPhoneNumber: 0x1c4a33520: stringValue=5127994767, initialCountryCode=(null)>
                    PhoneContact pc = new PhoneContact()
                    {
                        Status       = FriendStatus.NotRegistered,
                        Name         = c.Name,
                        PhoneNumber  = ExtractPhoneNumber(c.Number),
                        PhoneNumbers = new List <String>()
                        {
                            ExtractPhoneNumber(c.Number)
                        }
                    };
                    contactNumbers.Add(pc.PhoneNumber);
                    foreach (string str in c.Numbers)
                    {
                        string multi = ExtractPhoneNumber(str);
                        if (!pc.PhoneNumber.Equals(multi))
                        {
                            contactNumbers.Add(multi);
                            pc.PhoneNumbers.Add(multi);
                        }
                    }
                    PhoneContacts.Add(pc);
                }
                UserPhoneNumbers upn = new UserPhoneNumbers()
                {
                    Numbers = contactNumbers,
                    UserId  = App.AppUser.id
                };
                await AcquireUsersFromPhoneNumbers(upn);
            }
            else
            {
                throw new InvalidOperationException("contacts permission is not granted");
                //await Navigation.PopAsync();
                //await Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await App.Current.MainPage.Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await Navigation.PopAsync();
            }
        }
示例#2
0
        private async Task <PhoneContacts> CheckPhoneExistenceAsync(long contactId)
        {
            PhoneContacts phone = await PhoneRepo.FindById(contactId);

            if (phone == null)
            {
                throw new Exception(String.Format("There is no phone record with id {0}", contactId));
            }

            return(phone);
        }
示例#3
0
        public async Task <bool> RemoveContactNumberAsync(long ownerId, long restaurantId, long contactId)
        {
            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            PhoneContacts phone = await CheckPhoneExistenceAsync(contactId);

            CheckTheLoggedInPerson();
            await PhoneRepo.RemoveAsync(phone);

            return(true);
        }
示例#4
0
        public async Task <PhoneContacts> UpdateContactNumberAsync(long ownerId, long restaurantId, long contactId, string phoneNumber, string phoneDescription)
        {
            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            PhoneContacts phone = await CheckPhoneExistenceAsync(contactId);

            CheckTheLoggedInPerson();
            phone.PhoneNumber      = phoneNumber;
            phone.PhoneDescription = phoneDescription;
            await PhoneRepo.UpdateAsync(phone, ModifierId);

            return(phone);
        }
示例#5
0
        public async Task <PhoneContacts> AddContactNumberAsync(long ownerId, long restaurantId, string phoneNumber, string phoneDescription)
        {
            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            PhoneContacts phone = new PhoneContacts
            {
                PhoneNumber      = phoneNumber,
                PhoneDescription = phoneDescription,
                RestaurantId     = connection.RestaurantId
            };

            CheckTheLoggedInPerson();
            await PhoneRepo.AddAsync(phone, ModifierId);

            return(phone);
        }
        private static void MatchContacts()
        {
            //DEBUG
            //foreach (var item in BookSyncContacts)
            //{
            //    item.FacebookUserId = string.Empty;
            //}

            // BookSyncContacts.Clear();
            // SaveBookSyncContacts();


            //so having all the contacts we need to update the book sync contacts with the new ones and remove the deleted ones
            //then go through the contacts matched with fb users and update the pictures
            List <BookSyncContact> contactsToAdd = (from a in PhoneContacts
                                                    where !BookSyncContacts.Contains(BookSyncContacts.FirstOrDefault(f => f.PhoneContactId == a.PhoneContactId))
                                                    select new BookSyncContact()
            {
                PhoneContactId = a.PhoneContactId,
                PhoneFirstName = a.FirstName,
                PhoneLastName = a.LastName,
                PhoneImageBase64 = a.PhoneImageBase64
            }).AsParallel().ToList();

            //Get all the booksync contacts that have been removed from the phone
            List <string> contactsToRemove = (from a in BookSyncContacts
                                              where !PhoneContacts.Contains(PhoneContacts.FirstOrDefault(f => f.PhoneContactId == a.PhoneContactId))
                                              select a.PhoneContactId).AsParallel().ToList();

            //remove the ones to remove
            BookSyncContacts.RemoveAll((obj) => contactsToRemove.Contains(obj.PhoneContactId));

            //add in the new ones
            BookSyncContacts.AddRange(contactsToAdd);

            //sort the list TODO:// check if this is actually needed as we should maybe insert at
            BookSyncContacts.Sort(new BookSyncContactComparer());

            //loop through each of the contacts we've got and update the fb image if it's matched
            Parallel.ForEach(BookSyncContacts.Where(w => !string.IsNullOrEmpty(w.FacebookUserId)), (BookSyncContact contact, ParallelLoopState state) =>
            {
                var matchedFbFriend = FacebookUsers.FirstOrDefault(f => f.ID == contact.FacebookUserId);
                if (matchedFbFriend != null)
                {
                    contact.FacebookImageSmallUrl = matchedFbFriend.ProfileImageSmallUrl;
                    contact.FacebookImageLargeUrl = matchedFbFriend.ProfileImageLargeUrl;
                }
            });

            //loop through all the contacts and update the phone details
            Parallel.ForEach(BookSyncContacts, (BookSyncContact contact, ParallelLoopState state) =>
            {
                var phoneContact = PhoneContacts.FirstOrDefault(f => f.PhoneContactId == contact.PhoneContactId);
                if (phoneContact != null)
                {
                    contact.PhoneFirstName   = phoneContact.FirstName;
                    contact.PhoneLastName    = phoneContact.LastName;
                    contact.PhoneImageBase64 = phoneContact.PhoneImageBase64;
                }
            });

            //save the new collection of objects back to the settings to save it
            SaveBookSyncContacts();

            ContactsLoadedAndMatchced?.Invoke(null, new EventArgs());
        }