public ConversationsListPanorama() { InitializeComponent(); mPubSub = App.HikePubSubInstance; logger = NLog.LogManager.GetCurrentClassLogger(); appSettings = App.appSettings; App.ViewModel.MessageListPageCollection = new ObservableCollection <ConversationListObject>(); this.myListBox.ItemsSource = App.ViewModel.MessageListPageCollection; convMap = new Dictionary <string, ConversationListObject>(); LoadMessages(); registerListeners(); initAppBar(); msisdn = (string)App.appSettings[App.MSISDN_SETTING]; string name; appSettings.TryGetValue(App.ACCOUNT_NAME, out name); if (name != null) { accountName.Text = name; } creditsTxtBlck.Text = Convert.ToString(App.appSettings[App.SMS_SETTING]); photoChooserTask = new PhotoChooserTask(); photoChooserTask.ShowCamera = true; photoChooserTask.PixelHeight = 95; photoChooserTask.PixelWidth = 95; photoChooserTask.Completed += new EventHandler <PhotoResult>(photoChooserTask_Completed); Thumbnails profileThumbnail = MiscDBUtil.getThumbNailForMSisdn(msisdn + "::large"); if (profileThumbnail != null) { MemoryStream memStream = new MemoryStream(profileThumbnail.Avatar); memStream.Seek(0, SeekOrigin.Begin); BitmapImage empImage = new BitmapImage(); empImage.SetSource(memStream); avatarImage.Source = empImage; } }
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); }); } }