Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
ChrisTutt #1
Member since Mar 2015 · 12 posts
Group memberships: Members
Show profile · Link to this post
Subject: Accept subscribe rrequest for "both"
I'm sure this is going to be a simple question, but I'm just getting started :)

I am learning XMPP with an account in Psi and one in the MiniClient sample application.  When I add a contact in Psi I see the below in the MiniClient:

  1. RECV: <presence to="christest3@voice2000.eu.bc.im" from="442082881248@voice2000.bc.im" type="subscribe" xmlns="jabber:client">
  2. <nick xmlns="http://jabber.org/protocol/nick">Chris</nick>
  3. </presence>
  4.  
  5. SEND: <presence type="subscribed" to="442082881248@voice2000.bc.im" xmlns="jabber:client" />
  6.  
  7. RECV: <iq id="rsttig2" to="christest3@voice2000.bc.im/MatriX" xmlns="jabber:client" type="set">
  8.   <query xmlns="jabber:iq:roster">
  9.     <item name="442082881248" jid="442082881248@voice2000.bc.im" subscription="from" />
  10.   </query>
  11. </iq>

This all looks fine but I want to the subscription type to be "both" not "from".   How would I set the subscription type when accepting a subscription request?

Thanks,
Chris
This post was edited on 2015-03-18, 09:36 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to do the same in the other direction. In XMPP subscriptions are not automatically "mutual". "Both" is what we call a mutual subscription.

If you want always mutual subscription then you check if you are already subscribed to the user which asks you to subscribe.
If not then send a subscription request with PresenceManager.Subscribe(jid).

There is no best practice for this. Many existing clients do it different. What I have often seen (I think Psi does it also this way) is 3 buttons in the "incoming subscription request dialog", "deny", "accept", "accept & add" or "accept & subscribe".

There are use cases where "User A" wants to be subscribed to "User B", but "User B" does not care about the presence of "User A". For bots this is a very common use case. When you are a bot that can talk to thousands or millions of people the incoming presence is also lots of traffic.

For normal IM use cases normally mutual subscription is what you want.
Avatar
ChrisTutt #3
Member since Mar 2015 · 12 posts
Group memberships: Members
Show profile · Link to this post
Thanks, I understand.  So if I want to use mutual subscriptions all the time then I would use

  1. using (PresenceManager pm = new PresenceManager(Client))
  2. {
  3.    pm.ApproveSubscriptionRequest(jId);
  4.    pm.Subscribe(jId);
  5. }
This post was edited on 2015-03-18, 09:58 by Alex.
Avatar
ChrisTutt #4
Member since Mar 2015 · 12 posts
Group memberships: Members
Show profile · Link to this post
Sorry, pressed the wrong key! :)

So I should just use the code from my last post, or should I check that I'm not already subscribed first?  If so how do I check through the PresenceManager?

Thanks,
Chris
Avatar
Alex #5
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ChrisTutt:
So I should just use the code from my last post, or should I check that I'm not already subscribed first?  If so how do I check through the PresenceManager?

when possible you should check if the subscribe is necessary or not. Just check if the user is on your contact list and subscription is "none" or "from".

If you send unnecessary subscription requests it does not break anything. The server will not route it to the user and automatically reply on behalf of the user with subscribed. Its only unnecessary traffic to the server and an event in your code.

Alex
Avatar
ChrisTutt #6
Member since Mar 2015 · 12 posts
Group memberships: Members
Show profile · Link to this post
Perfect, thanks!
Avatar
ChrisTutt #7
Member since Mar 2015 · 12 posts
Group memberships: Members
Show profile · Link to this post
Sorry, one more question.   If it doesn't break anything if I send unnecessary subscription requests then can I send them as part of the OnRosterItem handler, as below?  I want to make sure all subscriptions are mutual but another IM&P client may have been used before, so I can't be sure this is the case.

  1. private void OnRosterItem(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
  2. {
  3.  try
  4.  {
  5.     if ((e.RosterItem.Subscription==Matrix.Xmpp.Roster.Subscription.none) || (e.RosterItem.Subscription==Matrix.Xmpp.Roster.Subscription.from))
  6.     {
  7.       using (PresenceManager pm = new PresenceManager(Client))
  8.         pm.Subscribe(e.RosterItem.Jid);
  9.     }
  10. }
  11. catch...

Also, if a user denies a subscription request is there any way for me to tell if they are online or not?  If they deny my subscription request, then my client is restarted then using the above code it will try to subscribe again.  Will the user then be prompted again?

Sorry, almost done :)

Chris
This post was edited on 2015-03-18, 10:34 by Alex.
Avatar
Alex #8
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ChrisTutt:
Sorry, one more question.   If it doesn't break anything if I send unnecessary subscription requests then can I send them as part of the OnRosterItem handler, as below?  I want to make sure all subscriptions are mutual but another IM&P client may have been used before, so I can't be sure this is the case.
yes you can do that if you always want mutual subscription, no problem at all.


Quote by ChrisTutt:
Also, if a user denies a subscription request is there any way for me to tell if they are online or not?  If they deny my subscription request, then my client is restarted then using the above code it will try to subscribe again.  Will the user then be prompted again?
no there is no way, that is what the subscription is for, tell you the online state. Id the request gets denied you get no presences for this user. Of course you can try to subscribe again and the user will get prompted again.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS