Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
MikeManske #1
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: Retrieve List of Subscriptions (not for owner)
Hi all,

I'm developing a client for Windows Phone 7. I'm using pubsub and therefore I wanted to know, how to retrieve a list of subscriptions for a given node and a given user?

I only want to get the subscriptions of the current user and not of all users for a given node. So the following code doesn't help me:

  1. pubsubManager.RequestSubscriptionsList(pubsubJid, "myNode");

Can I build my own Iq request, if the API does not contain this query? It has to look like this at the end:
  1. <iq id="zHY7q-7" to="pubsub.domain.de" type="get">
  2.  <pubsub xmlns="http://jabber.org/protocol/pubsub">
  3.     <subscriptions node="myNode"/>
  4.  </pubsub>
  5. </iq>

Thanks a lot for helping me!

Have a nice day,
Mike
This post was edited on 2013-02-03, 17:29 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hi Mike,

I have attached a new build. There are 2 new members in the PubSubManager:

  • RequestAllSubscriptions
  • RequestSubscriptions

RequestSubscriptions is what you are looking for. Please let me know if it works. Then I'll upload the new build to the latest binaries.

Regards,
Alex
This post was edited on 2013-02-03, 22:00 by Alex.
Edit reason: removed attachment
Avatar
MikeManske #3
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

wow, that was quick! Thanks a lot for your support. It works perfectly!

Now another question: is there any API for unsubscribing from a node based on the subscriptionID like:

pubsubManager.Unsubscribe(pubsubJid, "myNode", "my-sub-id-for-node", jid, xmppClient_Handler);

Or do I have to use the way proposed here: http://forum.ag-software.de/thread/950-Null-exception-in-I…

Thanks in advance!
Mike
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Currently there is no API where you can pass a subId. I will add some more overloads which allow you to pass a subId.
I will notify you here in this thread when I have the update.

Alex
Avatar
MikeManske #5
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
Okay, thanks.

For those who want to have a full example of how unsubscriptions work, while multiple subscriptions have been made, here is an example based on the work of Beaker (http://forum.ag-software.de/thread/950-Null-exception-in-I…):

  1. pubsubManager.RequestSubscriptions(pubsubJid, "myNode", xmppClient_UnsubscribeFromMyNode);
  2.  
  3. void xmppClient_UnsubscribeFromMyNode(object sender, IqEventArgs e)
  4. {
  5.  
  6.     Matrix.Xmpp.PubSub.PubSub pubsubElement = (Matrix.Xmpp.PubSub.PubSub)e.Iq.Query;
  7.     IEnumerable<Subscription> subscriptions = pubsubElement.Subscriptions.GetSubscriptions();
  8.  
  9.     foreach (Subscription element in subscriptions)
  10.     {
  11.         Iq iq2 = new Iq();
  12.         iq2.GenerateId();
  13.         iq2.To = new Jid("pubsub.domain.de");
  14.         iq2.From = jid;
  15.         iq2.Type = IqType.set;
  16.         string subid = element.Attribute("subid").Value;
  17.        
  18.         Unsubscribe unsub = new Unsubscribe();
  19.         unsub.Node = "myNode";
  20.         unsub.Jid = jid;
  21.         unsub.SetAttribute("subid", subid);
  22.  
  23.         PubSub pubsub = new PubSub();
  24.         pubsub.Unsubscribe = unsub;
  25.  
  26.         iq2.Query = pubsub;
  27.  
  28.         IqFilter myFilter = new IqFilter(xmppClient);
  29.         myFilter.SendIq(iq2, null, null);
  30.     }
  31. }


Cheers,
Mike
This post was edited on 2013-02-03, 22:02 by Alex.
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I have attached a new build again. There are overloads for Unsubscribe now which accept a subid.
Alex
The author has attached one file to this post:
Matrix_WP7.zip 322.4 kBytes
You have no permission to open this file.
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
here is some prettier code which builds the ubsubscribe stanza  :-)

  1. var pubSubIq = new PubSubIq
  2.         {
  3.             To = "pubsub.domain.de",
  4.             Type = IqType.set,
  5.             PubSub =
  6.                 {
  7.                     Unsubscribe = new Unsubscribe
  8.                         {
  9.                             Node = "node_name",
  10.                             Jid = "user@domain.de",
  11.                             SubId = "some_sub_id"
  12.                         }
  13.                 }
  14.         };
