private async void DisplayPastMessagesAsync(IEnumerable <ChatMessage> messages) { foreach (ChatMessage message in messages) { if (!message.IsOutgoing) { IncomingChatBubble bubble = new IncomingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.DownloadImage += bubble_DownloadImage; bubble.ImageTapped += Bubble_ImageTapped; bubble.RefreshImage(); MessagesList.Children.Add(bubble); } else { if (!message.IsText && message.FileTransferInformation != null) { var tempFolder = ApplicationData.Current.LocalFolder; string name = message.FileTransferInformation.Name; StorageFile tempFile = await tempFolder.GetFileAsync(name.Substring(0, name.IndexOf('.'))); message.FileTransferFilepath = tempFile.Path; } OutgoingChatBubble bubble = new OutgoingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.UpdateStatus(message.State); bubble.RefreshImage(); MessagesList.Children.Add(bubble); } } }
/// <summary> /// Callback called by LinphoneCore when the state of a sent message changes. /// </summary> public void MessageStateChanged(LinphoneChatMessage message, LinphoneChatMessageState state) { Logger.Msg("[Chat] Message state changed: " + state.ToString()); Dispatcher.BeginInvoke(() => { if (ProgressPopup.Visibility == Visibility.Visible) { ProgressPopup.Visibility = Visibility.Collapsed; MessageBox.Visibility = Visibility.Visible; AddSendButtonsToAppBar(); } if (state == LinphoneChatMessageState.InProgress) { // Create the chat bubble for both text or image messages OutgoingChatBubble bubble = new OutgoingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble); scrollToBottom(); } else if (state == LinphoneChatMessageState.FileTransferDone && !message.IsOutgoing) { try { message.AppData = message.FileTransferFilePath; ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last(); if (bubble != null) { ((IncomingChatBubble)bubble).RefreshImage(); } EnableDownloadButtons(true); } catch { } } else { // Update the outgoing status of the message try { ChatBubble bubble = (ChatBubble)MessagesList.Children.Where(b => message.Equals(((ChatBubble)b).ChatMessage)).Last(); if (bubble != null) { ((OutgoingChatBubble)bubble).UpdateStatus(state); } } catch { } } if (chatRoom != null) { chatRoom.MarkAsRead(); } }); }
private void DisplayPastMessages(IList <Object> messages) { foreach (LinphoneChatMessage message in messages) { if (!message.IsOutgoing) { IncomingChatBubble bubble = new IncomingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.DownloadImage += bubble_DownloadImage; MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble); } else { OutgoingChatBubble bubble = new OutgoingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.UpdateStatus(message.State); MessagesList.Children.Insert(MessagesList.Children.Count - 1, bubble); } } scrollToBottom(); }
private void DisplayPastMessages(IList <ChatMessage> messages) { foreach (ChatMessage message in messages) { if (!message.IsOutgoing) { IncomingChatBubble bubble = new IncomingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.DownloadImage += bubble_DownloadImage; bubble.ImageTapped += Bubble_ImageTapped; MessagesList.Children.Add(bubble); } else { OutgoingChatBubble bubble = new OutgoingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; bubble.UpdateStatus(message.State); MessagesList.Children.Add(bubble); } } scrollToBottom(); }
/* private void cm_ContactFound(object sender, ContactFoundEventArgs e) * { * if (e.ContactFound != null) * { * ContactName.Text = e.ContactFound.DisplayName; * ContactManager.Instance.TempContact = e.ContactFound; * ContactName.Tap += ContactName_Tap; * * ContactName.Visibility = Visibility.Visible; * NewChat.Visibility = Visibility.Collapsed; * } * }*/ /* private void ContactName_Tap(object sender, System.Windows.Input.GestureEventArgs e) * { * NavigationService.Navigate(new Uri("/Views/Contact.xaml", UriKind.RelativeOrAbsolute)); * }*/ public void MessageStateChanged(ChatMessage message, ChatMessageState state) { if (LinphoneManager.Instance.CoreDispatcher == null) { return; } #pragma warning disable CS4014 // Dans la mesure où cet appel n'est pas attendu, l'exécution de la méthode actuelle continue avant la fin de l'appel LinphoneManager.Instance.CoreDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { if (ProgressPopup.Visibility == Visibility.Visible) { ProgressPopup.Visibility = Visibility.Collapsed; MessageBox.Visibility = Visibility.Visible; } if (state == ChatMessageState.Delivered) { if (messageUploading != null && messageUploading.Equals(message)) { messageUploading = null; } } if (state == ChatMessageState.InProgress && message.IsOutgoing && messageUploading == null) { // Create the chat bubble for both text or image messages if (message.Appdata != null && messageUploading == null) { messageUploading = message; } OutgoingChatBubble bubble = new OutgoingChatBubble(message); bubble.MessageDeleted += bubble_MessageDeleted; MessagesList.Children.Add(bubble); scrollToBottom(); } else if (state == ChatMessageState.FileTransferDone && !message.IsOutgoing) { try { IncomingChatBubble bubble = (IncomingChatBubble)MessagesList.Children.OfType <IncomingChatBubble>().Where(b => message.Equals(((IncomingChatBubble)b).ChatMessage)).Last(); if (bubble != null) { ((IncomingChatBubble)bubble).ChatMessage.FileTransferFilepath = message.FileTransferFilepath; ((IncomingChatBubble)bubble).RefreshImage(); } EnableDownloadButtons(true); } catch { Debug.WriteLine("Cannot create load download image"); } } else if (state == ChatMessageState.FileTransferDone && message.IsOutgoing) { try { OutgoingChatBubble bubble = (OutgoingChatBubble)MessagesList.Children.OfType <OutgoingChatBubble>().Where(b => message.Equals(((OutgoingChatBubble)b).ChatMessage)).Last(); if (bubble != null) { ((OutgoingChatBubble)bubble).ChatMessage.FileTransferFilepath = message.FileTransferFilepath; ((OutgoingChatBubble)bubble).RefreshImage(); } } catch { Debug.WriteLine("Cannot load uploaded image"); } } else { try { foreach (OutgoingChatBubble bubble in MessagesList.Children.OfType <OutgoingChatBubble>()) { if (bubble.ChatMessage.Equals(message)) { bubble.UpdateStatus(state); } } } catch { Debug.WriteLine("Cannot update message state"); } } if (chatRoom != null) { chatRoom.MarkAsRead(); } }); }