示例#1
0
        public static async Task <(bool res, Contact contact)> AddRouter(string mac, string name)
        {
            try
            {
                var list = await GetContactList();

                if (list == null)
                {
                    return(false, null);
                }
                Contact contact = new Contact();
                contact.FirstName = name;
                var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/images/router.png"));

                contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromFile(file);
                contact.Thumbnail            = RandomAccessStreamReference.CreateFromFile(file);
                string appid = Windows.ApplicationModel.Package.Current.Id.FamilyName + "!App";
                contact.ProviderProperties.Add("ContactPanelAppID", appid);
                await list.SaveContactAsync(contact);

                var annotation = new ContactAnnotation();
                annotation.ContactId = contact.Id;
                annotation.ProviderProperties.Add("ContactPanelAppID", appid);
                annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;
                var annotationList = await GetContactAnnotationList();

                var res = await annotationList.TrySaveAnnotationAsync(annotation);

                return(res, contact);
            }
            catch (Exception e)
            {
                return(false, null);
            }
        }
示例#2
0
        async Task PlatformAnnotate(NGContact contact, NGAnnotations annotations)
        {
            ContactAnnotationOperations winAnnotations = (ContactAnnotationOperations)annotations;

            if (winAnnotations == ContactAnnotationOperations.None)
            {
                winAnnotations = ContactAnnotationOperations.ContactProfile;
            }

            // Annotate this contact with a remote ID, which you can then retrieve when the Contact Panel is activated.
            var contactAnnotation = new ContactAnnotation
            {
                ContactId           = contact.Id,
                RemoteId            = contact.RemoteId,
                SupportedOperations = winAnnotations
            };

            // Annotate that this contact can load this app's Contact Panel or Contact Share.
            var infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            contactAnnotation.ProviderProperties.Add("ContactPanelAppID", infos[0].AppInfo.AppUserModelId);
            if ((winAnnotations & ContactAnnotationOperations.Share) == ContactAnnotationOperations.Share)
            {
                contactAnnotation.ProviderProperties.Add("ContactShareAppID", infos[0].AppInfo.AppUserModelId);
            }

            var annotationList = await FindOrRegisterAnnotationList();

            await annotationList.TrySaveAnnotationAsync(contactAnnotation);
        }
示例#3
0
        private async Task TagAContact(Contact contact)
        {
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            ContactAnnotationList annotationList;
            IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

            if (!annotationLists.Any())
            {
                annotationList = await annotationStore.CreateAnnotationListAsync();
            }
            else
            {
                annotationList = annotationLists.First();
            }

            var annotation = new ContactAnnotation
            {
                ContactId           = contact.Id,
                RemoteId            = "*****@*****.**",
                SupportedOperations =
                    ContactAnnotationOperations.AudioCall |
                    ContactAnnotationOperations.VideoCall |
                    ContactAnnotationOperations.ContactProfile |
                    ContactAnnotationOperations.Share | ContactAnnotationOperations.Message
            };
            string appId = "d2b5f9e1-1de2-4efb-863b-9eb5737d84b1_75cr2b68sm664!App";

            annotation.ProviderProperties.Add("ContactPanelAppID", appId);
            annotation.ProviderProperties.Add("ContactShareAppID", appId);

            await annotationList.TrySaveAnnotationAsync(annotation);
        }
示例#4
0
        /// <summary>
        /// Add contact by Discord friend object
        /// </summary>
        /// <param name="user">Discord User</param>
        public async void AddContact(Friend user)
        {
            // Create contact
            Contact contact = new Contact();

            contact.FirstName            = user.user.Username;
            contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromUri(Common.AvatarUri(user.user.Avatar, user.Id));

            // Save contact
            if (contactList == null)
            {
                return;
            }
            await contactList.SaveContactAsync(contact);

            ContactAnnotationList annotationList = await GetContactAnnotationList();

            if (annotationList == null)
            {
                return;
            }

            // Creeate annotations of contact
            ContactAnnotation annotation = new ContactAnnotation();

            annotation.ContactId           = contact.Id;
            annotation.RemoteId            = user.Id;
            annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.Message | ContactAnnotationOperations.Share;

            // Save annotations on contact
            if (!await annotationList.TrySaveAnnotationAsync(annotation))
            {
                return;
            }
        }
