private async Task GetSampleDataAsync()
        {
            if (this._groups.Count != 0)
            {
                return;
            }
#if WINDOWS_PHONE_APP
            ContactStore agenda = await ContactManager.RequestStoreAsync();

            IReadOnlyList <Contact> contacts = null;
            contacts = await agenda.FindContactsAsync();


            var q = contacts
                    .Where(c => c.JobInfo.FirstOrDefault()?.CompanyName == "笨笨老师")
                    .Select(c => new SampleDataItem(
                                c.Id,
                                c.LastName,
                                string.Format("祝{0}节日快乐", c.DisplayName ?? c.LastName),
                                "Assets/DarkGray.png",
                                c.Phones.FirstOrDefault()?.Number, "desc"))
                    .ToList();


            var group = new SampleDataGroup("hh", "老师", "hello group", "Assets/LightGray.png", "group descirpt");
            foreach (var item in q)
            {
                group.Items.Add(item);
            }
            //group.Items.Add(new SampleDataItem("hll", "title", "subti", "Assets/DarkGray.png", "itemdesc", "comntetahj"));
            this.Groups.Add(group);
#endif
        }
Beispiel #2
0
        private async Task <ContactGroup> GetDataAsync(string message, string groupName)
        {
#if WINDOWS_PHONE_APP
            ContactStore agenda = await ContactManager.RequestStoreAsync();

            IReadOnlyList <Contact> contacts = null;
            contacts = await agenda.FindContactsAsync();


            var q = contacts
                    .Where(c => c.JobInfo.FirstOrDefault()?.CompanyName == groupName)
                    .Select(c => new MessageItem
            {
                Id          = c.Id,
                LastName    = c.LastName,
                FirstName   = c.FirstName,
                DisplayName = c.DisplayName,
                RawContent  = message,
                Telephone   = c.Phones.FirstOrDefault()?.Number,
            })
                    .ToList();


            var group = new ContactGroup {
                Name = groupName, Items = q
            };
            return(group);
#endif
        }
        private async Task <bool> __SyncContactsFromDevice()
        {
            List <string>      phone_no_list = dbHelper.GetDistinctPhoneNumbers();
            List <ContactData> contact_data  = new List <ContactData>();
            ContactData        cd;

            ContactStore contact_store = await ContactManager.RequestStoreAsync();

            foreach (string phone_no in phone_no_list)
            {
                IReadOnlyList <Contact> cl = await contact_store.FindContactsAsync(phone_no).AsTask();

                if (cl.Count > 0)
                {
                    Contact c = cl.FirstOrDefault();

                    cd             = new ContactData();
                    cd.PhoneNo     = phone_no;
                    cd.ContactName = c.FullName;

                    contact_data.Add(cd);
                }
            }

            // Now save this in DB
            return(SaveContactData(contact_data));
        }
Beispiel #4
0
        private async Task ImportContacts(ContactStore peopleList)
        {
            var contacts = await peopleList.FindContactsAsync();

            foreach (var contact in contacts)
            {
            }
        }
Beispiel #5
0
        public async Task <List <Contact> > GetContactCollection()
        {
            ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            // All available contacts
            var contacts = await allAccessStore.FindContactsAsync();

            return(contacts.ToList());
        }
Beispiel #6
0
        private async Task <Contact> FindContact(string id)
        {
            ContactStore contactStore = await ContactManager.RequestStoreAsync();

            IReadOnlyList <Contact> contacts = null;

            contacts = await contactStore.FindContactsAsync(id);

            return(contacts.FirstOrDefault());
        }
