/// <summary> /// OnNewIncomingConversation /// Handles new conversations initiated by a peer /// </summary> private void OnNewIncomingConversation(Conversation conversation, ChatType chatType) { Logger.Debug("NotificationManager.OnNewIncomingConversation was called"); if(conversation.PeerUser == null) { Logger.Error("NewIncomingConversation event had a conversation with null PeerUser"); return; } // If we have a ChatWindow for this conversation, don't do anything... the ChatWindow // will handle the change if(ChatWindowManager.ChatWindowExists(conversation.PeerUser.ID)) return; if(chatType == ChatType.Text) { NotifyOfTextMessage(conversation); } else if(chatType == ChatType.Audio) { NotifyOfAudioRequest(conversation); } else if(chatType == ChatType.Video) { NotifyOfVideoRequest(conversation); } conversation.MessageReceived += OnTextAdditionalMessageReceived; conversation.MediaChannelOpened += OnMediaChannelOpened; conversation.MediaChannelClosed += OnMediaChannelClosed; conversation.TextChannelOpened += OnTextChannelOpened; }
///<summary> /// OnTextAdditionalMessageReceived /// Handles additional Text messages on a pending conversation ///</summary> private void OnTextAdditionalMessageReceived(Conversation conversation, Message message) { Logger.Debug("NotificationManager.OnTextAdditionalMessageReceived was called"); NotifyOfTextMessage(conversation); }
/// <summary> /// NotifyOfVideoRequest /// Notifies user of an incoming video request /// </summary> private void NotifyOfVideoRequest(Conversation conversation) { // close the current notification before adding another if(currentNotification != null) { Logger.Debug("Current notification != null"); currentNotification.Close(); currentNotification = null; currentPeerID = 0; } lock(notifyLock) { Person peer = PersonManager.GetPerson(conversation.PeerUser); if(peer == null) return; peer.VideoNotifyCount++; String messageTitle = Catalog.GetString("Incoming Video Chat"); String messageBody = String.Format(Catalog.GetString("{0} is requesting a video chat"), peer.DisplayName); Message[] messages = conversation.GetReceivedMessages(); Notification notification; if(peer.Photo != null) { Gdk.Pixbuf sizedPhoto = peer.Photo.ScaleSimple(48, 48, Gdk.InterpType.Bilinear); notification = new Notification(messageTitle, messageBody, sizedPhoto); } else { Gdk.Pixbuf banterIcon = Application.GetIcon ("banter-44", 44); notification = new Notification(messageTitle, messageBody, banterIcon); } NotificationData data = new NotificationData(conversation, ChatType.Video, peer); pendingData[conversation.PeerUser.ID] = data; notification.AddAction("Accept", Catalog.GetString("Accept"), AcceptNotificationHandler); notification.AddAction("Decline", Catalog.GetString("Decline"), DeclineNotificationHandler); notification.Closed += ClosedNotificationHandler; notification.Timeout = 120000; currentNotification = notification; currentPeerID = conversation.PeerUser.ID; Banter.Application.ShowAppNotification(notification); Gnome.Sound.Play(Path.Combine(Banter.Defines.SoundDir, "notify.wav")); } }
///<summary> /// OnMediaChannelOpened /// Handles a media channel opened on a conversation ///</summary> private void OnMediaChannelOpened(Conversation conversation) { Logger.Debug("NotificationManager.OnMediaChannelOpened was called"); NotifyOfVideoRequest(conversation); }
/// <summary> /// CleanUpConversation /// Removes all event handlers and optionally destroys the conversation /// </summary> private void CleanUpConversation(Conversation conversation, bool destroyit) { conversation.MessageReceived -= OnTextAdditionalMessageReceived; conversation.MediaChannelOpened -= OnMediaChannelOpened; conversation.MediaChannelClosed -= OnMediaChannelClosed; conversation.TextChannelOpened -= OnTextChannelOpened; if(pendingData.ContainsKey(conversation.PeerUser.ID)) { pendingData.Remove(conversation.PeerUser.ID); } if(destroyit) { ConversationManager.Destroy(conversation); } }
/// <summary> /// NotifyOfTextMessage /// Notifies user of an incoming text message /// </summary> private void NotifyOfTextMessage(Conversation conversation) { // close the current notification before adding another if(currentNotification != null) { Logger.Debug("Current notification != null"); currentNotification.Close(); currentNotification = null; currentPeerID = 0; } lock(notifyLock) { Person peer = PersonManager.GetPerson(conversation.PeerUser); if(peer == null) return; peer.TextNotifyCount++; String messageTitle = String.Format(Catalog.GetString("Message from {0}"), peer.DisplayName); Message[] messages = conversation.GetReceivedMessages(); String messageBody; if(messages.Length > 0) { messageBody = messages[messages.Length - 1].Text; } else messageBody = ""; // Limit the size of the message that is sent if(messageBody.Length > 200) { messageBody = messageBody.Substring(0, 200); messageBody = messageBody + " ..."; } Notification notification; if(peer.Photo != null) { Gdk.Pixbuf sizedPhoto = peer.Photo.ScaleSimple(48, 48, Gdk.InterpType.Bilinear); notification = new Notification(messageTitle, messageBody, sizedPhoto); } else { Gdk.Pixbuf banterIcon = Application.GetIcon ("banter-44", 44); notification = new Notification(messageTitle, messageBody, banterIcon); } NotificationData data = new NotificationData(conversation, ChatType.Text, peer); pendingData[conversation.PeerUser.ID] = data; notification.AddAction("Accept", Catalog.GetString("Accept"), AcceptNotificationHandler); notification.AddAction("Decline", Catalog.GetString("Decline"), DeclineNotificationHandler); notification.Closed += ClosedNotificationHandler; currentNotification = notification; currentPeerID = conversation.PeerUser.ID; Banter.Application.ShowAppNotification(notification); Gnome.Sound.Play(Path.Combine(Banter.Defines.SoundDir, "notify.wav")); } }
///<summary> /// OnTextChannelOpened /// Called when a new text channel is opened ///</summary> private void OnTextChannelOpened(Conversation conversation) { // code goes here }
/// <summary> /// Method called from Account when a new channel is created /// </summary> internal static void ProcessNewChannel( Account account, ObjectPath channelPath, string channelType, HandleType handleType, uint handle, bool suppressHandler) { Logger.Debug ("ConversationManager::ProcessNewChannel - called"); bool createdNewConversation = false; Conversation conversation = null; ChatType chattype = ChatType.Text; ProviderUser peerUser = null; switch (channelType) { case "org.freedesktop.Telepathy.Channel.Type.Text": { IChannelText txtChannel = null; if (handle == 0) return; // Check if we have an existing conversation with the peer user try { peerUser = ProviderUserManager.GetProviderUser (handle); if (peerUser == null) return; txtChannel = Bus.Session.GetObject<IChannelText> ( account.BusName, channelPath); conversation = ConversationManager.GetExistingConversation (peerUser); if (conversation.ActiveTextChannel == false) { conversation.AddTextChannel (txtChannel); conversation.IndicateReceivedMessages (); } } catch (Exception ex) { Logger.Debug (ex.Message); } if (conversation == null) { try { Logger.Debug ("creating conversation object"); conversation = new Conversation (account, peerUser, channelPath, txtChannel); conversations.Add (conversation); createdNewConversation = true; Logger.Debug ("created new conversation object"); } catch (Exception es) { Logger.Debug (es.Message); Logger.Debug (es.StackTrace); } } break; } case "org.freedesktop.Telepathy.ChannelType.StreamedMedia": { // Check if we have an existing conversation with the peer user IChannelStreamedMedia mediaChannel = null; try { mediaChannel = Bus.Session.GetObject<IChannelStreamedMedia> ( account.BusName, channelPath); peerUser = ProviderUserManager.GetProviderUser (mediaChannel.Members[0]); if (peerUser == null) return; mediaChannel.AddMembers (mediaChannel.LocalPendingMembers, String.Empty); conversation = ConversationManager.GetExistingConversation (peerUser); conversation.AddMediaChannel (channelPath, mediaChannel); chattype = ChatType.Audio; StreamInfo[] streams = mediaChannel.ListStreams (); Logger.Debug ("#streams: {0}", streams.Length); foreach (StreamInfo si in streams) if (si.Type == StreamType.Video) { chattype = ChatType.Video; break; } // FIXME::Pump conversation to create the channel Logger.Debug ( "An existing conversation with {0} already exists", peerUser.Uri); } catch{} if (peerUser == null) return; if (conversation == null) { try { Logger.Debug ("creating conversation object"); conversation = new Conversation (account, peerUser, channelPath, mediaChannel); conversations.Add (conversation); chattype = ChatType.Audio; StreamInfo[] streams = mediaChannel.ListStreams (); Logger.Debug ("#streams: {0}", streams.Length); foreach (StreamInfo si in streams) if (si.Type == StreamType.Video) { chattype = ChatType.Video; break; } createdNewConversation = true; Logger.Debug ("created new conversation object"); } catch (Exception es) { Logger.Debug (es.Message); Logger.Debug (es.StackTrace); } } break; /* if(ichannel.Members.Length > 0) { foreach(uint ch in ichannel.Members) { Logger.Debug("Member in ichannel.Members {0}", ch); } } if(ichannel.Members.Length > 0) { peerHandle = ichannel.Members[0]; } else return; */ /* if (handle == 0) { if (ichannel.LocalPendingMembers.Length > 0) { Logger.Debug ("Incoming media conversation"); handle = ichannel.LocalPendingMembers[0]; } else if (ichannel.RemotePendingMembers.Length > 0) { handle = ichannel.RemotePendingMembers[0]; Logger.Debug ("Pulled the handle from ichannel.RemotePendingMembers"); return; } else if (ichannel.Members.Length > 0) { handle = ichannel.Members[0]; Logger.Debug ("Pulled the handle from ichannel.Members"); return; } else { Logger.Debug ("Could not resolve the remote handle"); return; } } else { Logger.Debug ("Handle was non-zero {0} - returning", handle); return; } if (handle == this.tlpConnection.SelfHandle) { Logger.Debug ("Handle was me - yay"); uint[] meHandles = {handle}; uint[] ids = {ichannel.Members[0]}; // Check if we have an existing conversation with the peer user ProviderUser puMe = null; ProviderUser puPeer = null; try { puMe = ProviderUserManager.GetProviderUser (handle); puPeer = ProviderUserManager.GetProviderUser(peerHandle); } catch{} if (puMe == null) return; if (puPeer == null) return; if (ConversationManager.Exist (puPeer) == true) { Logger.Debug ("An existing conversation with {0} already exists", puPeer.Uri); return; } ichannel.AddMembers(meHandles, String.Empty); Logger.Debug ("Peer: {0}", peer.Id); Logger.Debug ("Peer Name: {0}", peer.DisplayName); try { Logger.Debug ("creating conversation object"); conversation = ConversationManager.Create (this, peer, false); IChannelText txtChannel = Bus.Session.GetObject<IChannelText> (busName, channelPath); conversation.SetTextChannel (txtChannel); conversation.SetMediaChannel (ichannel, channelPath); Logger.Debug ("created new conversation object"); conversation.SetPreviewWindow (cw.PreviewWindowId); conversation.SetPeerWindow (cw.VideoWindowId); conversation.StartVideo (false); } catch (Exception es) { Logger.Debug (es.Message); Logger.Debug (es.StackTrace); } } break; */ } default: break; } // If successfully created a conversation and have registered consumers // of the callback event - fire the rocket if (conversation != null) { if (createdNewConversation == true && NewIncomingConversation != null) NewIncomingConversation (conversation, chattype); else if (chattype == ChatType.Audio) { conversation.IndicateAudioCall (); } else if (chattype == ChatType.Video) { conversation.IndicateVideoCall (); } } }
/// <summary> /// OnNewIncomingConversation /// Handles new conversations initiated by a peer /// </summary> internal static void HandleAcceptedConversation(Conversation conversation, ChatType chatType) { Logger.Debug("ChatWindowManager.NewAcceptedConversation was called"); if(conversation.PeerUser == null) { Logger.Error("NewIncomingConversation event had a conversation with null PeerUser"); return; } // If we have a ChatWindow for this conversation, don't do anything... the ChatWindow // will handle the change if(ChatWindowManager.ChatWindowExists(conversation.PeerUser.ID)) return; ChatWindowManager cwm = ChatWindowManager.Instance; Logger.Debug("**************Creating chat window"); ChatWindow cw = new ChatWindow(conversation, chatType); Logger.Debug("**************Creating chat window 2"); cwm.chatWindows[conversation.PeerUser.ID] = cw; cw.DeleteEvent += cwm.OnChatWindowDeleted; cw.ShowAll(); }
///<summary> /// OnTextMessageSent /// Deals with all TextMessages sent ///</summary> private void OnTextMessageSent(Conversation conversation, Message message) { Logger.Debug("OnMessageSent called: {0}", message.Text); AddMessage(message, false, conversation.CurrentMessageSameAsLast, null); }
public NotificationData(Conversation conversation, ChatType chatType, Person person) { this.conversation = conversation; this.chatType = chatType; this.person = person; }
public static void Destroy(Conversation conversation) { lock (lckr) { // Check if a conversation already exists foreach (Conversation c in ConversationManager.conversations) { if (c == conversation) { conversations.Remove (c); break; } } } conversation.RemoveTextChannel (); conversation.RemoveMediaChannel (); }
public static Conversation Create(ProviderUser provideruser) { Conversation conversation = null; lock (lckr) { // Check if a conversation already exists foreach (Conversation c in ConversationManager.conversations) { if (provideruser.Uri.CompareTo (c.PeerUser.Uri) == 0) { conversation = c; break; } } if (conversation == null) { Logger.Debug ("Conversation with {0} doesn't exist", provideruser.Uri); conversation = new Conversation (provideruser); conversations.Add (conversation); } } return conversation; }
private void OnTextChannelOpened(Conversation conversation) { Logger.Debug("NotificationManager.OnTextChannelOpened was called"); NotifyOfTextMessage(conversation); }
private void OnVideoStreamDown(Conversation conversation) { // close the current notification before adding another if(currentNotification != null) { Logger.Debug("Current notification != null"); currentNotification.Close(); currentNotification = null; currentPeerID = 0; } CleanUpConversation(conversation, true); }
internal static void AddConversation(Conversation conversation) { lock (lckr) { // Check if a conversation already exists foreach (Conversation c in ConversationManager.conversations) { if (conversation.PeerUser.Uri.CompareTo (c.PeerUser.Uri) == 0) { throw new ApplicationException ("Conversation with user already exists"); } } Logger.Debug ( "Adding an incoming conversation with {0} to the list", conversation.PeerUser.Uri); conversations.Add (conversation); } }