示例#5
0
        private async Task TagAContact(Contact contact)
        {
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            ContactAnnotationList annotationList;
            IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

            if (!annotationLists.Any())
            {
                annotationList = await annotationStore.CreateAnnotationListAsync();
            }
            else
            {
                annotationList = annotationLists.First();
            }

            var annotation = new ContactAnnotation
            {
                ContactId           = contact.Id,
                RemoteId            = "*****@*****.**",
                SupportedOperations =
                    ContactAnnotationOperations.AudioCall |
                    ContactAnnotationOperations.VideoCall |
                    ContactAnnotationOperations.ContactProfile |
                    ContactAnnotationOperations.Share | ContactAnnotationOperations.Message
            };

            string appId = "83c77a04-6440-426b-9245-8cddbac7e616_ga16xwmw2tna2!App";

            annotation.ProviderProperties.Add("ContactPanelAppID", appId);
            annotation.ProviderProperties.Add("ContactShareAppID", appId);

            await annotationList.TrySaveAnnotationAsync(annotation);
        }
示例#6
0
        private async Task AnnotateContactAsync(Contact contact)
        {
            // Annotate this contact with a remote ID, which you can then retrieve when the Contact Panel is activated.
            ContactAnnotation contactAnnotation = new ContactAnnotation
            {
                ContactId           = contact.Id,
                RemoteId            = Constants.ContactRemoteId,
                SupportedOperations = ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.Message
            };

            // Annotate that this contact can load this app's Contact Panel.
            var infos = await Windows.System.AppDiagnosticInfo.RequestInfoForAppAsync();

            contactAnnotation.ProviderProperties.Add("ContactPanelAppID", infos[0].AppInfo.AppUserModelId);

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

            var contactAnnotationLists = await contactAnnotationStore.FindAnnotationListsAsync();

            ContactAnnotationList contactAnnotationList = contactAnnotationLists.Count > 0 ? contactAnnotationLists[0] : null;

            if (contactAnnotationList == null)
            {
                contactAnnotationList = await contactAnnotationStore.CreateAnnotationListAsync();
            }


            await contactAnnotationList.TrySaveAnnotationAsync(contactAnnotation);
        }
示例#7
0
        //添加联系人进列表
        public static async Task <bool> addContactAsync(Contact contact)
        {
            if (await checkContactAsync(contact))
            {
                return(false);
            }
            var contactList = await getContactListAsync();

            await contactList.SaveContactAsync(contact);

            await contactList.SaveAsync();

            ContactAnnotation contactAnnotation = new ContactAnnotation();

            //contactAnnotation.ContactId = contact.Id;
            contactAnnotation.ContactListId = contact.ContactListId;
            contactAnnotation.RemoteId      = contact.RemoteId;
            contactAnnotation.ProviderProperties.Add("ContactPanelAppID", "18416PixeezPlusProject.PixivUWP_fsr1r9g7nfjfw!App");
            contactAnnotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;
            var contactAnnotationList = await getContactAnnotationListAsync();

            var b = await contactAnnotationList.TrySaveAnnotationAsync(contactAnnotation);

            return(true);
        }
示例#8
0
        public async static void AssignAppToPhoneContacts()
        {
            try
            {
                var store = await ContactManager.RequestStoreAsync();

                var contacts = await store.FindContactsAsync();

                if (contacts != null)
                {
                    var phonecontacts = contacts.Where(x => x.Phones.Count != 0);
                    if (phonecontacts != null)
                    {
                        foreach (var phonecontact in phonecontacts)
                        {
                            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                            ContactAnnotationList annotationList;

                            IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

                            if (0 == annotationLists.Count)
                            {
                                annotationList = await annotationStore.CreateAnnotationListAsync();
                            }
                            else
                            {
                                annotationList = annotationLists[0];
                            }

                            ContactAnnotation annotation = new ContactAnnotation();
                            annotation.ContactId = phonecontact.Id;
                            annotation.RemoteId  = phonecontact.Id;

                            annotation.SupportedOperations = ContactAnnotationOperations.Message;

                            await annotationList.TrySaveAnnotationAsync(annotation);
                        }
                    }
                }
            }
            catch
            {
            }
        }