Beispiel #7
0
        private async void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (store == null || loading)
            {
                return;
            }

            string search = (sender as TextBox).Text;

            Debug.WriteLine("Looking for: '{0}'", search);
            loading            = true;
            candidates.Opacity = 0.8;
            candidates.Items.Clear();

            IReadOnlyList <Contact> contacts = new List <Contact>();

            if (string.IsNullOrWhiteSpace(search))
            {
                contacts = await store.FindContactsAsync();
            }
            else
            {
                contacts = await store.FindContactsAsync(search);
            }

            foreach (var c in contacts)
            {
                var email = c.Emails.FirstOrDefault();
                if (email == null)
                {
                    continue;
                }
                candidates.Items.Add(new ContactInfo {
                    Name = c.DisplayName, Email = email.Address
                });
            }

            Debug.WriteLine("Found {0} contacts", candidates.Items.Count);
            loading            = false;
            candidates.Opacity = 1;
        }
        private async void StartSearchContacts()
        {
            listLog.Items.Add("Searching Contacts...");
            listLog.SelectedIndex = 0;
            ContactStore contactStore = await ContactManager.RequestStoreAsync();

            IReadOnlyList <Contact> contacts = null;

            contacts = await contactStore.FindContactsAsync();

            listLog.Items.Add("The number of contacts is: " + contacts.Count.ToString());
            Save_Contacts(contacts);
        }
Beispiel #9
0
        private async Task <Telegram.Td.Api.BaseObject> ImportAsync(ContactStore store)
        {
            var contacts = await store.FindContactsAsync();

            var importedPhones = new Dictionary <string, Contact>();

            foreach (var contact in contacts)
            {
                foreach (var phone in contact.Phones)
                {
                    importedPhones[phone.Number] = contact;
                }
            }

            var importingContacts = new List <Telegram.Td.Api.Contact>();

            foreach (var phone in importedPhones.Keys.ToList())
            {
                var contact   = importedPhones[phone];
                var firstName = contact.FirstName ?? string.Empty;
                var lastName  = contact.LastName ?? string.Empty;

                if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                {
                    if (string.IsNullOrEmpty(contact.DisplayName))
                    {
                        continue;
                    }

                    firstName = contact.DisplayName;
                }

                if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName))
                {
                    var item = new Telegram.Td.Api.Contact
                    {
                        PhoneNumber = phone,
                        FirstName   = firstName,
                        LastName    = lastName
                    };

                    importingContacts.Add(item);
                }
            }

            return(await _protoService.SendAsync(new Telegram.Td.Api.ChangeImportedContacts(importingContacts)));
        }
Beispiel #10
0
        private async Task <Windows.ApplicationModel.Contacts.Contact> findContact(string emailAddress)
        {
            if (contactStore == null)
            {
                contactStore = await ContactManager.RequestStoreAsync();

                contactStore.ContactChanged += ContactStore_ContactChanged;
                contactStore.ChangeTracker.Enable();
            }


            IReadOnlyList <Windows.ApplicationModel.Contacts.Contact> contacts = null;

            contacts = await contactStore.FindContactsAsync(emailAddress);

            Windows.ApplicationModel.Contacts.Contact contact = contacts[0];


            return(contact);
        }
Beispiel #11
0
        // https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/contact-card
        // Display a contact in response to an event
        private async void OnUserClickShowContactCard(FrameworkElement element, string name, string address)
        {
            if (ContactManager.IsShowContactCardSupported())
            {
                Rect selectionRect = GetElementRect(element);

                // https://docs.microsoft.com/en-us/windows/uwp/contacts-and-calendar/integrating-with-contacts
                ContactStore contactStore = await ContactManager.RequestStoreAsync();

                IReadOnlyList <Contact> contacts = await contactStore.FindContactsAsync(address);

                // Retrieve the contact to display
                Contact contact;
                if (contacts.Count > 0)
                {
                    contact = contacts[0];
                }
                else
                {
                    // Create new contact
                    contact = new Contact();
                    var email = new ContactEmail();
                    email.Address = address;
                    contact.Emails.Add(email);
                    if (!string.IsNullOrEmpty(name))
                    {
                        contact.Name = name;
                    }
                }

                ContactManager.ShowContactCard(contact, selectionRect, Placement.Default);
            }
            else
            {
                // Launch People app
                bool success = await Launcher.LaunchUriAsync(new Uri("ms-people:viewcontact?Email=" + address));
            }
        }