Avatar
MikeManske #8
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
Nice Alex, thanks a lot! Your code looks very clean and clear.

However, I figured out a problem while unsubscribing from a node. Lets assume I created 10 subscriptions on a node "notifications". Then I try to unsubscribe them all. 9 of 10 subscriptions are unsubscribed but the last one doesnt get unsubscribed. Here is the Stream:

SEND:
<iq id="MX_4" type="get" to="pubsub.md2m.de" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <subscriptions node="notifications" />
  </pubsub>
</iq>

RCV:
<iq type="result" id="MX_4" from="pubsub.md2m.de" to="wp7@md2m.de/Matrix-Windows-Phone" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <subscriptions node="notifications">
      <subscription jid="wp7@md2m.de/Matrix-Windows-Phone" subscription="subscribed" subid="T43p2nI3Ot491xIv6b1clrO0q3eSmrEL505U9MkG" />
    </subscriptions>
  </pubsub>
</iq>

SEND:
<iq id="MX_5" to="pubsub.md2m.de" type="set" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <unsubscribe node="notifications" jid="wp7@md2m.de/Matrix-Windows-Phone" subid="T43p2nI3Ot491xIv6b1clrO0q3eSmrEL505U9MkG" />
  </pubsub>
</iq>

RCV:
<iq type="error" id="MX_5" from="pubsub.md2m.de" to="wp7@md2m.de/Matrix-Windows-Phone" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <unsubscribe node="notifications" jid="wp7@md2m.de/Matrix-Windows-Phone" subid="T43p2nI3Ot491xIv6b1clrO0q3eSmrEL505U9MkG" />
  </pubsub>
  <error code="400" type="wait">
    <unexpected-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
    <not-subscribed xmlns="http://jabber.org/protocol/pubsub#errors" />
  </error>
</iq>

The subscription has been done this way:

SEND:
<iq id="MX_5" to="pubsub.md2m.de" type="set" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <subscribe node="notifications" jid="wp7@md2m.de/Matrix-Windows-Phone" />
  </pubsub>
</iq>

RCV:
<iq type="result" id="MX_5" from="pubsub.md2m.de" to="wp7@md2m.de/Matrix-Windows-Phone" xmlns="jabber:client">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <subscription node="notifications" jid="wp7@md2m.de/Matrix-Windows-Phone" subid="T43p2nI3Ot491xIv6b1clrO0q3eSmrEL505U9MkG" subscription="subscribed">
      <subscribe-options />
    </subscription>
  </pubsub>
</iq>

Whats wrong here? It only happens if there is just ONE last subscription for the node for the given JID.

Cheers,
Mike
This post was edited on 2013-02-04, 10:09 by MikeManske.
Avatar
Alex #9
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by MikeManske:
However, I figured out a problem while unsubscribing from a node. Lets assume I created 10 subscriptions on a node "notifications". Then I try to unsubscribe them all. 9 of 10 subscriptions are unsubscribed but the last one doesnt get unsubscribed. Here is the Stream:

Whats wrong here?

hm, no idea, I see that you subscribed a full jid. Normally you subscribe to bare jid (without resource). Maybe this confuses your server.

Alex
Avatar
Alex #10
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
its also possible that you server expects a unsubscribe request without a subid for the last subscription.
Avatar
MikeManske #11
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
Yes, both is possible. I'm using openfire.
For the moment I couldn't figure out any pattern.

Thanks for your effort Alex, helped me a lot!

Mike
Avatar
Alex #12
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
its also possible that you database is messed up because of sending some wrong XML during tests. Does the same happen when you create a new node and subscribe bare Jids only?
Avatar
MikeManske #13
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
I tried your described approach: I deleted the node, created a new one, subscribed with a bare Jid. The same behavior. I also tried to unsubscribe with and without subid (while having only one subscription).

Very strange.

Thanks for your help Alex.
Avatar
Alex #14
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your logs would help, but for now I see nothing wrong it MatriX. Did you check some other server software like ejabberd, Prosody or Tigase to check if its not a server bug?
Did you try to contact the Openfire developers?

Alex
Avatar
MikeManske #15
Member since Feb 2013 · 7 posts
Group memberships: Members
Show profile · Link to this post
I dont think its a MatriX bug. I think its a problem related to the server.

For the moment I can live with it, because its a students project and I'm running out of time. If I finally have more time, I'll check this in detail.

Cheers
Stefan
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: