private void MenuItem_Tap_AddUser(object sender, System.Windows.Input.GestureEventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) { MessageBoxResult result = MessageBox.Show(AppResources.Please_Try_Again_Txt, AppResources.No_Network_Txt, MessageBoxButton.OK); return; } ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem; if (selectedListBoxItem == null) { return; } gp_obj = selectedListBoxItem.DataContext as GroupParticipant; if (gp_obj == null) { return; } if (!gp_obj.Msisdn.Contains(gp_obj.Name)) // shows name is already stored so return { return; } ContactInfo ci = UsersTableUtils.getContactInfoFromMSISDN(gp_obj.Msisdn); if (ci != null) { return; } ContactUtils.saveContact(gp_obj.Msisdn, new ContactUtils.contactSearch_Callback(saveContactTask_Completed)); }
public GroupParticipant getGroupParticipant(string defaultName, string msisdn, string grpId) { if (grpId == null) { return(null); } if (groupCache.ContainsKey(grpId)) { List <GroupParticipant> l = groupCache[grpId]; for (int i = 0; i < l.Count; i++) { if (l[i].Msisdn == msisdn) { return(l[i]); } } } ContactInfo cInfo = UsersTableUtils.getContactInfoFromMSISDN(msisdn); GroupParticipant gp = new GroupParticipant(grpId, cInfo != null ? cInfo.Name : string.IsNullOrWhiteSpace(defaultName) ? msisdn : defaultName, msisdn, cInfo != null ? cInfo.OnHike : true); if (groupCache.ContainsKey(grpId)) { groupCache[grpId].Add(gp); return(gp); } List <GroupParticipant> ll = new List <GroupParticipant>(); ll.Add(gp); groupCache.Add(grpId, ll); return(gp); }
public InviteUsers() { InitializeComponent(); object hikeFriends; if (PhoneApplicationService.Current.State.TryGetValue("HIKE_FRIENDS", out hikeFriends)) { topHeader.Text = AppResources.Add_To_Fav_Txt; title.Text = AppResources.Hike_Friends_Text; enterNameTxt.Visibility = System.Windows.Visibility.Collapsed; _isAddToFavPage = true; } shellProgress.IsVisible = true; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { if (_isAddToFavPage) { allContactsList = UsersTableUtils.GetAllHikeContactsOrdered(); } else { allContactsList = UsersTableUtils.getAllContactsToInvite(); } }; bw.RunWorkerAsync(); bw.RunWorkerCompleted += (s, e) => { if (_isAddToFavPage) { if (allContactsList == null || allContactsList.Count == 0) { emptyHikeFriendsTxt.Visibility = Visibility.Visible; } } jumpList = getGroupedList(allContactsList); contactsListBox.ItemsSource = jumpList; shellProgress.IsVisible = false; }; initPage(); }
private void btnGetSelected_Tap(object sender, System.Windows.Input.GestureEventArgs e) { groupChatParticipants.SelectedIndex = -1; gp_obj = (sender as ListBox).SelectedItem as GroupParticipant; if (gp_obj == null) { return; } if (!gp_obj.Msisdn.Contains(gp_obj.Name)) // shows name is already stored so return { return; } ContactInfo ci = UsersTableUtils.getContactInfoFromMSISDN(gp_obj.Msisdn); if (ci != null) { return; } ContactUtils.saveContact(gp_obj.Msisdn, new ContactUtils.contactSearch_Callback(saveContactTask_Completed)); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (isFirstLaunch) { if (App.appSettings.TryGetValue(App.PAGE_STATE, out ps) && ps == App.PageState.NUX_SCREEN_FAMILY) { txtHeader.Text = AppResources.Nux_InviteFamily_Txt; txtConnectHike.Text = AppResources.Nux_FamilyMembersConnect_txt; } listCloseFriends = new List<ContactInfo>(); listFamilyMembers = new List<ContactInfo>(); progressBar.Opacity = 1; progressBar.IsEnabled = true; listContactInfo = UsersTableUtils.GetContactsFromFile(); if (listContactInfo == null || listContactInfo.Count == 0) { App.appSettings[App.PAGE_STATE] = App.PageState.CONVLIST_SCREEN; NavigationService.Navigate(new Uri("/View/ConversationsList.xaml", UriKind.Relative)); return; } BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, a) => { Stopwatch st = Stopwatch.StartNew(); ProcessNuxContacts(listContactInfo); st.Stop(); Debug.WriteLine("Time to process NUX in NUX Screen is {0} ms", st.ElapsedMilliseconds); }; bw.RunWorkerAsync(); bw.RunWorkerCompleted += LoadingCompleted; if (NavigationService.CanGoBack) NavigationService.RemoveBackEntry(); isFirstLaunch = false; } }
private void LoadMessages() { List <Conversation> conversationList = ConversationTableUtils.getAllConversations(); if (conversationList == null) { return; } for (int i = 0; i < conversationList.Count; i++) { Conversation conv = conversationList[i]; ConvMessage lastMessage = MessagesTableUtils.getLastMessageForMsisdn(conv.Msisdn); // why we are not getting only lastmsg as string ContactInfo contact = UsersTableUtils.getContactInfoFromMSISDN(conv.Msisdn); Thumbnails thumbnail = MiscDBUtil.getThumbNailForMSisdn(conv.Msisdn); ConversationListObject mObj = new ConversationListObject((contact == null) ? conv.Msisdn : contact.Msisdn, (contact == null) ? conv.Msisdn : contact.Name, lastMessage.Message, (contact == null) ? conv.OnHike : contact.OnHike, TimeUtils.getTimeString(lastMessage.Timestamp), thumbnail == null ? null : thumbnail.Avatar); convMap.Add(conv.Msisdn, mObj); App.ViewModel.MessageListPageCollection.Add(mObj); } }
public void onEventReceived(string type, object obj) { if (HikePubSub.MESSAGE_RECEIVED == type || HikePubSub.SEND_NEW_MSG == type) { ConvMessage convMessage = (ConvMessage)obj; ConversationListObject mObj; bool isNewConversation = false; /*This is used to avoid cross thread invokation exception*/ if (convMap.ContainsKey(convMessage.Msisdn)) { mObj = convMap[convMessage.Msisdn]; mObj.LastMessage = convMessage.Message; mObj.TimeStamp = TimeUtils.getTimeString(convMessage.Timestamp); Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModel.MessageListPageCollection.Remove(mObj); }); } else { ContactInfo contact = UsersTableUtils.getContactInfoFromMSISDN(convMessage.Msisdn); Thumbnails thumbnail = MiscDBUtil.getThumbNailForMSisdn(convMessage.Msisdn); mObj = new ConversationListObject(convMessage.Msisdn, contact == null ? convMessage.Msisdn : contact.Name, convMessage.Message, contact == null ? !convMessage.IsSms : contact.OnHike, TimeUtils.getTimeString(convMessage.Timestamp), thumbnail == null ? null : thumbnail.Avatar); convMap.Add(convMessage.Msisdn, mObj); isNewConversation = true; } Deployment.Current.Dispatcher.BeginInvoke(() => { if (App.ViewModel.MessageListPageCollection == null) { App.ViewModel.MessageListPageCollection = new ObservableCollection <ConversationListObject>(); } App.ViewModel.MessageListPageCollection.Insert(0, mObj); }); object[] vals = new object[2]; vals[0] = convMessage; vals[1] = isNewConversation; if (HikePubSub.SEND_NEW_MSG == type) { mPubSub.publish(HikePubSub.MESSAGE_SENT, vals); } } else if (HikePubSub.MSG_READ == type) { string msisdn = (string)obj; try { ConversationListObject convObj = convMap[msisdn]; convObj.MessageStatus = ConvMessage.State.RECEIVED_READ; //TODO : update the UI here also. } catch (KeyNotFoundException) { } } else if ((HikePubSub.USER_LEFT == type) || (HikePubSub.USER_JOINED == type)) { string msisdn = (string)obj; try { ConversationListObject convObj = convMap[msisdn]; convObj.IsOnhike = HikePubSub.USER_JOINED == type; } catch (KeyNotFoundException) { } } else if (HikePubSub.UPDATE_UI == type) { string msisdn = (string)obj; try { ConversationListObject convObj = convMap[msisdn]; Deployment.Current.Dispatcher.BeginInvoke(() => { convObj.NotifyPropertyChanged("Msisdn"); }); } catch (KeyNotFoundException) { } } else if (HikePubSub.SMS_CREDIT_CHANGED == type) { Deployment.Current.Dispatcher.BeginInvoke(() => { creditsTxtBlck.Text = Convert.ToString((int)obj); }); } }
public void ProcessNuxContacts(List<ContactInfo> listContact) { if (listContact != null && listContact.Count > 0 && listFamilyMembers != null && listCloseFriends != null) { Stopwatch st = Stopwatch.StartNew(); List<ContactInfo> listContactsFromDb = UsersTableUtils.getAllContactsToInvite(); st.Stop(); Debug.WriteLine("Time taken to fetch contacts to be invited :{0}", st.ElapsedMilliseconds); if (listContactsFromDb == null) listContactsFromDb = new List<ContactInfo>(); string lastName = GetLastName(); bool isLastNameCheckApplicable = lastName != null; st.Reset(); st.Start(); listContact.Sort(new ContactCompare()); st.Stop(); Debug.WriteLine("Time taken to sort :{0}", st.ElapsedMilliseconds); st.Reset(); st.Start(); Dictionary<string, ContactInfo> dictContactsInDb = new Dictionary<string, ContactInfo>(); foreach (ContactInfo cinfo in listContactsFromDb) { dictContactsInDb[cinfo.Name + cinfo.PhoneNo] = cinfo; } foreach (ContactInfo cn in listContact) { if (listCloseFriends.Count == 30 && listFamilyMembers.Count == 30) break; ContactInfo contactFromDb; if (!dictContactsInDb.TryGetValue(cn.Name + cn.PhoneNo, out contactFromDb)) continue; cn.Msisdn = contactFromDb.Msisdn; bool markedForNux = false; if (listFamilyMembers.Count < 30) { if (!string.IsNullOrEmpty(cn.Name)) { string[] nameArray = cn.Name.Trim().Split(' '); if (isLastNameCheckApplicable) { if (nameArray.Length > 1) { string curlastName = nameArray[nameArray.Length - 1]; if (curlastName.Equals(lastName, StringComparison.OrdinalIgnoreCase)) { listFamilyMembers.Add(cn); markedForNux = true; } } } if (!markedForNux && MatchFromFamilyVocab(nameArray)) { markedForNux = true; listFamilyMembers.Add(cn); } } } if (!markedForNux && listCloseFriends.Count < 30) { markedForNux = true; listCloseFriends.Add(cn); } } st.Stop(); Debug.WriteLine("Time fr nux scanning " + st.ElapsedMilliseconds); } }
/* This is the callback function which is called when server returns the addressbook*/ public void postAddressBook_Callback(JObject jsonForAddressBookAndBlockList) { // test this is called JObject obj = jsonForAddressBookAndBlockList; if (obj == null) { Debug.WriteLine("Post addbook request returned unsuccessfully .... "); ContactUtils.ContactState = ContactUtils.ContactScanState.ADDBOOK_STORE_FAILED; Deployment.Current.Dispatcher.BeginInvoke(() => { // if next button is clicked show the error msg if (isClicked) { this.msgTxtBlk.Opacity = 0; this.nameErrorTxt.Text = AppResources.Contact_Scanning_Failed_Txt; this.nameErrorTxt.Visibility = Visibility.Visible; this.progressBar.IsEnabled = false; this.progressBar.Opacity = 0; this.nextIconButton.IsEnabled = true; this.txtBxEnterName.IsReadOnly = false; isClicked = false; } }); return; } Debug.WriteLine("Post addbook request returned successfully .... "); List <ContactInfo> addressbook = AccountUtils.getContactList(jsonForAddressBookAndBlockList, ContactUtils.contactsMap, false); List <string> blockList = AccountUtils.getBlockList(jsonForAddressBookAndBlockList); int count = 1; // waiting for DB to be created while (!App.appSettings.Contains(App.IS_DB_CREATED) && count <= 120) { Thread.Sleep(1 * 500); count++; } if (!App.appSettings.Contains(App.IS_DB_CREATED)) // if DB is not created for so long { Deployment.Current.Dispatcher.BeginInvoke(() => { Debug.WriteLine("Phone DB is not created in time .... "); ContactUtils.ContactState = ContactUtils.ContactScanState.ADDBOOK_STORE_FAILED; this.msgTxtBlk.Text = AppResources.EnterName_Failed_Txt; }); return; } try { // if addressbook is null, then also user should be able to move inside app. UsersTableUtils.deleteAllContacts(); UsersTableUtils.deleteBlocklist(); Stopwatch st = Stopwatch.StartNew(); UsersTableUtils.addContacts(addressbook); // add the contacts to hike users db. st.Stop(); long msec = st.ElapsedMilliseconds; Debug.WriteLine("Time to add addressbook {0}", msec); UsersTableUtils.addBlockList(blockList); } catch (Exception e) { Debug.WriteLine("EnterName :: postAddressBook_Callback : Exception : " + e.StackTrace); } Debug.WriteLine("Addbook stored in Hike Db .... "); App.WriteToIsoStorageSettings(ContactUtils.IS_ADDRESS_BOOK_SCANNED, true); ContactUtils.ContactState = ContactUtils.ContactScanState.ADDBOOK_STORED_IN_HIKE_DB; }
public void updateAddressBook_Callback(JObject obj) { if ((obj == null) || HikeConstants.FAIL == (string)obj[HikeConstants.STAT]) { Dispatcher.BeginInvoke(() => { MessageBox.Show(AppResources.CONTACT_NOT_SAVED_ON_SERVER); }); return; } JObject addressbook = (JObject)obj["addressbook"]; if (addressbook == null) { Dispatcher.BeginInvoke(() => { MessageBox.Show(AppResources.CONTACT_NOT_SAVED_ON_SERVER); }); return; } IEnumerator <KeyValuePair <string, JToken> > keyVals = addressbook.GetEnumerator(); KeyValuePair <string, JToken> kv; int count = 0; while (keyVals.MoveNext()) { kv = keyVals.Current; JArray entries = (JArray)addressbook[kv.Key]; for (int i = 0; i < entries.Count; ++i) { JObject entry = (JObject)entries[i]; string msisdn = (string)entry["msisdn"]; if (string.IsNullOrWhiteSpace(msisdn)) { continue; } bool onhike = (bool)entry["onhike"]; contactInfo.Msisdn = msisdn; contactInfo.OnHike = onhike; count++; } } UsersTableUtils.addContact(contactInfo); Dispatcher.BeginInvoke(() => { gp_obj.Name = contactInfo.Name; GroupParticipant gp = GroupManager.Instance.getGroupParticipant(gp_obj.Name, gp_obj.Msisdn, groupId); gp.Name = gp_obj.Name; GroupManager.Instance.GetParticipantList(groupId).Sort(); GroupManager.Instance.SaveGroupCache(groupId); // if default grp name is not set , then only update grp if (gi.GroupName == null) { string gpName = GroupManager.Instance.defaultGroupName(groupId); groupNameTxtBox.Text = gpName; if (App.newChatThreadPage != null) { App.newChatThreadPage.userName.Text = gpName; } if (App.ViewModel.ConvMap.ContainsKey(groupId)) { App.ViewModel.ConvMap[groupId].ContactName = gpName; } } // update normal 1-1 chat contact if (App.ViewModel.ConvMap.ContainsKey(gp_obj.Msisdn)) { App.ViewModel.ConvMap[gp_obj.Msisdn].ContactName = contactInfo.Name; } else // fav and pending case update { ConversationListObject co = App.ViewModel.GetFav(gp_obj.Msisdn); if (co != null) { co.ContactName = contactInfo.Name; } } if (count > 1) { MessageBox.Show(string.Format(AppResources.MORE_THAN_1_CONTACT_FOUND, gp_obj.Msisdn)); } else { MessageBox.Show(AppResources.CONTACT_SAVED_SUCCESSFULLY); } }); }
/* This callback is on background thread started by getContacts function */ public void makePatchRequest_Callback(object sender, ContactsSearchEventArgs e) { if (stopContactScanning) { stopContactScanning = false; return; } Dictionary <string, List <ContactInfo> > new_contacts_by_id = ContactUtils.getContactsListMap(e.Results); Dictionary <string, List <ContactInfo> > hike_contacts_by_id = ContactUtils.convertListToMap(UsersTableUtils.getAllContacts()); /* If no contacts in Phone as well as App , simply return */ if ((new_contacts_by_id == null || new_contacts_by_id.Count == 0) && hike_contacts_by_id == null) { scanningComplete(); canGoBack = true; return; } Dictionary <string, List <ContactInfo> > contacts_to_update_or_add = new Dictionary <string, List <ContactInfo> >(); if (new_contacts_by_id != null) // if there are contacts in phone perform this step { foreach (string id in new_contacts_by_id.Keys) { List <ContactInfo> phList = new_contacts_by_id[id]; if (hike_contacts_by_id == null || !hike_contacts_by_id.ContainsKey(id)) { contacts_to_update_or_add.Add(id, phList); continue; } List <ContactInfo> hkList = hike_contacts_by_id[id]; if (!ContactUtils.areListsEqual(phList, hkList)) { contacts_to_update_or_add.Add(id, phList); } hike_contacts_by_id.Remove(id); } new_contacts_by_id.Clear(); new_contacts_by_id = null; } /* If nothing is changed simply return without sending update request*/ if (contacts_to_update_or_add.Count == 0 && (hike_contacts_by_id == null || hike_contacts_by_id.Count == 0)) { Thread.Sleep(1000); scanningComplete(); canGoBack = true; return; } JArray ids_to_delete = new JArray(); if (hike_contacts_by_id != null) { foreach (string id in hike_contacts_by_id.Keys) { ids_to_delete.Add(id); } } ContactUtils.contactsMap = contacts_to_update_or_add; ContactUtils.hike_contactsMap = hike_contacts_by_id; App.MqttManagerInstance.disconnectFromBroker(false); NetworkManager.turnOffNetworkManager = true; /* * contacts_to_update : These are the contacts to add * ids_json : These are the contacts to delete */ if (stopContactScanning) { stopContactScanning = false; return; } AccountUtils.updateAddressBook(contacts_to_update_or_add, ids_to_delete, new AccountUtils.postResponseFunction(updateAddressBook_Callback)); }
public NewSelectUserPage() { InitializeComponent(); App.appSettings.TryGetValue <bool>(App.SHOW_FREE_SMS_SETTING, out isFreeSmsOn); if (isFreeSmsOn) { hideSmsContacts = true; } else { hideSmsContacts = false; } object obj; if (PhoneApplicationService.Current.State.TryGetValue(HikeConstants.FORWARD_MSG, out obj) && obj is object[]) { object[] attachmentForwardMessage = (object[])obj; if (attachmentForwardMessage.Length == 2 && attachmentForwardMessage[0] is MyChatBubble && ((MyChatBubble)attachmentForwardMessage[0]).FileAttachment.ContentType.Contains(HikeConstants.CONTACT)) { hideSmsContacts = false; isContactShared = true; } } //case when share contact is called if (PhoneApplicationService.Current.State.ContainsKey(HikeConstants.SHARE_CONTACT)) { isContactShared = true; hideSmsContacts = true; txtChat.Visibility = Visibility.Collapsed; txtTitle.Text = AppResources.ShareContact_Txt; } /* Case when this page is called from GroupInfo page*/ if (PhoneApplicationService.Current.State.ContainsKey(HikeConstants.EXISTING_GROUP_MEMBERS)) { isGroupChat = true; TAP_MSG = AppResources.SelectUser_TapMsg_Grp_Txt; } /* Case when this page is called from create group button.*/ if (PhoneApplicationService.Current.State.ContainsKey(HikeConstants.START_NEW_GROUP)) { isGroupChat = (bool)PhoneApplicationService.Current.State[HikeConstants.START_NEW_GROUP]; TAP_MSG = AppResources.SelectUser_TapMsg_Grp_Txt; } //if (isGroupChat) // title.Text = "new group chat"; shellProgress.IsVisible = true; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { allContactsList = UsersTableUtils.getAllContactsByGroup(); }; bw.RunWorkerAsync(); bw.RunWorkerCompleted += (s, e) => { jumpList = getGroupedList(allContactsList); if (!hideSmsContacts) { if (filteredJumpList == null) { MakeFilteredJumpList(); } contactsListBox.ItemsSource = filteredJumpList; } else { contactsListBox.ItemsSource = jumpList; } shellProgress.IsVisible = false; }; initPage(); App.HikePubSubInstance.addListener(HikePubSub.GROUP_END, this); }
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; }