Inheritance: Caliburn.Micro.ReactiveUI.ReactiveScreen
Exemple #1
0
        private void OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            lock (chatSessionsMutext)
            {
                //Do we have a chat session with the sender of this message?
                ChatSessionViewModel chatSession = chatSessions.SingleOrDefault(x => x.Target.Bare == msg.From.Bare);
                if (chatSession == null)
                {
                    JIDViewModel friend = friends.SingleOrDefault(x => x.Bare == msg.From.Bare);
                    if (friend == null)
                    {
                        friend = new JIDViewModel(msg.From, this);
                        friends.Add(friend);
                        //No way to get groups here. :\
                    }
                    //Nope.  Create a new one.
                    chatSession = new ChatSessionViewModel(this, friend);
                    chatSessions.Add(chatSession);
                    NotifyChatSessionStarted(chatSession);
                }

                if (!String.IsNullOrEmpty(msg.Body))
                {
                    ChatMessage newMsg = new ChatMessage()
                        {
                            To = msg.To,
                            From = msg.From,
                            Date = GetTimestamp(msg),
                            Message = msg.Body,
                            MessageType = msg.Type
                        };
                    //Add the message.
                    chatSession.OnMessage(newMsg);

                    NotifyChatChatMessage(chatSession, newMsg);
                }
                else
                    chatSession.OnChatState(msg.Chatstate);
            }
        }
Exemple #2
0
 private void NotifyChatSessionStarted(ChatSessionViewModel chatSessionViewModel)
 {
     if (ChatSessionStarted != null)
         ChatSessionStarted(chatSessionViewModel);
 }
Exemple #3
0
 private void NotifyChatSessionInitiatedByUser(ChatSessionViewModel chatSessionViewModel)
 {
     if (ChatSessionInitiatedByUser != null)
         ChatSessionInitiatedByUser(chatSessionViewModel);
 }
Exemple #4
0
 private void NotifyChatChatMessage(ChatSessionViewModel chatSessionViewModel, ChatMessage chatMessage)
 {
     if (OnChatMessage != null)
         OnChatMessage(chatSessionViewModel, chatMessage);
 }
Exemple #5
0
        /// <summary>
        /// Open up a new chat session with the target
        /// </summary>
        /// <param name="target"></param>
        public void StartNewChatSession(JIDViewModel target)
        {
            if (connectionState != XmppConnectionState.SessionStarted)
                return;

            lock (chatSessionsMutext)
            {
                //Do we already have a chat session open with this target?
                ChatSessionViewModel chatSession = chatSessions.SingleOrDefault(x => x.Target == target);
                if (chatSession == null)
                {
                    //Create and add.
                    chatSession = new ChatSessionViewModel(this, target);
                    chatSessions.Add(chatSession);
                }

                //Always notify
                NotifyChatSessionInitiatedByUser(chatSession);
            }
        }
Exemple #6
0
        /// <summary>
        /// Send a message to a particular Jid
        /// </summary>
        /// <param name="target"></param>
        /// <param name="message"></param>
        public void SendMessage(ChatSessionViewModel chatSessionVM, ChatMessage chatMessage)
        {
            //Only allow messages when the session is active
            if (connectionState != XmppConnectionState.SessionStarted)
                return;

            agsXMPP.protocol.client.Message sendMessage = new agsXMPP.protocol.client.Message(chatSessionVM.Target, chatMessage.MessageType, chatMessage.Message);
            clientConnection.Send(sendMessage);
            NotifyChatChatMessage(chatSessionVM, chatMessage);
        }