Beispiel #12
0
        private async Task ImportAsync(ContactStore store)
        {
            var contacts = await store.FindContactsAsync();

            var importedPhones = new Dictionary <string, Contact>();

            foreach (var contact in contacts)
            {
                foreach (var phone in contact.Phones)
                {
                    importedPhones[phone.Number] = contact;
                }
            }

            var importedPhonesCache = GetImportedPhones();

            var importingContacts = new TLVector <TLInputContactBase>();
            var importingPhones   = new List <string>();

            foreach (var phone in importedPhones.Keys.Take(1300).ToList())
            {
                if (!importedPhonesCache.ContainsKey(phone))
                {
                    var contact   = importedPhones[phone];
                    var firstName = contact.FirstName ?? string.Empty;
                    var lastName  = contact.LastName ?? string.Empty;

                    if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                    {
                        if (string.IsNullOrEmpty(contact.DisplayName))
                        {
                            continue;
                        }

                        firstName = contact.DisplayName;
                    }

                    if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName))
                    {
                        var item = new TLInputPhoneContact
                        {
                            Phone     = phone,
                            FirstName = firstName,
                            LastName  = lastName,
                            ClientId  = importedPhones[phone].GetHashCode()
                        };

                        importingContacts.Add(item);
                        importingPhones.Add(phone);
                    }
                }
            }

            if (importingContacts.IsEmpty())
            {
                return;
            }

            //base.IsWorking = true;
            _protoService.ImportContactsAsync(importingContacts, result =>
            {
                //Telegram.Api.Helpers.Execute.BeginOnUIThread(delegate
                //{
                //    this.IsWorking = false;
                //    this.Status = ((this.Items.get_Count() == 0 && this.LazyItems.get_Count() == 0 && result.Users.Count == 0) ? string.Format("{0}", AppResources.NoContactsHere) : string.Empty);
                //    int count = result.RetryContacts.Count;
                //    if (count > 0)
                //    {
                //        Telegram.Api.Helpers.Execute.ShowDebugMessage("contacts.importContacts error: retryContacts count=" + count);
                //    }
                //    this.InsertContacts(result.Users);
                //});

                _aggregator.Publish(new TLUpdateContactsReset());
                SaveImportedPhones(importedPhonesCache, importingPhones);
            },
                                              fault =>
            {
                Telegram.Api.Helpers.Execute.BeginOnUIThread(delegate
                {
                    //this.IsWorking = false;
                    //this.Status = string.Empty;
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("contacts.importContacts error: " + fault);
                });
            });
        }
        public async Task RefreshContacts()
        {
            CancellationTokenSource cancelSource = new CancellationTokenSource();

            RefreshingContacts = true;
            Contacts.Clear();
            signalContacts.Clear();
            ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            List <PhoneContact> intermediateContacts = new List <PhoneContact>();

            if (contactStore != null)
            {
                HashSet <string> seenNumbers = new HashSet <string>();
                var contacts = await contactStore.FindContactsAsync();

                ContactAnnotationStore contactAnnotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                ContactAnnotationList contactAnnotationList;
                var contactAnnotationLists = await contactAnnotationStore.FindAnnotationListsAsync();

                if (contactAnnotationLists.Count == 0)
                {
                    contactAnnotationList = await contactAnnotationStore.CreateAnnotationListAsync();
                }
                else
                {
                    contactAnnotationList = contactAnnotationLists[0];
                }

                foreach (var contact in contacts)
                {
                    var phones = contact.Phones;
                    foreach (var phone in contact.Phones)
                    {
                        if (phone.Kind == ContactPhoneKind.Mobile)
                        {
                            string formattedNumber = null;
                            try
                            {
                                formattedNumber = ParsePhoneNumber(phone.Number);
                            }
                            catch (NumberParseException)
                            {
                                Logger.LogDebug("RefreshContacts() could not parse number");
                                continue;
                            }
                            if (!seenNumbers.Contains(formattedNumber))
                            {
                                seenNumbers.Add(formattedNumber);
                                PhoneContact phoneContact = new PhoneContact
                                {
                                    Id          = contact.Id,
                                    Name        = contact.FullName,
                                    PhoneNumber = formattedNumber,
                                    OnSignal    = false
                                };
                                if (contact.SourceDisplayPicture != null)
                                {
                                    using (var stream = await contact.SourceDisplayPicture.OpenReadAsync())
                                    {
                                        BitmapImage bitmapImage = new BitmapImage();
                                        await bitmapImage.SetSourceAsync(stream);

                                        phoneContact.Photo = bitmapImage;
                                    }
                                }
                                intermediateContacts.Add(phoneContact);
                            }
                        }
                    }
                }

                // check if we've annotated a contact as a Signal contact already, if we have we don't need to ask Signal about them
                for (int i = 0; i < intermediateContacts.Count; i++)
                {
                    var annotatedContact = await contactAnnotationList.FindAnnotationsByRemoteIdAsync(intermediateContacts[i].PhoneNumber);

                    if (annotatedContact.Count > 0)
                    {
                        intermediateContacts[i].OnSignal = true;
                        signalContacts.Add(intermediateContacts[i]);
                        intermediateContacts.RemoveAt(i);
                        i--;
                    }
                }

                List <string> intermediateContactPhoneNumbers = intermediateContacts.Select(c => c.PhoneNumber).ToList();
                var           registeredUsers = await accountManager.GetRegisteredUsersAsync(intermediateContactPhoneNumbers, LibUtils.SignalSettings.ContactDiscoveryServiceEnclaveId, cancelSource.Token);

                foreach (var contact in intermediateContacts)
                {
                    var foundContact = registeredUsers.FirstOrDefault(c => c.Key == contact.PhoneNumber);
                    if (!string.IsNullOrEmpty(foundContact.Key))
                    {
                        contact.OnSignal   = true;
                        contact.SignalGuid = foundContact.Value;
                        ContactAnnotation contactAnnotation = new ContactAnnotation
                        {
                            ContactId           = contact.Id,
                            RemoteId            = contact.PhoneNumber,
                            SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile
                        };
                        contactAnnotation.ProviderProperties.Add(nameof(contact.SignalGuid), foundContact.Value);
                        await contactAnnotationList.TrySaveAnnotationAsync(contactAnnotation);

                        signalContacts.Add(contact);
                    }
                }
                Contacts.AddRange(signalContacts);
            }
            else
            {
                ContactsVisible = false;
            }
            RefreshingContacts = false;
        }
