Exemplo n.º 1
0
        /// <presence id="AWAQt-31" from="[email protected]/calculon" to="[email protected]/phone"><status>Away</status><priority>0</priority><show>away</show></presence>

        public override bool NewPresence(PresenceMessage pres)
        {
            if ((pres.Type == "") || (pres.Type == "unavailable"))
            {
                /// Means avialbe
                ///
                RosterItem item = XMPPClient.FindRosterItem(pres.From);
                if (item != null)
                {
                    item.SetPresence(pres);
                }
            }
            //<presence from="[email protected]/calculon" to="*****@*****.**" type="subscribe"/>
            else if (pres.Type == "subscribe")
            {
                Answer answer = XMPPClient.ShouldSubscribeUser(pres);

                if (answer == Answer.Yes)
                {
                    AcceptUserPresence(pres, "", "");
                }
                else if (answer == Answer.No) /// reject if the user has responded
                {
                    DeclineUserPresence(pres);
                }
            }
            else if (pres.Type == "subscribed")
            {
            }
            else
            {
                RosterItem item = XMPPClient.FindRosterItem(pres.From);
                if (item != null)
                {
                    item.SetPresence(pres);
                    //item.Presence = pres.PresenceStatus;

                    /// Commented out because no one seems to support this method
                    //if (pres.AvatarHash != null)
                    //{
                    //    if (pres.AvatarHash.Hash != null)
                    //    {
                    //        /// May have a new avatar, check against our current file system
                    //        ///
                    //        if (XMPPClient.AvatarStorage.AvatarExist(pres.AvatarHash.Hash) == false)
                    //           DownloadAvatarJabberIQMethod(pres.From);
                    //    }
                    //}

                    if (pres.VCardUpdate != null)
                    {
                        if (pres.VCardUpdate.PhotoHash != null)
                        {
                            //byte [] bURL = Convert.FromBase64String(pres.VCardUpdate.PhotoHash);
                            //string strURL = System.Text.UTF8Encoding.UTF8.GetString(bURL, 0, bURL.Length);
                            //item.AvatarImagePath = strURL;



                            /// XEP-153 - vcard-based avatars... sha1 hash of the current avatar
                            if ((XMPPClient.AvatarStorage.AvatarExist(pres.VCardUpdate.PhotoHash) == false) && (XMPPClient.AutomaticallyDownloadAvatars == true))
                            {
                                RequestVCARD(pres.From);
                            }
                            else
                            {
                                item.AvatarImagePath = pres.VCardUpdate.PhotoHash;
                            }


                            //RequestVCARD(pres.From);


                            /// or XEP-0008 IQ based avatars
                            ///


                            /// or XEP- jaber fldlkjsl
                            //string strRelativeImage = string.Format("Avatars/{0}", pres.VCardUpdate.PhotoHash);
                            ///// See if this file exists, if it doesn't, download the file
                            /////
                            //if (System.IO.File.Exists(strRelativeImage) == true)
                            //    item.AvatarImagePath = strRelativeImage;
                            //else
                            //    //XMPPClient.PersonalEventingLogic.DownloadDataNode(jidfrom, "urn:xmpp:avatar:data", strItem);
                            //    XMPPClient.DownloadAvatar(pres.From, pres.VCardUpdate.PhotoHash);
                        }
                    }


                    System.Diagnostics.Debug.WriteLine(item.ToString());
                    XMPPClient.FireListChanged(1);
                }
            }

            return(true);
        }