示例#9
0
        /// <summary>
        /// Add contact
        /// </summary>
        /// <param name="user">Discord User</param>
        public async Task AddContact(User user)
        {
            if (!await CheckContact(user))
            {
                // Create contact
                Contact contact = new Contact();
                contact.Name                 = user.Username + "#" + user.Discriminator;
                contact.RemoteId             = user.Id;
                contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromUri(Common.AvatarUri(user.Avatar, user.Id));

                // Save the contacts
                ContactList contactList = await GetContactList();

                if (null == contactList)
                {
                    return;
                }
                try
                {
                    await contactList.SaveContactAsync(contact);
                }
                catch
                {
                    // :shrug:
                }

                if (annotationList == null)
                {
                    return;
                }

                // Create annotations for contact
                ContactAnnotation annotation = new ContactAnnotation();
                annotation.RemoteId            = user.Id;
                annotation.ContactId           = contact.Id;
                annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.Message | ContactAnnotationOperations.Share;
                annotation.ProviderProperties.Add("ContactPanelAppID", Windows.ApplicationModel.Package.Current.Id.FamilyName + "!App");

                // Save annotations on contact
                if (!await annotationList.TrySaveAnnotationAsync(annotation))
                {
                    Debug.WriteLine("Failed to save contact " + user.Username);
                }
            }
        }
示例#10
0
        /// <summary>
        /// Sync the contacts for the user
        /// </summary>
        /// <param name="contactList">The ContactList for this app</param>
        /// <param name="annotationList">The ContactAnnotationList</param>
        private async Task _SyncContactsAsync(
            ContactList contactList,
            ContactAnnotationList annotationList)
        {
            // This app will read the contacts from a file and do some at this time.
            // In the case of a web service, this should be done on a background task.

            // Get the XML file that contains that user information
            StorageFile file =
                await Package.Current.InstalledLocation.TryGetItemAsync("Assets\\Contacts.xml")
                as StorageFile;

            if (file == null)
            {
                return;
            }

            // Parse the XML file and create all of the contacts
            XDocument doc      = XDocument.Load(file.Path);
            var       contacts = doc.Descendants("Contact");

            foreach (XElement contact in contacts)
            {
                Contact currentContact = new Contact();
                currentContact.FirstName = contact.Attribute("FirstName").Value;
                currentContact.LastName  = contact.Attribute("LastName").Value;
                currentContact.Emails.Add(new ContactEmail()
                {
                    Address = contact.Attribute("Email").Value,
                    Kind    = ContactEmailKind.Personal
                });
                currentContact.RemoteId = contact.Attribute("Id").Value;

                await contactList.SaveContactAsync(currentContact);

                ContactAnnotation annotation = new ContactAnnotation();
                annotation.ContactId           = currentContact.Id;
                annotation.RemoteId            = currentContact.RemoteId;
                annotation.SupportedOperations =
                    ContactAnnotationOperations.SocialFeeds;

                await annotationList.TrySaveAnnotationAsync(annotation);
            }
        }
示例#11
0
        /// <summary>
        /// Creates the Me contact
        /// </summary>
        /// <param name="contactList">The ContactList for this app</param>
        /// <param name="annotationList">The ContactAnnotationList</param>
        private async Task _CreateMeContactAsync(
            ContactList contactList,
            ContactAnnotationList annotationList)
        {
            // All of the contact information will come from the web service.
            // This app will use some default values.
            Contact meContact = await contactList.GetMeContactAsync();

            meContact.FirstName = "Eleanor";
            meContact.LastName  = "Taylor";

            meContact.Emails.Add(new ContactEmail()
            {
                Address = "*****@*****.**",
                Kind    = ContactEmailKind.Personal
            });

            // The RemoteId is the ID used by the web service to identify the user.
            meContact.RemoteId = "Eleanor_Taylor";
            await contactList.SaveContactAsync(meContact);

            // Set the annotations for the me contact.
            // By setting the SocialFeeds annotation, the People app will be able to
            // show social feeds for that contact.
            ContactAnnotation annotation = new ContactAnnotation();

            annotation.ContactId           = meContact.Id;
            annotation.RemoteId            = meContact.RemoteId;
            annotation.SupportedOperations = ContactAnnotationOperations.SocialFeeds;

            bool saveSuccessful = await annotationList.TrySaveAnnotationAsync(annotation);

            if (!saveSuccessful)
            {
                throw new Exception("Could not save the annotations for the me contact.");
            }
        }
