private void Invite_Or_Fav_Click(object sender, EventArgs e) { #region FAV SECTION if (_isAddToFavPage) { bool isPendingRemoved = false; for (int i = 0; i < (hikeFavList == null ? 0 : hikeFavList.Count); i++) { if (!App.ViewModel.Isfavourite(hikeFavList[i].Msisdn) && hikeFavList[i].Msisdn != App.MSISDN) // if not already favourite then only add to fav { ConversationListObject favObj = null; if (App.ViewModel.ConvMap.ContainsKey(hikeFavList[i].Msisdn)) { favObj = App.ViewModel.ConvMap[hikeFavList[i].Msisdn]; favObj.IsFav = true; } else { favObj = new ConversationListObject(hikeFavList[i].Msisdn, hikeFavList[i].Name, hikeFavList[i].OnHike, hikeFavList[i].Avatar); } App.ViewModel.FavList.Insert(0, favObj); if (App.ViewModel.IsPending(favObj.Msisdn)) // if this is in pending already , remove from pending and add to fav { App.ViewModel.PendingRequests.Remove(favObj); isPendingRemoved = true; } int count = 0; App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count); App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count + 1); JObject data = new JObject(); data["id"] = hikeFavList[i].Msisdn; JObject obj = new JObject(); obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.ADD_FAVOURITE; obj[HikeConstants.DATA] = data; App.HikePubSubInstance.publish(HikePubSub.MQTT_PUBLISH, obj); MiscDBUtil.SaveFavourites(favObj); App.AnalyticsInstance.addEvent(Analytics.ADD_FAVS_INVITE_USERS); } } MiscDBUtil.SaveFavourites(); if (isPendingRemoved) { MiscDBUtil.SavePendingRequests(); } App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null); } #endregion #region INVITE else { string inviteToken = ""; //App.appSettings.TryGetValue<string>(HikeConstants.INVITE_TOKEN, out inviteToken); int count = 0; foreach (string key in contactsList.Keys) { if (key == App.MSISDN) { continue; } JObject obj = new JObject(); JObject data = new JObject(); data[HikeConstants.SMS_MESSAGE] = string.Format(AppResources.sms_invite_message, inviteToken); data[HikeConstants.TIMESTAMP] = TimeUtils.getCurrentTimeStamp(); data[HikeConstants.MESSAGE_ID] = -1; obj[HikeConstants.TO] = key; obj[HikeConstants.DATA] = data; obj[HikeConstants.TYPE] = NetworkManager.INVITE; App.MqttManagerInstance.mqttPublishToServer(obj); count++; } if (count > 0) { MessageBox.Show(string.Format(AppResources.InviteUsers_TotalInvitesSent_Txt, count), AppResources.InviteUsers_FriendsInvited_Txt, MessageBoxButton.OK); } } #endregion NavigationService.GoBack(); }
public static List <ContactInfo> getContactList(JObject obj, Dictionary <string, List <ContactInfo> > new_contacts_by_id, bool isRefresh) { try { if ((obj == null) || HikeConstants.FAIL == (string)obj[HikeConstants.STAT]) { return(null); } JObject addressbook = (JObject)obj["addressbook"]; if (addressbook == null || new_contacts_by_id == null || new_contacts_by_id.Count == 0) { return(null); } bool isFavSaved = false; bool isPendingSaved = false; int hikeCount = 1, smsCount = 1; List <ContactInfo> msgToShow = null; List <string> msisdns = null; Dictionary <string, GroupInfo> allGroupsInfo = null; if (!isRefresh) { msgToShow = new List <ContactInfo>(5); msisdns = new List <string>(); } else // if refresh case load groups in cache { GroupManager.Instance.LoadGroupCache(); List <GroupInfo> gl = GroupTableUtils.GetAllGroups(); for (int i = 0; i < gl.Count; i++) { if (allGroupsInfo == null) { allGroupsInfo = new Dictionary <string, GroupInfo>(); } allGroupsInfo[gl[i].GroupId] = gl[i]; } } List <ContactInfo> server_contacts = new List <ContactInfo>(); IEnumerator <KeyValuePair <string, JToken> > keyVals = addressbook.GetEnumerator(); KeyValuePair <string, JToken> kv; int count = 0; int totalContacts = 0; while (keyVals.MoveNext()) { try { kv = keyVals.Current; JArray entries = (JArray)addressbook[kv.Key]; List <ContactInfo> cList = new_contacts_by_id[kv.Key]; for (int i = 0; i < entries.Count; ++i) { JObject entry = (JObject)entries[i]; string msisdn = (string)entry["msisdn"]; if (string.IsNullOrWhiteSpace(msisdn)) { count++; continue; } bool onhike = (bool)entry["onhike"]; ContactInfo cinfo = cList[i]; ContactInfo cn = new ContactInfo(kv.Key, msisdn, cinfo.Name, onhike, cinfo.PhoneNo); if (!isRefresh) // this is case for new installation { if (cn.Msisdn != (string)App.appSettings[App.MSISDN_SETTING]) // do not add own number { if (onhike && hikeCount <= 3 && !msisdns.Contains(cn.Msisdn)) { msisdns.Add(cn.Msisdn); msgToShow.Add(cn); hikeCount++; } if (!onhike && smsCount <= 2 && cn.Msisdn.StartsWith("+91") && !msisdns.Contains(cn.Msisdn)) // allow only indian numbers for sms { msisdns.Add(cn.Msisdn); msgToShow.Add(cn); smsCount++; } } } else // this is refresh contacts case { if (App.ViewModel.ConvMap.ContainsKey(cn.Msisdn)) // update convlist { try { App.ViewModel.ConvMap[cn.Msisdn].ContactName = cn.Name; } catch (Exception e) { Debug.WriteLine("REFRESH CONTACTS :: Update contact exception " + e.StackTrace); } } else // fav and pending case { ConversationListObject c = App.ViewModel.GetFav(cn.Msisdn); if (c != null) // this user is in favs { c.ContactName = cn.Name; MiscDBUtil.SaveFavourites(c); isFavSaved = true; } else { c = App.ViewModel.GetPending(cn.Msisdn); if (c != null) { c.ContactName = cn.Name; isPendingSaved = true; } } } GroupManager.Instance.RefreshGroupCache(cn, allGroupsInfo); } server_contacts.Add(cn); totalContacts++; } } catch (Exception ex) { Debug.WriteLine("AccountUtils : getContactList : Exception : " + ex.StackTrace); } } if (isFavSaved) { MiscDBUtil.SaveFavourites(); } if (isPendingSaved) { MiscDBUtil.SavePendingRequests(); } msisdns = null; Debug.WriteLine("Total contacts with no msisdn : {0}", count); Debug.WriteLine("Total contacts inserted : {0}", totalContacts); if (!isRefresh) { App.WriteToIsoStorageSettings(HikeConstants.AppSettings.CONTACTS_TO_SHOW, msgToShow); } return(server_contacts); } catch (ArgumentException) { return(null); } catch (Exception e) { return(null); } }
private void MenuItem_Tap_AddRemoveFav(object sender, System.Windows.Input.GestureEventArgs e) { ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem; if (selectedListBoxItem == null) { return; } GroupParticipant gp = selectedListBoxItem.DataContext as GroupParticipant; if (gp != null) { if (gp.IsFav) // already fav , remove request { MessageBoxResult result = MessageBox.Show(AppResources.Conversations_RemFromFav_Confirm_Txt, AppResources.RemFromFav_Txt, MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } gp.IsFav = false; ConversationListObject favObj = App.ViewModel.GetFav(gp.Msisdn); App.ViewModel.FavList.Remove(favObj); if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn)) { (App.ViewModel.ConvMap[gp.Msisdn]).IsFav = false; } JObject data = new JObject(); data["id"] = gp.Msisdn; JObject obj = new JObject(); obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.REMOVE_FAVOURITE; obj[HikeConstants.DATA] = data; mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj); App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null); MiscDBUtil.SaveFavourites(); MiscDBUtil.DeleteFavourite(gp.Msisdn); int count = 0; App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count); App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count - 1); App.AnalyticsInstance.addEvent(Analytics.REMOVE_FAVS_CONTEXT_MENU_GROUP_INFO); } else // add to fav { gp.IsFav = true; ConversationListObject favObj; if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn)) { favObj = App.ViewModel.ConvMap[gp.Msisdn]; favObj.IsFav = true; } else { favObj = new ConversationListObject(gp.Msisdn, gp.Name, gp.IsOnHike, MiscDBUtil.getThumbNailForMsisdn(gp.Msisdn)); } App.ViewModel.FavList.Insert(0, favObj); if (App.ViewModel.IsPending(gp.Msisdn)) { App.ViewModel.PendingRequests.Remove(favObj); MiscDBUtil.SavePendingRequests(); } MiscDBUtil.SaveFavourites(); MiscDBUtil.SaveFavourites(favObj); int count = 0; App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count); App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count + 1); JObject data = new JObject(); data["id"] = gp.Msisdn; JObject obj = new JObject(); obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.ADD_FAVOURITE; obj[HikeConstants.DATA] = data; mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj); App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null); App.AnalyticsInstance.addEvent(Analytics.ADD_FAVS_CONTEXT_MENU_GROUP_INFO); } } }