void CoreListener.MessageReceived(ChatRoom room, ChatMessage message) { if (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 CoreDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (MessageReceived != null) { MessageReceived(room, message); } Address fromAddress = message.FromAddress; string sipAddress = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain); if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress)) { MessageListener.MessageReceived(message); } else { string url = message.ExternalBodyUrl; url = url.Replace("\"", ""); if (MessageReceivedNotification != null) { ToastNotificationManager.History.Clear(); } XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(sipAddress)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(message.Text)); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("launch", "chat ? sip = " + sipAddress); MessageReceivedNotification = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(MessageReceivedNotification); } }); #pragma warning restore 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 }
void OnMessageReceived(Core lc, ChatRoom room, ChatMessage message) { if (CoreDispatcher == null) { return; } if (MessageReceived != null) { MessageReceived(room, message); } Address fromAddress = message.FromAddress; string sipAddress = String.Format("{0}@{1}", fromAddress.Username, fromAddress.Domain); if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress)) { MessageListener.MessageReceived(message); } else { string url = message.ExternalBodyUrl; //url = url.Replace("\"", ""); if (MessageReceivedNotification != null) { ToastNotificationManager.History.Clear(); } XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(sipAddress)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(message.Text)); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("launch", "chat ? sip = " + sipAddress); MessageReceivedNotification = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(MessageReceivedNotification); } }
/// <summary> /// Callback for LinphoneCoreListener /// </summary> public void MessageReceived(LinphoneChatMessage message) { if (BaseModel.UIDispatcher == null) { return; } BaseModel.UIDispatcher.BeginInvoke(() => { LinphoneAddress fromAddress = message.From; string sipAddress = String.Format("{0}@{1}", fromAddress.UserName, fromAddress.Domain); Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.Text + "\r\n"); //Vibrate ChatSettingsManager settings = new ChatSettingsManager(); settings.Load(); if ((bool)settings.VibrateOnIncomingMessage) { VibrationDevice vibrator = VibrationDevice.GetDefault(); vibrator.Vibrate(TimeSpan.FromSeconds(1)); } if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress)) { MessageListener.MessageReceived(message); } else { DateTime date = new DateTime(message.Time * TimeSpan.TicksPerSecond, DateTimeKind.Utc).AddYears(1969).ToLocalTime(); DateTime now = DateTime.Now; string dateStr; if (now.Year == date.Year && now.Month == date.Month && now.Day == date.Day) { dateStr = String.Format("{0:HH:mm}", date); } else if (now.Year == date.Year) { dateStr = String.Format("{0:ddd d MMM, HH:mm}", date); } else { dateStr = String.Format("{0:ddd d MMM yyyy, HH:mm}", date); } //TODO: Temp hack to remove string url = message.ExternalBodyUrl; url = url.Replace("\"", ""); //Displays the message as a popup if (MessageReceivedNotification != null) { MessageReceivedNotification.Dismiss(); } MessageReceivedNotification = new CustomMessageBox() { Title = dateStr, Caption = url.Length > 0 ? AppResources.ImageMessageReceived : AppResources.MessageReceived, Message = url.Length > 0 ? "" : message.Text, LeftButtonContent = AppResources.Close, RightButtonContent = AppResources.Show }; MessageReceivedNotification.Dismissed += (s, e) => { switch (e.Result) { case CustomMessageBoxResult.RightButton: BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/Chat.xaml?sip=" + Utils.ReplacePlusInUri(message.PeerAddress.AsStringUriOnly()), UriKind.RelativeOrAbsolute)); break; } }; MessageReceivedNotification.Show(); } }); }