示例#12
0
        private async Task ExportAsync(ContactList contactList, ContactAnnotationList annotationList, Telegram.Td.Api.Users result)
        {
            if (result == null)
            {
                return;
            }

            var remove = new List <long>();

            var prev = _contacts;
            var next = result.UserIds.ToHashSet();

            if (prev != null)
            {
                foreach (var id in prev)
                {
                    if (!next.Contains(id))
                    {
                        remove.Add(id);
                    }
                }
            }

            _contacts = next;

            foreach (var item in remove)
            {
                var contact = await contactList.GetContactFromRemoteIdAsync("u" + item);

                if (contact != null)
                {
                    await contactList.DeleteContactAsync(contact);
                }
            }

            foreach (var item in result.UserIds)
            {
                var user = _protoService.GetUser(item);

                var contact = await contactList.GetContactFromRemoteIdAsync("u" + user.Id);

                if (contact == null)
                {
                    contact = new Contact();
                }

                if (user.ProfilePhoto != null && Telegram.Td.Api.Extensions.IsFileExisting(user.ProfilePhoto.Small.Local))
                {
                    contact.SourceDisplayPicture = await StorageFile.GetFileFromPathAsync(user.ProfilePhoto.Small.Local.Path);
                }

                contact.FirstName = user.FirstName;
                contact.LastName  = user.LastName;
                //contact.Nickname = item.Username ?? string.Empty;
                contact.RemoteId = "u" + user.Id;
                //contact.Id = item.Id.ToString();

                if (user.PhoneNumber.Length > 0)
                {
                    var phone = contact.Phones.FirstOrDefault();
                    if (phone == null)
                    {
                        phone        = new ContactPhone();
                        phone.Kind   = ContactPhoneKind.Mobile;
                        phone.Number = string.Format("+{0}", user.PhoneNumber);
                        contact.Phones.Add(phone);
                    }
                    else
                    {
                        phone.Kind   = ContactPhoneKind.Mobile;
                        phone.Number = string.Format("+{0}", user.PhoneNumber);
                    }
                }

                await contactList.SaveContactAsync(contact);

                ContactAnnotation annotation;
                var annotations = await annotationList.FindAnnotationsByRemoteIdAsync(user.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
                                                 | ContactAnnotationOperations.VideoCall
                                                 | 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);
            }
        }
