예제 #1
0
        public void SendChatMessage(TextMessage txtmsg)
        {
            txtmsg.Sent = true;
            ChatMessage msg = new ChatMessage(null);

            msg.From = txtmsg.From;
            msg.To   = txtmsg.To;
            msg.Type = "chat";
            msg.Body = txtmsg.Message;
            //suresh added for message receipt
            msg.InnerXML = "<request xmlns='urn:xmpp:receipts'/>";

            if (txtmsg.Thread == null || txtmsg.Thread.Length < 1)
            {
                //txtmsg = ExtractThread(txtmsg);
                ExtractThread(txtmsg);
            }

            msg.Thread = txtmsg.Thread;

            //msg.InnerXML = string.Format(@"<body>{0}</body>", txtmsg.Message);

            /// Find the roster guy for this message and add it to their conversation
            ///
            RosterItem item = XMPPClient.FindRosterItem(txtmsg.To);

            if (item != null)
            {
                item.AddSendTextMessage(txtmsg);
                //commented due to newconversation for conatct or delay msg send for not in the our roster item
                // Notify XMPPClient that a new conversation item has been added
                // XMPPClient.FireNewConversationItem(item, false, txtmsg,msg.ID);
            }
            XMPPClient.FireNewConversationItem(item, false, txtmsg, msg.ID);
            XMPPClient.SendXMPP(msg);
        }
예제 #2
0
 void DoAddMessage(TextMessage msg)
 {
     m_listMessages.Add(msg);
 }
예제 #3
0
        public override bool NewMessage(Message iq)
        {
            /// See if this is a standard text message
            ///
            if (iq is ChatMessage)
            {
                ChatMessage chatmsg = iq as ChatMessage;
                RosterItem  item    = XMPPClient.FindRosterItem(chatmsg.From);
                if (item != null)
                {
                    if (chatmsg.Body != null)
                    {
                        TextMessage txtmsg = new TextMessage();
                        txtmsg.From     = chatmsg.From;
                        txtmsg.To       = chatmsg.To;
                        txtmsg.Received = DateTime.Now;
                        if (chatmsg.Delivered.HasValue == true)
                        {
                            txtmsg.Received = chatmsg.Delivered.Value; /// May have been a server stored message
                        }
                        txtmsg.Message = chatmsg.Body;
                        txtmsg         = ExtractThread(txtmsg, true);
                        txtmsg.Sent    = false;
                        item.AddRecvTextMessage(txtmsg);
                        item.HasNewMessages = true;

                        // Notify XMPPClient that a new conversation item has been added
                        XMPPClient.FireNewConversationItem(item, true, txtmsg, iq.ID);
                    }
                    if (chatmsg.ConversationState != ConversationState.none)// A conversation message
                    {
                        item.Conversation.ConversationState = chatmsg.ConversationState;
                        XMPPClient.FireNewConversationState(item, item.Conversation.ConversationState);
                    }
                    else
                    {
                        XDocument xmldocument = XDocument.Parse(iq.InnerXML.ToString());
                        if (xmldocument.Root.LastAttribute != null)
                        {
                            string id = xmldocument.Root.LastAttribute.Value.ToString();
                            XMPPClient.FireDelegateReceiptHandler(chatmsg.From, id);
                        }
                    }
                }
                if (item == null)
                {
                    XDocument xmldocument = XDocument.Parse(iq.InnerXML.ToString());
                    if (xmldocument.Root.LastAttribute != null)
                    {
                        string id = xmldocument.Root.LastAttribute.Value.ToString();
                        XMPPClient.FireDelegateReceiptHandler(chatmsg.From, id);
                    }
                }

                return(true);
            }
            //suresh handle group chat
            else if (iq.Type == "groupchat")
            {
                XDocument xmldoc = XDocument.Parse(iq.InnerXML.ToString());
                string    body   = xmldoc.Descendants("body").Single().Value.ToString();
                XMPPClient.FireNewGroupConversation(iq, body);
            }

            else if (iq.Type == "normal")
            {
                XDocument xmldocument = XDocument.Parse(iq.MessageXML.ToString());
                XMPPClient.FireNewGroupConversation(iq, xmldocument.ToString());
            }
            //suresh handle receipt
            else if (iq.Type == "" || iq.Type == null)
            {
                XDocument xmldocument    = XDocument.Parse(iq.InnerXML.ToString());
                string    id             = xmldocument.Root.LastAttribute.Value.ToString();
                JID       messageFromJID = iq.From;

                XMPPClient.FireDelegateReceiptHandler(messageFromJID, id);
            }
            return(false);
        }
예제 #4
0
 public TextMessage ExtractThread(TextMessage txtmsg)
 {
     return(ExtractThread(txtmsg, false));
 }
예제 #5
0
 public void AddRecvTextMessage(TextMessage msg)
 {
     LastFullJIDToGetMessageFrom = msg.From;
     Conversation.AddMessage(msg);
 }
예제 #6
0
 public void AddSendTextMessage(TextMessage msg)
 {
     Conversation.AddMessage(msg);
 }