private void DisplayMessage(Message message) { Dispatcher.BeginInvoke(() => { if (message.From.IndexOf(email) != 0) { gtalkHelper.ShowToast(message); } else if (message.Typing) { TypingStatus.Visibility = Visibility.Visible; ScrollToBottom(); } else { if (message.OTR != otr) { if (message.OTR) { ShowStartOtr(); } else { ShowEndOtr(); } otr = message.OTR; lock (chatLog) { while (chatLog.Count >= GoogleTalkHelper.MaximumChatLogSize) { chatLog.RemoveAt(0); } chatLog.Add(new Message { OTR = otr, Outbound = false, Time = message.Time }); } } TypingStatus.Visibility = Visibility.Collapsed; to = message.From; if (message.Body != null) { var bubble = new ReceivedChatBubble(); bubble.Text = message.Body; bubble.TimeStamp = message.Time; MessageList.Children.Add(bubble); ScrollToBottom(); } FlurryWP7SDK.Api.LogEvent("Chat - Chat recieved"); } }); }
private void Initialize() { gtalkHelper.RosterUpdated -= Initialize; Dispatcher.BeginInvoke(() => { string displayName = email; string status = string.Empty; if (App.Current.Roster.Contains(to)) { Contact t = App.Current.Roster[to]; displayName = t.NameOrEmail; status = t.Status; } PageTitle.Text = displayName.ToUpper(); if (status != string.Empty) { PageTitle.Text += ", " + char.ToUpper(status[0]) + status.Substring(1); } TypingStatus.Text = String.Format(AppResources.Chat_NoticeTyping, displayName); if (gtalkHelper.IsContactPinned(email)) { pinButton.IsEnabled = false; } chatLog = gtalkHelper.ChatLog(to); MessageList.Visibility = System.Windows.Visibility.Collapsed; MessageList.Children.Clear(); lock (chatLog) { var otr = false; foreach (var message in chatLog) { UserControl bubble; if (message.OTR != otr) { if (message.OTR) { ShowStartOtr(); } else { ShowEndOtr(); } otr = message.OTR; } if (message.Body == null) { continue; } if (message.Outbound) { bubble = new SentChatBubble(); (bubble as SentChatBubble).Text = message.Body; (bubble as SentChatBubble).TimeStamp = message.Time; } else { bubble = new ReceivedChatBubble(); (bubble as ReceivedChatBubble).Text = message.Body; (bubble as ReceivedChatBubble).TimeStamp = message.Time; } MessageList.Children.Add(bubble); } } MessageList.Visibility = System.Windows.Visibility.Visible; MessageList.UpdateLayout(); Scroller.UpdateLayout(); Scroller.ScrollToVerticalOffset(Scroller.ExtentHeight); var unread = settings["unread"] as Dictionary <string, int>; lock (unread) { unread[email] = 0; } if (App.Current.Roster.Contains(email)) { App.Current.Roster[email].UnreadCount = 0; } foreach (var con in App.Current.RecentContacts) { if (con.Email == email) { con.UnreadCount = 0; break; } } Uri url = gtalkHelper.GetPinUri(email); ShellTile existing = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri == url); if (existing != null) { existing.Update( new StandardTileData { Count = 0 } ); } var contact = App.Current.Roster[email]; if (contact != null) { contact.UnreadCount = 0; } // Sets to broadcast the first message in a conversation to = email; }); }