示例#13
0
        public static async Task UpdateContactsListAsync()
        {
            try
            {
                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("AvatarCache", CreationCollisionOption.OpenIfExists);

                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); // requests contact permissions

                if (store != null)
                {
                    var lists = await store.FindContactListsAsync();

                    var list = lists.FirstOrDefault() ?? (await store.CreateContactListAsync(CONTACT_LIST_NAME));

                    var allContacts = await store.FindContactsAsync();

                    var removed = allContacts.Where(c =>
                    {
                        if (ulong.TryParse(c.RemoteId.Split('_').Last(), out var id))
                        {
                            return(!App.Discord.Relationships.ContainsKey(id));
                        }

                        return(false);
                    });

                    foreach (var cont in removed)
                    {
                        await list.DeleteContactAsync(cont);
                    }

                    var contactsToAnnotate = new Dictionary <DiscordRelationship, Contact>();

                    foreach (var relationship in App.Discord.Relationships.Values.Where(r => r.RelationshipType == DiscordRelationshipType.Friend))
                    {
                        var contact = await AddOrUpdateContactForRelationship(list, relationship, folder);

                        if (contact != null)
                        {
                            contactsToAnnotate[relationship] = contact;
                        }
                    }

                    if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Contacts.ContactAnnotation"))
                    {
                        var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                        var annotationList = await Tools.GetAnnotationlistAsync(annotationStore);

                        foreach (var contact in contactsToAnnotate)
                        {
                            var annotation = new ContactAnnotation()
                            {
                                ContactId           = contact.Value.Id,
                                RemoteId            = REMOTE_ID_PREFIX + contact.Key.User.Id.ToString(),
                                SupportedOperations = ContactAnnotationOperations.Share | ContactAnnotationOperations.AudioCall | ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.SocialFeeds | ContactAnnotationOperations.VideoCall
                            };

                            annotation.ProviderProperties.Add("ContactPanelAppID", APP_ID);
                            annotation.ProviderProperties.Add("ContactShareAppID", APP_ID);

                            await annotationList.TrySaveAnnotationAsync(annotation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Failed to sync contacts!");
                Logger.Log(ex.ToString());
            }
        }
        public static async Task <Contact> AddOrUpdateContactAsync(DiscordRelationship relationship, ContactList list = null, ContactAnnotationList annotationList = null, StorageFolder folder = null)
        {
            if (list == null)
            {
                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); // requests contact permissions

                var lists = await store.FindContactListsAsync();

                list = lists.FirstOrDefault(l => l.DisplayName == CONTACT_LIST_NAME) ?? (await store.CreateContactListAsync(CONTACT_LIST_NAME));
            }

            if (annotationList == null)
            {
                var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                annotationList = await Tools.GetAnnotationListAsync(annotationStore);
            }

            folder = folder ?? await ApplicationData.Current.LocalFolder.CreateFolderAsync("AvatarCache", CreationCollisionOption.OpenIfExists);

            Contact contact;

            if ((contact = await list.GetContactFromRemoteIdAsync(string.Format(REMOTE_ID_FORMAT, relationship.User.Id))) == null)
            {
                Logger.Log($"Creating new contact for user {relationship.User}");
                contact = new Contact {
                    RemoteId = string.Format(REMOTE_ID_FORMAT, relationship.User.Id)
                };
            }

            if (contact.Name != relationship.User.Username)
            {
                Logger.Log($"Updating contact username for {relationship.User}");
                contact.Name = relationship.User.Username;
            }

            var currentHash = App.LocalSettings.Read <string>("ContactAvatarHashes", relationship.User.Id.ToString(), null);

            if (currentHash == null || relationship.User.AvatarHash != currentHash)
            {
                Logger.Log($"Updating contact avatar for {relationship.User}");
                contact.SourceDisplayPicture = await GetAvatarReferenceAsync(relationship.User, folder);
            }

            await list.SaveContactAsync(contact);

            var annotations = await annotationList.FindAnnotationsByRemoteIdAsync(contact.RemoteId);

            if (!annotations.Any())
            {
                Logger.Log($"Creating new contact annotation for user {relationship.User}");

                var annotation = new ContactAnnotation()
                {
                    ContactId           = contact.Id,
                    RemoteId            = string.Format(REMOTE_ID_FORMAT, relationship.User.Id),
                    SupportedOperations = ContactAnnotationOperations.Share | ContactAnnotationOperations.AudioCall | ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile | ContactAnnotationOperations.SocialFeeds | ContactAnnotationOperations.VideoCall,
                    ProviderProperties  = { ["ContactPanelAppID"] = APP_ID, ["ContactShareAppID"] = APP_ID }
                };

                await annotationList.TrySaveAnnotationAsync(annotation);
            }

            return(contact);
        }
        private async void CreateTestContacts()
        {
            //
            // Creating two test contacts with email address and phone number.
            //

            Contact contact1 = new Contact();
            contact1.FirstName = "TestContact1";

            ContactEmail email1 = new ContactEmail();
            email1.Address = "*****@*****.**";
            contact1.Emails.Add(email1);

            ContactPhone phone1 = new ContactPhone();
            phone1.Number = "4255550100";
            contact1.Phones.Add(phone1);

            Contact contact2 = new Contact();
            contact2.FirstName = "TestContact2";

            ContactEmail email2 = new ContactEmail();
            email2.Address = "*****@*****.**";
            email2.Kind = ContactEmailKind.Other;
            contact2.Emails.Add(email2);

            ContactPhone phone2 = new ContactPhone();
            phone2.Number = "4255550101";
            phone2.Kind = ContactPhoneKind.Mobile;
            contact2.Phones.Add(phone2);

            // Save the contacts
            ContactList contactList = await _GetContactList();
            if (null == contactList)
            {
                return;
            }

            await contactList.SaveContactAsync(contact1);
            await contactList.SaveContactAsync(contact2);

            //
            // Create annotations for those test contacts.
            // Annotation is the contact meta data that allows People App to generate deep links
            // in the contact card that takes the user back into this app.
            //

            ContactAnnotationList annotationList = await _GetContactAnnotationList();
            if (null == annotationList)
            {
                return;
            }

            ContactAnnotation annotation = new ContactAnnotation();
            annotation.ContactId = contact1.Id;

            // Remote ID: The identifier of the user relevant for this app. When this app is
            // launched into from the People App, this id will be provided as context on which user
            // the operation (e.g. ContactProfile) is for.
            annotation.RemoteId = "user12";

            // The supported operations flags indicate that this app can fulfill these operations
            // for this contact. These flags are read by apps such as the People App to create deep
            // links back into this app. This app must also be registered for the relevant
            // protocols in the Package.appxmanifest (in this case, ms-contact-profile).
            annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;

            if (!await annotationList.TrySaveAnnotationAsync(annotation))
            {
                rootPage.NotifyUser("Failed to save annotation for TestContact1 to the store.", NotifyType.ErrorMessage);
                return;
            }

            annotation = new ContactAnnotation();
            annotation.ContactId = contact2.Id;
            annotation.RemoteId = "user22";

            // You can also specify multiple supported operations for a contact in a single
            // annotation. In this case, this annotation indicates that the user can be
            // communicated via VOIP call, Video Call, or IM via this application.
            annotation.SupportedOperations = ContactAnnotationOperations.Message |
                ContactAnnotationOperations.AudioCall |
                ContactAnnotationOperations.VideoCall;

            if (!await annotationList.TrySaveAnnotationAsync(annotation))
            {
                rootPage.NotifyUser("Failed to save annotation for TestContact2 to the store.", NotifyType.ErrorMessage);
                return;
            }

            rootPage.NotifyUser("Sample data created successfully.", NotifyType.StatusMessage);
        }
示例#16
0
        private async Task AddAppContactsAndAnnotationsToStoreAsync()
        {
            foreach (var appContact in _appContacts)
            {
                Uri pictureUri  = new Uri(appContact.PhotoUri);
                var pictureFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(appContact.PhotoUri));

                Contact contact = new Contact
                {
                    FirstName            = appContact.FirstName,
                    LastName             = appContact.LastName,
                    SourceDisplayPicture = pictureFile,
                    RemoteId             = appContact.ContactId
                };

                ContactEmail email1 = new ContactEmail
                {
                    Address = appContact.EmailAddress
                };

                ContactPhone phone1 = new ContactPhone
                {
                    Number = appContact.TelephoneNumber
                };

                contact.Emails.Add(email1);
                contact.Phones.Add(phone1);

                if (ContactList != null)
                {
                    try
                    {
                        await ContactList.SaveContactAsync(contact);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"Problem saving contact. Name: {contact.Name}, Message: {ex.Message}.  Try flushing ContactList with await MyContactStoreService.Current.InitializeAsync(AppContacts.ToList(), true);");
                    }
                }

                ContactAnnotation contactAnnotation = new ContactAnnotation
                {
                    ContactId           = contact.Id,
                    RemoteId            = appContact.ContactId,
                    SupportedOperations = ContactAnnotationOperations.ContactProfile |
                                          ContactAnnotationOperations.Message |
                                          ContactAnnotationOperations.Share
                };

                contactAnnotation.ProviderProperties.Add("ContactPanelAppID", "fa86aedc-86f1-4dfc-9ecf-04a41289f016_rkjxvw9zmwpp0!App");
                contactAnnotation.ProviderProperties.Add("ContactShareAppID", "fa86aedc-86f1-4dfc-9ecf-04a41289f016_rkjxvw9zmwpp0!App");

                try
                {
                    if (!await _contactAnnotationList.TrySaveAnnotationAsync(contactAnnotation))
                    {
                        throw new Exception($"Unable to save contact annotation.");
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Problem saving contact annotation. Name: {contact.Name}, Message: {ex.Message}. Try flushing ContactList with await MyContactStoreService.Current.InitializeAsync(AppContacts.ToList(), true);");
                }
            }
        }
示例#17
0
        private async void CreateContact_Click(object sender, RoutedEventArgs e)
        {
            Windows.ApplicationModel.Contacts.Contact contact = new Windows.ApplicationModel.Contacts.Contact();
            contact.FirstName = "TestContactWhatsApp";

            Windows.ApplicationModel.Contacts.ContactEmail email = new Windows.ApplicationModel.Contacts.ContactEmail();
            email.Address = "*****@*****.**";
            email.Kind    = Windows.ApplicationModel.Contacts.ContactEmailKind.Other;
            contact.Emails.Add(email);

            Windows.ApplicationModel.Contacts.ContactPhone phone = new Windows.ApplicationModel.Contacts.ContactPhone();
            phone.Number = "4255550101";
            phone.Kind   = Windows.ApplicationModel.Contacts.ContactPhoneKind.Mobile;
            contact.Phones.Add(phone);

            Windows.ApplicationModel.Contacts.ContactStore store = await
                                                                   ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            ContactList contactList;

            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            if (0 == contactLists.Count)
            {
                contactList = await store.CreateContactListAsync("WhatsAppContactList");
            }
            else
            {
                contactList = contactLists[0];
            }

            await contactList.SaveContactAsync(contact);

            //Add Annotation
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            ContactAnnotationList annotationList;

            IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

            if (0 == annotationLists.Count)
            {
                annotationList = await annotationStore.CreateAnnotationListAsync();
            }
            else
            {
                annotationList = annotationLists[0];
            }


            ContactAnnotation annotation = new ContactAnnotation();

            annotation.ContactId = contact.Id;
            annotation.RemoteId  = phone.Number; //associate the ID of a contact to an ID that your app uses internally to identify that user.

            annotation.SupportedOperations = ContactAnnotationOperations.Message |
                                             ContactAnnotationOperations.AudioCall |
                                             ContactAnnotationOperations.VideoCall |
                                             ContactAnnotationOperations.ContactProfile;


            await annotationList.TrySaveAnnotationAsync(annotation);
        }
示例#18
0
        public static async void SyncContacts()
        {
            ContactList contactList;

            //CleanUp
            {
                ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

                if (contactLists.Count > 0)
                {
                    await contactLists[0].DeleteAsync();
                }

                contactList = await store.CreateContactListAsync("Lite Messenger");
            }

            ContactAnnotationList annotationList;

            {
                ContactAnnotationStore annotationStore = await
                                                         ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);


                IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

                if (annotationLists.Count > 0)
                {
                    await annotationLists[0].DeleteAsync();
                }

                annotationList = await annotationStore.CreateAnnotationListAsync();
            }


            String appId = "4a6ce7f5-f418-4ba8-8836-c06d77ab735d_g91sr9nghxvmm!App";

            foreach (var chatHeader in Names)
            {
                //if (chatHeader.IsGroup)
                //    continue;
                Contact contact = new Contact
                {
                    FirstName = chatHeader.Name,
                    RemoteId  = chatHeader.Href
                };
                await contactList.SaveContactAsync(contact);

                ContactAnnotation annotation = new ContactAnnotation
                {
                    ContactId           = contact.Id,
                    RemoteId            = chatHeader.Href,
                    SupportedOperations = ContactAnnotationOperations.Message
                };


                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                {
                    annotation.ProviderProperties.Add("ContactPanelAppID", appId);
                    annotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile;
                }
                await annotationList.TrySaveAnnotationAsync(annotation);
            }
        }
