public async Task SyncContactsAsync(TLContactsContactsBase result) { using (await _syncLock.WaitAsync()) { Debug.WriteLine("SYNCING CONTACTS"); var contactList = await GetContactListAsync(); var annotationList = await GetAnnotationListAsync(); var peopleList = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); if (contactList != null && annotationList != null) { await ExportContacts(contactList, annotationList, result); } //if (peopleList != null) //{ // await ImportContacts(peopleList); //} Debug.WriteLine("SYNCED CONTACTS"); } }
public async Task SyncContactsAsync(TLContactsContactsBase result) { using (await _syncLock.WaitAsync()) { Debug.WriteLine("SYNCING CONTACTS"); var contactList = await GetContactListAsync(); var annotationList = await GetAnnotationListAsync(); if (contactList != null && annotationList != null) { await ExportContacts(contactList, annotationList, result); } Debug.WriteLine("SYNCED CONTACTS"); } }
private async Task ExportAsync(ContactList contactList, ContactAnnotationList annotationList, TLContactsContactsBase result) { var contacts = result as TLContactsContacts; if (contacts != null) { foreach (var item in contacts.Users.OfType <TLUser>()) { var contact = await contactList.GetContactFromRemoteIdAsync("u" + item.Id); if (contact == null) { contact = new Contact(); } contact.FirstName = item.FirstName ?? string.Empty; contact.LastName = item.LastName ?? string.Empty; //contact.Nickname = item.Username ?? string.Empty; contact.RemoteId = "u" + item.Id; //contact.Id = item.Id.ToString(); var phone = contact.Phones.FirstOrDefault(); if (phone == null) { phone = new ContactPhone(); phone.Kind = ContactPhoneKind.Mobile; phone.Number = string.Format("+{0}", item.Phone); contact.Phones.Add(phone); } else { phone.Kind = ContactPhoneKind.Mobile; phone.Number = string.Format("+{0}", item.Phone); } await contactList.SaveContactAsync(contact); ContactAnnotation annotation; var annotations = await annotationList.FindAnnotationsByRemoteIdAsync(item.Id.ToString()); if (annotations.Count == 0) { annotation = new ContactAnnotation(); } else { annotation = annotations[0]; } annotation.ContactId = contact.Id; annotation.RemoteId = contact.RemoteId; annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.Message | ContactAnnotationOperations.AudioCall; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)) { annotation.SupportedOperations |= ContactAnnotationOperations.Share; } if (annotation.ProviderProperties.Count == 0) { annotation.ProviderProperties.Add("ContactPanelAppID", Package.Current.Id.FamilyName + "!App"); annotation.ProviderProperties.Add("ContactShareAppID", Package.Current.Id.FamilyName + "!App"); } await annotationList.TrySaveAnnotationAsync(annotation); } } }