Ejemplo n.º 1
0
        ///<summary>
        ///	Constructor
        /// Creates a ChatWindow and a conversation according to the type requested
        ///</summary>
        public ChatWindow(Person person, ProviderUser providerUser, ChatType type) :
            base(WindowType.Toplevel)
        {
            Logger.Debug("ChatWindow is being created with the ChatType: {0}", type.ToString());
            this.chatType = type;
            conv          = ConversationManager.Create(providerUser);

            /*
             * switch(chatType) {
             *      case ChatType.Text:
             *              conv.AddTextChannel();
             *              break;
             *      case ChatType.Audio:
             *              conv.AddAudioChannel();
             *              //conv.AddTextChannel();
             *              break;
             *      case ChatType.Video:
             *              conv.AddAudioVideoChannels();
             *              //conv.AddTextChannel();
             *              break;
             * }
             */

            peerPerson       = person;
            peerProviderUser = providerUser;

            InitWindow();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a person from a tapioca contact
        /// </summary>

        /*internal Person(Evolution.Contact edsContact)
         * {
         *      this.edsContact = edsContact;
         *      Init();
         * }
         */

        /// <summary>
        /// Constructs a person with a displayName
        /// </summary>
        public Person(ProviderUser user)
        {
            providerUsers = new List <ProviderUser> ();

            textNotifyCount  = 0;
            audioNotifyCount = 0;
            videoNotifyCount = 0;

            if (user != null)
            {
                providerUsers.Add(user);
                if (user.Presence != null)
                {
                    presence = user.Presence;
                }
                user.PresenceUpdated    += ProviderUserPresenceUpdated;
                user.AvatarTokenUpdated += this.ProviderUserAvatarTokenUpdated;
                user.AvatarReceived     += this.ProviderUserAvatarReceived;
                if (user.Alias.Length > 0)
                {
                    displayName = user.Alias;
                }
                else
                {
                    displayName = user.Uri;
                }
            }

            if (presence == null)
            {
                presence = new Presence(PresenceType.Offline);
            }
        }
Ejemplo n.º 3
0
        internal Conversation(ProviderUser providerUser)
        {
            this.Init(
                AccountManagement.GetAccountByName(providerUser.AccountName),
                providerUser);

            this.initiated = true;
        }
Ejemplo n.º 4
0
        public void ProviderUserAdded(ProviderUser user)
        {
            Person person = PersonManager.GetPerson(user);

            if (person == null)
            {
                person = new Person(user);
                //person.JabberId = user.Uri;
                PersonManager.AddPerson(person);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the ProviderUser for the specified key
        /// The key is basically "Uri:Provider"
        /// </summary>
        public static ProviderUser GetProviderUser(string key)
        {
            ProviderUser user = null;

            lock (locker) {
                if (ProviderUserManager.Instance.users.ContainsKey(key))
                {
                    user = ProviderUserManager.Instance.users[key];
                }
            }
            return(user);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles notification from a ProviderUser that the Avatar has been received
        /// AvatarTokenUpdated handler
        /// AvatarReceived
        /// </summary>
        private void ProviderUserAvatarReceived(ProviderUser user, string token, string mimeType, byte[] avatarData)
        {
            // FIXME: This needs to determine if the AvatarUpdated needs to be called depending
            // on the avatar stored in EDS etc.
            avatar = new Gdk.Pixbuf(avatarData);

            // Call the event on the GUI thread
            if (AvatarUpdated != null)
            {
                Gtk.Application.Invoke(delegate {
                    AvatarUpdated(this);
                });
            }
        }
Ejemplo n.º 7
0
 private void Init(Account account, ProviderUser providerUser)
 {
     this.account                   = account;
     this.tlpConnection             = this.account.TlpConnection;
     this.peerUser                  = providerUser;
     this.callType                  = CallType.None;
     this.messages                  = new List <Message> ();
     this.last                      = 999;
     this.videoStreams              = new Dictionary <uint, uint> ();
     this.audioStreams              = new Dictionary <uint, uint> ();
     this.peerUser.PresenceUpdated += OnPeerPresenceUpdated;
     this.lastPeerPresence          = this.peerUser.Presence;
     this.inRemoveMedia             = false;  //hack
 }
Ejemplo n.º 8
0
        public static bool Exist(ProviderUser peer)
        {
            bool exists = false;
            foreach (Conversation conversation in ConversationManager.conversations)
            {
                if (conversation.PeerUser.Uri.CompareTo (peer.Uri) == 0)
                {
                    exists = true;
                    break;
                }
            }

            return exists;
        }
Ejemplo n.º 9
0
        ///<summary>
        ///	Constructor
        /// Creates a ChatWindow based on an existing conversation.  This mainly used on
        /// incoming conversations.
        ///</summary>
        public ChatWindow(Conversation conversation, ChatType type) :
            base(WindowType.Toplevel)
        {
            Logger.Debug("ChatWindow is being created with the ChatType: {0}", type.ToString());

            this.chatType = type;
            conv          = conversation;

            // no need to Add any channels, they will be set up already

            peerProviderUser = conv.PeerUser;
            peerPerson       = PersonManager.GetPerson(peerProviderUser);

            InitWindow();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the ProviderUser based on the instance ID
        /// </summary>
        public static ProviderUser GetProviderUser(uint id)
        {
            ProviderUser user = null;

            lock (locker) {
                foreach (ProviderUser cUser in ProviderUserManager.Instance.users.Values)
                {
                    if (cUser.ID == id)
                    {
                        user = cUser;
                        break;
                    }
                }
            }
            return(user);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Signal called when presence changes for the peer user.
        /// </summary>
        private void OnPeerPresenceUpdated(ProviderUser user)
        {
            string msg;

            Banter.SystemMessage systemMessage = null;

            // no handlers?  exit
            if (MessageReceived == null)
            {
                return;
            }

            string displayName = (user.Alias != null) ? user.Alias.Split(' ')[0] : user.Uri;

            if (user.Presence.Type == Banter.PresenceType.Offline)
            {
                msg           = String.Format("{0} has gone {1}", displayName, user.Presence.Name);
                systemMessage = new Banter.SystemMessage(msg);
            }
            else
            {
                if (user.Presence.Message != null &&
                    user.Presence.Message != String.Empty &&
                    user.Presence.Message != lastPeerPresence.Message)
                {
                    msg = String.Format(
                        "{0} is {1} \"{2}\"",
                        displayName,
                        user.Presence.Name,
                        user.Presence.Message);
                    systemMessage = new Banter.SystemMessage(msg);
                }
                else
                {
                    msg           = String.Format("{0} is {1}", displayName, user.Presence.Name);
                    systemMessage = new Banter.SystemMessage(msg);
                }
            }

            lastPeerPresence = user.Presence;

            // Indicate the message to registered handlers
            if (systemMessage != null)
            {
                MessageReceived(this, systemMessage);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Constructor for a conversation initiated
        /// from a text channel via a remote user
        /// </summary>
        internal Conversation(
            Account account,
            ProviderUser providerUser,
            ObjectPath objectpath,
            IChannelText channel)
        {
            this.Init(account, providerUser);

            this.txtChannelObjectPath = objectpath;
            this.initiated            = false;

            txtChannel           = channel;
            txtChannel.Received += OnReceiveMessageHandler;
            txtChannel.Closed   += OnTextChannelClosed;

            AddPendingMessages();
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds the ProviderUser for the given key
 /// The key is basically "Uri:Provider"
 /// </summary>
 public static void AddProviderUser(string key, ProviderUser user)
 {
     lock (locker) {
         if (!ProviderUserManager.Instance.users.ContainsKey(key))
         {
             ProviderUserManager.Instance.users[key] = user;
             if (ProviderUserAdded != null)
             {
                 ProviderUserAdded(user);
             }
         }
         else
         {
             throw new ApplicationException("key already exists");
         }
     }
 }
Ejemplo n.º 14
0
        public static Conversation GetExistingConversation(ProviderUser peer)
        {
            Conversation existing = null;
            foreach (Conversation conversation in ConversationManager.conversations)
            {
                if (conversation.PeerUser.Uri.CompareTo (peer.Uri) == 0)
                {
                    existing = conversation;
                    break;
                }
            }

            if (existing == null)
                throw new ApplicationException ("Conversation does not exist");

            return existing;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Method to remove a provider user from the list
        /// using the contact ID
        /// </summary>
        public static void RemoveProviderUser(uint id, string protocol)
        {
            ProviderUser user = null;

            lock (locker) {
                foreach (ProviderUser cUser in ProviderUserManager.Instance.users.Values)
                {
                    if (cUser.ID == id)
                    {
                        user = cUser;
                        break;
                    }
                }

                if (user != null)
                {
                    string key = CreateKey(user.Uri, protocol);
                    if (ProviderUserManager.Instance.users.ContainsKey(key) == true)
                    {
                        ProviderUserManager.Instance.users.Remove(key);
                        if (ProviderUserRemoved != null)
                        {
                            ProviderUserRemoved(user.Uri);
                        }
                    }
                }
            }

            /*
             * lock (locker) {
             *      string key = CreateKey (uri, protocol);
             *
             *      if (ProviderUserManager.Instance.users.ContainsKey (key) == true)
             *      {
             *              ProviderUserManager.Instance.users.Remove (key);
             *              if(ProviderUserRemoved != null) {
             *                      ProviderUserRemoved(uri);
             *              }
             *      }
             * }
             */
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Constructor for a conversation initiated
        /// from a media channel via a remote user
        /// </summary>
        internal Conversation(
            Account account,
            ProviderUser providerUser,
            ObjectPath objectpath,
            IChannelStreamedMedia channel)
        {
            this.Init(account, providerUser);
            this.initiated = false;

            // Figure out the streamed media type
            mediaChannelObjectPath               = objectpath;
            mediaChannel                         = channel;
            mediaChannel.Closed                 += OnMediaChannelClosed;
            mediaChannel.StreamAdded            += OnStreamAdded;
            mediaChannel.StreamDirectionChanged += OnStreamDirectionChanged;
            mediaChannel.StreamError            += OnStreamError;
            mediaChannel.StreamRemoved          += OnStreamRemoved;
            mediaChannel.StreamStateChanged     += OnStreamStateChanged;
            mediaChannel.MembersChanged         += OnMembersChanged;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a new ProviderUser and adds them in one atomic operation
        /// </summary>
        public static ProviderUser CreateProviderUser(string uri, string protocol)
        {
            lock (locker) {
                string key = CreateKey(uri, protocol);

                if (!ProviderUserManager.Instance.users.ContainsKey(key))
                {
                    ProviderUser user = new ProviderUser();
                    user.Uri      = uri;
                    user.Protocol = protocol;
                    ProviderUserManager.Instance.users[key] = user;
                    if (ProviderUserAdded != null)
                    {
                        ProviderUserAdded(user);
                    }
                    return(user);
                }
                else
                {
                    throw new ApplicationException("key already exists");
                }
            }
        }
Ejemplo n.º 18
0
        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;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Handles notification from a ProviderUser that the Avatar Token has been updated
 /// AvatarTokenUpdated handler
 /// AvatarReceived
 /// </summary>
 private void ProviderUserAvatarTokenUpdated(ProviderUser user, string newToken)
 {
     // FIXME: we need to test to see if we really need to request the data
     // FIXME: Save off the newToken for later
     user.RequestAvatarData();
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Gets the Person object for a given Jabber ID
 /// </summary>
 public static Person GetPerson(ProviderUser user)
 {
     return(GetPerson(user.Uri));
 }
Ejemplo n.º 21
0
 private void ProviderUserPresenceUpdated(ProviderUser user)
 {
     Logger.Debug("Person:ProviderUserPresenceUpdated for ProviderUser: {0}", user.Alias);
     UpdatePresence();
 }
Ejemplo n.º 22
0
        /// <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 ();
                }
            }
        }
Ejemplo n.º 23
0
 public TextMessage(string message, ProviderUser sender) : base(message)
 {
     this.Sender = sender;
 }