示例#19
0
        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);
                }
            }
        }
        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;
        }
示例#21
0
        private async void CustomerSupport_Click(object sender, RoutedEventArgs e)
        {
            // Get the PinnedContactManager for the current user.
            PinnedContactManager pinnedContactManager = PinnedContactManager.GetDefault();

            // Check whether pinning to the taskbar is supported.
            if (!pinnedContactManager.IsPinSurfaceSupported(PinnedContactSurface.Taskbar))
            {
                return;
            }

            // Get the contact list for this app.
            ContactList list = await GetContactListAsync();

            // Check if the sample contact already exists.
            Contact contact = await list.GetContactFromRemoteIdAsync(Constants.ContactRemoteId);


            if (contact == null)
            {
                // Create the sample contact.
                contact           = new Contact();
                contact.FirstName = "Clippy";
                contact.LastName  = "";
                contact.RemoteId  = Constants.ContactRemoteId;
                contact.Emails.Add(new ContactEmail {
                    Address = Constants.ContactEmail
                });
                contact.Phones.Add(new ContactPhone {
                    Number = Constants.ContactPhone
                });
                contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/clippy.jpg"));

                await list.SaveContactAsync(contact);
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
            {
                // Create a new contact annotation
                ContactAnnotation annotation = new ContactAnnotation();
                annotation.ContactId = contact.Id;

                // Add appId and contact panel support to the annotation
                String appId = "d9714431-a083-4f7c-a89f-fe7a38f759e4_75cr2b68sm664!App";
                annotation.ProviderProperties.Add("ContactPanelAppID", appId);
                annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;

                // Save annotation to contact annotation list
                // Windows.ApplicationModel.Contacts.ContactAnnotationList
                var annotationList = await GetContactAnnotationList();

                await annotationList.TrySaveAnnotationAsync(annotation);
            }

            // Pin the contact to the taskbar.
            if (!await pinnedContactManager.RequestPinContactAsync(contact, PinnedContactSurface.Taskbar))
            {
                // Contact was not pinned.
                return;
            }
        }
        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;
        }
