Exemplo n.º 1
0
 public override bool NewMessage(Message iq)
 {
     if (iq is PubSubEventMessage)
     {
         PubSubEventMessage psem = iq as PubSubEventMessage;
         if (psem.Event != null)
         {
             if ((psem.Event.Items != null) && (psem.Event.Items.Node == Node) && (psem.Event.Items.Items != null))
             {
                 foreach (PubSubItem psi in psem.Event.Items.Items)
                 {
                     T item = psi.GetObjectFromXML <T>();
                     if (item != null)
                     {
                         if (ItemIdToObject.ContainsKey(psi.Id) == false)
                         {
                             Items.Add(item);
                             ItemIdToObject.Add(psi.Id, item);
                         }
                         else  /// item with this id already exists, replace it with the new version
                         {
                             T itemtoremove = ItemIdToObject[psi.Id];
                             Items.Remove(itemtoremove);
                             Items.Add(item);
                             ItemIdToObject[psi.Id] = item;
                         }
                     }
                 }
             }
             if ((psem.Event.Retract != null) && (psem.Event.Retract.Node == Node) && (psem.Event.Retract.Items != null))
             {
                 foreach (PubSubItem item  in psem.Event.Retract.Items)
                 {
                     string strRetract = item.Id;
                     if (ItemIdToObject.ContainsKey(strRetract) == true)
                     {
                         T itemtoremove = ItemIdToObject[strRetract];
                         Items.Remove(itemtoremove);
                         ItemIdToObject.Remove(strRetract);
                     }
                 }
             }
         }
     }
     return(base.NewMessage(iq));
 }
Exemplo n.º 2
0
        public Message BuildMessage(XElement elem, string strXML)
        {
            /// Examine the type and see if we have classes for any of these
            XAttribute attrType = elem.Attribute("type");

            if (attrType != null)
            {
                if (attrType.Value == "chat")
                {
                    return(new ChatMessage(strXML));
                }
            }
            else if (((XElement)elem.FirstNode).Name == "{http://jabber.org/protocol/pubsub#event}event")
            {
                PubSubEventMessage query = Utility.ParseObjectFromXMLString(strXML, typeof(PubSubEventMessage)) as PubSubEventMessage;
                return(query);
                //return new PubSubEventMessage(strXML);
            }

            return(new Message(strXML));
        }
        public override bool NewMessage(Message iq)
        {
            /// Look for pubsub events
            ///
            if (iq is PubSubEventMessage)
            {
                PubSubEventMessage psem = iq as PubSubEventMessage;
                if (psem.Event != null)
                {
                    if ((psem.Event.Items != null) && (psem.Event.Items.Items != null) && (psem.Event.Items.Items.Length > 0))
                    {
                        PubSubItem psitem = psem.Event.Items.Items[0];
                        XElement   elem   = psitem.InnerItemXML as XElement;

                        if (psem.Event.Items.Node == "http://jabber.org/protocol/tune")
                        {
                            TuneItem item = psitem.GetObjectFromXML <TuneItem>();
                            if (item != null)
                            {
                                /// find the roster item, set the tune item
                                RosterItem rosteritem = XMPPClient.FindRosterItem(iq.From);
                                if (rosteritem != null)
                                {
                                    rosteritem.Tune = item;
                                }
                            }
                        }
                        else if (psem.Event.Items.Node == "http://jabber.org/protocol/geoloc")
                        {
                            geoloc item = psitem.GetObjectFromXML <geoloc>();
                            if (item != null)
                            {
                                /// find the roster item, set the tune item
                                RosterItem rosteritem = XMPPClient.FindRosterItem(iq.From);
                                if (rosteritem != null)
                                {
                                    rosteritem.GeoLoc = item;
                                }
                            }
                        }
                        else if (psem.Event.Items.Node == "http://jabber.org/protocol/mood")
                        {
                        }
                        else if (psem.Event.Items.Node == "urn:xmpp:avatar:metadata") /// item avatar metadata
                        {
                            /// We have update avatar info for this chap, we should then proceed to get the avatar data
                            ///
                            foreach (PubSubItem objItem in psem.Event.Items.Items)
                            {
                                avatarmetadata meta = psitem.GetObjectFromXML <avatarmetadata>();
                                if (meta != null)
                                {
                                    /// Request this node ? maybe we get it automatically?
                                    ///
                                }
                                /// Not sure why they would have more than 1 avatar item, so we'll ignore fom now
                                ///
                                break;
                            }
                        }
                        else if (psem.Event.Items.Node == "urn:xmpp:avatar:data") /// item avatar
                        {
                            /// We have update avatar info for this chap, we should then proceed to get the avatar data
                            ///
                            /// Works, but let's comment out for now to focus on more supported avatar methods
                            //foreach (PubSubItem objItem in psem.Items)
                            //{
                            //    avatardata data = Utility.ParseObjectFromXMLString(objItem.InnerItemXML, typeof(avatardata)) as avatardata;
                            //    if (data != null)
                            //    {
                            //        string strHash = XMPPClient.AvatarStorage.WriteAvatar(data.ImageData);
                            //        RosterItem item = XMPPClient.FindRosterItem(psem.From);
                            //        if (item != null)
                            //        {
                            //            item.AvatarImagePath = strHash;
                            //        }
                            //    }
                            //    /// Not sure why they would have more than 1 avatar item, so we'll ignore fom now
                            //    ///
                            //    break;
                            //}
                        }
                    }
                }
            }

            return(base.NewMessage(iq));
        }