예제 #1
0
        // <summary>
        /// Invoked when a Message stanza is being received.
        /// </summary>
        /// <param name="message">The message stanza which is being received.</param>
        /// <returns>true to intercept the stanza or false to pass the stanza
        /// on to the next handler.</returns>
        public bool Input(Message message)
        {
            if ((message.Type == MessageType.Chat) ||
                (message.Type == MessageType.Headline))
            {
                XmlElement received;

                received = message.Data["received", "urn:xmpp:receipts"];
                if (received != null)
                {
                    string messageId = received.GetAttribute("id");

                    // Set Receipt Type according entity and event
                    ReceiptType receiptType;
                    var         entity = received.GetAttribute("entity");
                    var         evt    = received.GetAttribute("event");
                    if (entity == "server")
                    {
                        receiptType = ReceiptType.ServerReceived;
                    }
                    else if (evt == "received")
                    {
                        receiptType = ReceiptType.ClientReceived;
                    }
                    else
                    {
                        receiptType = ReceiptType.ClientRead;
                    }


                    DateTime dateTime  = DateTime.MinValue;
                    var      timestamp = message.Data["timestamp"];
                    if (timestamp != null)
                    {
                        String value = timestamp.GetAttribute("value");
                        if (!String.IsNullOrEmpty(value))
                        {
                            DateTime.TryParse(value, out dateTime);
                        }
                    }

                    if (message.Type == MessageType.Chat)
                    {
                        MessageDeliveryReceived.Raise(this, new MessageDeliveryReceivedEventArgs(messageId, receiptType, dateTime));
                    }
                    else
                    {
                        AlertMessageDeliveryReceived.Raise(this, new MessageDeliveryReceivedEventArgs(messageId, receiptType, dateTime));
                    }
                    return(true);
                }

                // Do we receive a "mark as read" for all messages ?
                received = message.Data["mark_as_read", "jabber:iq:notification"];
                if (received != null)
                {
                    string id = received.GetAttribute("id");
                    //if(id == "all-received")
                    {
                        String jid = received.GetAttribute("with");
                        MessagesAllRead.Raise(this, new JidEventArgs(jid));
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
 internal void OnMessagesAllRead(object sender, IdEventArgs args)
 {
     MessagesAllRead.Raise(sender, args);
 }