示例#23
0
        private async void CreateTestContacts()
        {
            //
            // Creating two test contacts with email address and phone number.
            //

            Contact contact1 = new Contact();

            contact1.FirstName = "TestContact1";

            ContactEmail email1 = new ContactEmail();

            email1.Address = "*****@*****.**";
            contact1.Emails.Add(email1);

            ContactPhone phone1 = new ContactPhone();

            phone1.Number = "4255550100";
            contact1.Phones.Add(phone1);

            Contact contact2 = new Contact();

            contact2.FirstName = "TestContact2";

            ContactEmail email2 = new ContactEmail();

            email2.Address = "*****@*****.**";
            email2.Kind    = ContactEmailKind.Other;
            contact2.Emails.Add(email2);

            ContactPhone phone2 = new ContactPhone();

            phone2.Number = "4255550101";
            phone2.Kind   = ContactPhoneKind.Mobile;
            contact2.Phones.Add(phone2);

            // Save the contacts
            ContactList contactList = await _GetContactList();

            if (null == contactList)
            {
                return;
            }

            await contactList.SaveContactAsync(contact1);

            await contactList.SaveContactAsync(contact2);

            //
            // Create annotations for those test contacts.
            // Annotation is the contact meta data that allows People App to generate deep links
            // in the contact card that takes the user back into this app.
            //

            ContactAnnotationList annotationList = await _GetContactAnnotationList();

            if (null == annotationList)
            {
                return;
            }

            ContactAnnotation annotation = new ContactAnnotation();

            annotation.ContactId = contact1.Id;

            // Remote ID: The identifier of the user relevant for this app. When this app is
            // launched into from the People App, this id will be provided as context on which user
            // the operation (e.g. ContactProfile) is for.
            annotation.RemoteId = "user12";

            // The supported operations flags indicate that this app can fulfill these operations
            // for this contact. These flags are read by apps such as the People App to create deep
            // links back into this app. This app must also be registered for the relevant
            // protocols in the Package.appxmanifest (in this case, ms-contact-profile).
            annotation.SupportedOperations = ContactAnnotationOperations.ContactProfile;

            if (!await annotationList.TrySaveAnnotationAsync(annotation))
            {
                rootPage.NotifyUser("Failed to save annotation for TestContact1 to the store.", NotifyType.ErrorMessage);
                return;
            }

            annotation           = new ContactAnnotation();
            annotation.ContactId = contact2.Id;
            annotation.RemoteId  = "user22";

            // You can also specify multiple supported operations for a contact in a single
            // annotation. In this case, this annotation indicates that the user can be
            // communicated via VOIP call, Video Call, or IM via this application.
            annotation.SupportedOperations = ContactAnnotationOperations.Message |
                                             ContactAnnotationOperations.AudioCall |
                                             ContactAnnotationOperations.VideoCall;

            if (!await annotationList.TrySaveAnnotationAsync(annotation))
            {
                rootPage.NotifyUser("Failed to save annotation for TestContact2 to the store.", NotifyType.ErrorMessage);
                return;
            }

            rootPage.NotifyUser("Sample data created successfully.", NotifyType.StatusMessage);
        }
