Exemplo n.º 1
0
        public void updateAddressBook_Callback(JObject patchJsonObj)
        {
            if (stopContactScanning)
            {
                stopContactScanning = false;
                return;
            }
            if (patchJsonObj == null)
            {
                Thread.Sleep(1000);
                App.MqttManagerInstance.connect();
                NetworkManager.turnOffNetworkManager = false;
                scanningComplete();
                canGoBack = true;
                return;
            }

            List <ContactInfo>             updatedContacts = ContactUtils.contactsMap == null ? null : AccountUtils.getContactList(patchJsonObj, ContactUtils.contactsMap, true);
            List <ContactInfo.DelContacts> hikeIds         = null;

            // Code to delete the removed contacts
            if (ContactUtils.hike_contactsMap != null && ContactUtils.hike_contactsMap.Count != 0)
            {
                hikeIds = new List <ContactInfo.DelContacts>(ContactUtils.hike_contactsMap.Count);
                // This loop deletes all those contacts which are removed.
                foreach (string id in ContactUtils.hike_contactsMap.Keys)
                {
                    ContactInfo.DelContacts dCn = new ContactInfo.DelContacts(id, ContactUtils.hike_contactsMap[id][0].Msisdn);
                    hikeIds.Add(dCn);
                    if (App.ViewModel.ConvMap.ContainsKey(dCn.Msisdn)) // check convlist map to remove the
                    {
                        try
                        {
                            // here we are removing name so that Msisdn will be shown instead of Name
                            App.ViewModel.ConvMap[dCn.Msisdn].ContactName = null;
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("REFRESH CONTACTS :: Delete contact exception " + e.StackTrace);
                        }
                    }
                    else // if this contact is in favourite or pending and not in convMap update this also
                    {
                        ConversationListObject obj;
                        obj = App.ViewModel.GetFav(id);
                        if (obj == null) // this msisdn is not in favs , check in pending
                        {
                            obj = App.ViewModel.GetPending(id);
                        }
                        if (obj != null)
                        {
                            obj.ContactName = null;
                        }
                    }
                }
            }
            if (stopContactScanning)
            {
                stopContactScanning = false;
                return;
            }
            if (hikeIds != null && hikeIds.Count > 0)
            {
                /* Delete ids from hike user DB */
                UsersTableUtils.deleteMultipleRows(hikeIds); // this will delete all rows in HikeUser DB that are not in Addressbook.
            }
            if (updatedContacts != null && updatedContacts.Count > 0)
            {
                UsersTableUtils.updateContacts(updatedContacts);
                ConversationTableUtils.updateConversation(updatedContacts);
            }

            allContactsList = UsersTableUtils.getAllContactsByGroup();
            App.MqttManagerInstance.connect();
            NetworkManager.turnOffNetworkManager = false;

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                filteredJumpList = null;
                jumpList         = getGroupedList(allContactsList);

                // this logic handles the case where hide sms contacts is there and user refreshed the list
                if (!hideSmsContacts)
                {
                    MakeFilteredJumpList();
                    contactsListBox.ItemsSource = filteredJumpList;
                }
                else
                {
                    contactsListBox.ItemsSource = jumpList;
                }
                progressIndicator.Hide(LayoutRoot);
                enableAppBar();
            });
            canGoBack = true;
        }