/// <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); } } 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 { System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ThreadedUpdateAvatarImageHash), new RosterItemImageHash() { RosterItem = item, ImageHash = pres.VCardUpdate.PhotoHash }); //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); }
public void SetPresence(PresenceMessage pres) { /// Hack for now to show who can do audio /// bool bCanDoAudio = false; bool IsKnownGoogleClient = false; if (pres.Capabilities != null) { if (pres.Capabilities.Extensions != null) { if (pres.Capabilities.Extensions.IndexOf("voice-v1") >= 0) { bCanDoAudio = true; } } if (pres.Capabilities.Node != null) { if (pres.Capabilities.Node == "http://www.android.com/gtalk/client/caps2") { IsKnownGoogleClient = true; } else if (pres.Capabilities.Node == "http://talkgadget.google.com/client/caps") { IsKnownGoogleClient = true; } } } if ((pres.From.Resource != null) && (pres.From.Resource.Length > 0)) { RosterItemPresenceInstance instance = FindInstance(pres.From); if (instance != null) { instance.Presence = pres.PresenceStatus; if (pres.PresenceStatus.PresenceType == PresenceType.unavailable) { //lock (m_lockClientInstances) //{ m_listClientInstances.Remove(instance); //} FirePropertyChanged("ClientInstances"); FirePropertyChanged("Name"); } } else { instance = new RosterItemPresenceInstance(pres.From); instance.Presence = pres.PresenceStatus; instance.CanClientDoAudio = bCanDoAudio; instance.IsKnownGoogleClient = IsKnownGoogleClient; //lock (m_lockClientInstances) //{ m_listClientInstances.Add(instance); //} FirePropertyChanged("ClientInstances"); FirePropertyChanged("Name"); } } /// Get the precense of the most available and latest client instance /// PresenceStatus beststatus = pres.PresenceStatus; if (pres.PresenceStatus.PresenceType != PresenceType.available) { RosterItemPresenceInstance[] instances = null; lock (m_lockClientInstances) { foreach (RosterItemPresenceInstance instance in m_listClientInstances) { if (instance.Presence.PresenceType == PresenceType.available) { beststatus = instance.Presence; break; } } } } Presence = beststatus; //System.Diagnostics.Debug.WriteLine(item.ToString()); XMPPClient.FireListChanged(1); }