示例#24
0
        private async Task ExportAsync(ContactList contactList, ContactAnnotationList annotationList, Telegram.Td.Api.Users result)
        {
            if (result == null)
            {
                return;
            }

            foreach (var item in result.UserIds)
            {
                var user = _protoService.GetUser(item);

                var contact = await contactList.GetContactFromRemoteIdAsync("u" + user.Id);

                if (contact == null)
                {
                    contact = new Contact();
                }

                if (user.ProfilePhoto != null && user.ProfilePhoto.Small.Local.IsDownloadingCompleted)
                {
                    contact.SourceDisplayPicture = await StorageFile.GetFileFromPathAsync(user.ProfilePhoto.Small.Local.Path);
                }

                contact.FirstName = user.FirstName ?? string.Empty;
                contact.LastName  = user.LastName ?? string.Empty;
                //contact.Nickname = item.Username ?? string.Empty;
                contact.RemoteId = "u" + user.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}", user.PhoneNumber);
                    contact.Phones.Add(phone);
                }
                else
                {
                    phone.Kind   = ContactPhoneKind.Mobile;
                    phone.Number = string.Format("+{0}", user.PhoneNumber);
                }

                await contactList.SaveContactAsync(contact);

                ContactAnnotation annotation;
                var annotations = await annotationList.FindAnnotationsByRemoteIdAsync(user.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");
                }

                var added = await annotationList.TrySaveAnnotationAsync(annotation);
            }
        }