Beispiel #14
0
        private async Task ImportAsync(ContactStore store)
        {
            var contacts = await store.FindContactsAsync();

            var importedPhones = new Dictionary <string, Contact>();

            foreach (var contact in contacts)
            {
                foreach (var phone in contact.Phones)
                {
                    importedPhones[phone.Number] = contact;
                }
            }

            var importedPhonesCache = GetImportedPhones();

            var importingContacts = new List <TdWindows.Contact>();
            var importingPhones   = new List <string>();

            foreach (var phone in importedPhones.Keys.Take(1300).ToList())
            {
                if (!importedPhonesCache.ContainsKey(phone))
                {
                    var contact   = importedPhones[phone];
                    var firstName = contact.FirstName ?? string.Empty;
                    var lastName  = contact.LastName ?? string.Empty;

                    if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                    {
                        if (string.IsNullOrEmpty(contact.DisplayName))
                        {
                            continue;
                        }

                        firstName = contact.DisplayName;
                    }

                    if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName))
                    {
                        var item = new TdWindows.Contact
                        {
                            PhoneNumber = phone,
                            FirstName   = firstName,
                            LastName    = lastName
                        };

                        importingContacts.Add(item);
                        importingPhones.Add(phone);
                    }
                }
            }

            if (importingContacts.IsEmpty())
            {
                return;
            }

            _protoService.Send(new TdWindows.ImportContacts(importingContacts), result =>
            {
                if (result is TdWindows.ImportedContacts)
                {
                    //_aggregator.Publish(new TLUpdateContactsReset());
                    SaveImportedPhones(importedPhonesCache, importingPhones);
                }
            });
        }
        public async Task RefreshContacts(CancellationToken?cancellationToken = null)
        {
            RefreshingContacts = true;
            Contacts.Clear();
            signalContacts.Clear();
            SignalServiceAccountManager accountManager = new SignalServiceAccountManager(App.ServiceUrls, App.Store.Username, App.Store.Password, (int)App.Store.DeviceId, App.USER_AGENT);
            ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            List <PhoneContact> intermediateContacts = new List <PhoneContact>();

            if (contactStore != null)
            {
                HashSet <string> seenNumbers = new HashSet <string>();
                var contacts = await contactStore.FindContactsAsync();

                ContactAnnotationStore contactAnnotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                ContactAnnotationList contactAnnotationList;
                var contactAnnotationLists = await contactAnnotationStore.FindAnnotationListsAsync();

                if (contactAnnotationLists.Count == 0)
                {
                    contactAnnotationList = await contactAnnotationStore.CreateAnnotationListAsync();
                }
                else
                {
                    contactAnnotationList = contactAnnotationLists[0];
                }

                foreach (var contact in contacts)
                {
                    var phones = contact.Phones;
                    foreach (var phone in contact.Phones)
                    {
                        if (phone.Kind == ContactPhoneKind.Mobile)
                        {
                            string formattedNumber = null;
                            try
                            {
                                formattedNumber = ParsePhoneNumber(phone.Number);
                            }
                            catch (NumberParseException)
                            {
                                Debug.WriteLine($"Couldn't parse {phone.Number}");
                                continue;
                            }
                            if (!seenNumbers.Contains(formattedNumber))
                            {
                                seenNumbers.Add(formattedNumber);
                                PhoneContact phoneContact = new PhoneContact
                                {
                                    Id          = contact.Id,
                                    Name        = contact.FullName,
                                    PhoneNumber = formattedNumber,
                                    OnSignal    = false
                                };
                                if (contact.SourceDisplayPicture != null)
                                {
                                    using (var stream = await contact.SourceDisplayPicture.OpenReadAsync())
                                    {
                                        BitmapImage bitmapImage = new BitmapImage();
                                        await bitmapImage.SetSourceAsync(stream);

                                        phoneContact.Photo = bitmapImage;
                                    }
                                }
                                intermediateContacts.Add(phoneContact);
                            }
                        }
                    }
                }

                // check if we've annotated a contact as a Signal contact already, if we have we don't need to ask Signal about them
                for (int i = 0; i < intermediateContacts.Count; i++)
                {
                    var annotatedContact = await contactAnnotationList.FindAnnotationsByRemoteIdAsync(intermediateContacts[i].PhoneNumber);

                    if (annotatedContact.Count > 0)
                    {
                        intermediateContacts[i].OnSignal = true;
                        signalContacts.Add(intermediateContacts[i]);
                        intermediateContacts.RemoveAt(i);
                        i--;
                    }
                }

                var signalContactDetails = accountManager.getContacts(intermediateContacts.Select(c => c.PhoneNumber).ToList());
                foreach (var contact in intermediateContacts)
                {
                    var foundContact = signalContactDetails.FirstOrDefault(c => c.getNumber() == contact.PhoneNumber);
                    if (foundContact != null)
                    {
                        contact.OnSignal = true;
                        ContactAnnotation contactAnnotation = new ContactAnnotation();
                        contactAnnotation.ContactId           = contact.Id;
                        contactAnnotation.RemoteId            = contact.PhoneNumber;
                        contactAnnotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile;
                        await contactAnnotationList.TrySaveAnnotationAsync(contactAnnotation);

                        signalContacts.Add(contact);
                    }
                }
                Contacts.AddRange(signalContacts);
            }
            else
            {
                ContactsVisible = false;
            }
            RefreshingContacts = false;
        }