/// <summary> /// Asks the provisioning server if a JID is a friend or not. /// </summary> /// <param name="JID">JID</param> /// <param name="Callback">Method to call when response is received.</param> /// <param name="State">State object to pass to callback method.</param> public void IsFriend(string JID, IsFriendCallback Callback, object State) { if ((!string.IsNullOrEmpty(this.ownerJid) && string.Compare(JID, this.ownerJid, true) == 0) || string.Compare(JID, this.provisioningServerAddress, true) == 0) { if (Callback != null) { try { IqResultEventArgs e0 = new IqResultEventArgs(null, string.Empty, this.client.FullJID, this.provisioningServerAddress, true, State); IsFriendResponseEventArgs e = new IsFriendResponseEventArgs(e0, State, JID, true); Callback(this.client, e); } catch (Exception ex) { Log.Critical(ex); } } return; } this.CachedIqGet("<isFriend xmlns='" + NamespaceProvisioningDevice + "' jid='" + XML.Encode(JID) + "'/>", this.IsFriendCallback, new object[] { Callback, State }); }
private void IsFriendCallback(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; IsFriendCallback Callback = (IsFriendCallback)P[0]; object State = P[1]; string JID; bool Result; XmlElement E = e.FirstElement; if (e.Ok && E != null && E.LocalName == "isFriendResponse" && E.NamespaceURI == NamespaceProvisioningDevice) { JID = XML.Attribute(E, "jid"); Result = XML.Attribute(E, "result", false); } else { Result = false; JID = null; } IsFriendResponseEventArgs e2 = new IsFriendResponseEventArgs(e, State, JID, Result); try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } }
private void CheckIfFriendCallback(object Sender, IsFriendResponseEventArgs e2) { PresenceEventArgs e = (PresenceEventArgs)e2.State; if (e2.Ok && e2.Friend) { Log.Informational("Presence subscription accepted.", e.FromBareJID, this.provisioningServerAddress); e.Accept(); RosterItem Item = this.client.GetRosterItem(e.FromBareJID); if (Item == null || Item.State == SubscriptionState.None || Item.State == SubscriptionState.From) { this.client.RequestPresenceSubscription(e.FromBareJID); } } else { Log.Notice("Presence subscription declined.", e.FromBareJID, this.provisioningServerAddress); e.Decline(); } }