Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Load ContactAnnotation List
        /// </summary>
        /// <returns></returns>
        private async Task <ContactAnnotationList> GetContactAnnotationList()
        {
            // If annotation list is already determined, return it
            if (annotationList == null)
            {
                // Initialize annotations contact store
                annotationStore = await Windows.ApplicationModel.Contacts.ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                if (annotationStore == null)
                {
                    // Unavailable, call it quits
                    return(null);
                }

                // Get annotations list
                IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

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

            return(annotationList);
        }
Example #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);
        }
Example #4
0
        public static async Task <ContactAnnotationList> GetAnnotationListAsync(ContactAnnotationStore store)
        {
            var lists = await store.FindAnnotationListsAsync();

            var list = lists.FirstOrDefault();

            if (list == null)
            {
                list = await store.CreateAnnotationListAsync();
            }

            return(list);
        }
Example #5
0
        /// <summary>
        /// Get the ContactAnnotationList
        /// </summary>
        private async Task <ContactAnnotationList> _GetContactAnnotationListAsync()
        {
            // Get the store and all of the annotation lists
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

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

            ContactAnnotationList annotationList;

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

            return(annotationList);
        }
Example #6
0
        private static async Task <ContactAnnotationList> GetContactAnnotationList()
        {
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            if (null == annotationStore)
            {
                return(null);
            }
            ContactAnnotationList annotationList;
            IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

            if (0 == annotationLists.Count)
            {
                annotationList = await annotationStore.CreateAnnotationListAsync();
            }
            else
            {
                annotationList = annotationLists[0];
            }
            return(annotationList);
        }
        private async Task <ContactAnnotationList> _GetContactAnnotationList()
        {
            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            if (null == annotationStore)
            {
                rootPage.NotifyUser("Unable to get an annotations store.", NotifyType.ErrorMessage);
                return(null);
            }

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

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

            return(annotationList);
        }
Example #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
            {
            }
        }
        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;
        }
        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;
        }
Example #11
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);
        }
Example #12
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);
            }
        }