Ejemplo n.º 1
0
        /// <summary>
        /// Add the given chat message to the current log file
        /// </summary>
        /// <param name="chatMessage"></param>
        public bool AddMessageToLog(ChatMessage chatMessage)
        {
            if (!isInitialized)
                return false;

            bool rtn = true;
            try
            {
                using (FileStream stream = new FileStream(fileName, FileMode.Create))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        chatMessages.Add(chatMessage);
                        String logText = JsonConvert.SerializeObject(chatMessages, new ChatMessageToJsonConverter());
                        writer.Write(logText);
                        writer.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                //WAT DO
                rtn = false;
            }

            return rtn;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send a message to our target
        /// </summary>
        public void SendMessage()
        {
            //No need to lock this.  Doing so would cause a dead-lock
            ChatMessage newMsg = new ChatMessage() { To = target.ToString(), From = account.AccountJid, Message = sendText, MessageType = agsXMPP.protocol.client.MessageType.chat };
            account.SendMessage(this, newMsg);

            lock (messagesLock)
            {
                messages.Add(newMsg);
            }

            //Reset the text
            SendText = String.Empty;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called when our account receives a message for us.  Locks our messages in case we try to send one at the
 /// same time.
 /// </summary>
 /// <param name="message">The messages received from target</param>
 public void OnMessage(ChatMessage message)
 {
     lock (messagesLock)
     {
         //do it on the UI thread.
         Execute.OnUIThread
         (
             new System.Action
             (
                 () =>
                 {
                     messages.Add(message);
                     NotifyOfPropertyChange(() => Messages);
                 }
             )
         );
     }
 }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 private void NotifyChatChatMessage(ChatSessionViewModel chatSessionViewModel, ChatMessage chatMessage)
 {
     if (OnChatMessage != null)
         OnChatMessage(chatSessionViewModel, chatMessage);
 }
Ejemplo n.º 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);
        }