[JDEV] Subscribe / Unsubscribe users
David Waite
dwaite at jabber.com
Fri Sep 22 11:30:21 CDT 2000
No problem - while the Roster lists the current subscription status of
your users, you cannot subscribe or unsubscribe using it (both the
subscription type and the current asking state are read-only).
To add or remove users, user presence:
<psuedocode>
PresenceBuilder presBuilder=new PresenceBuilder();
presBuilder.setToAddr(jidOfOtherUser);
presBuilder.setType("subscribe");
try
{
Packet p=presBuilder.build()
}
...appropriate error catching...
connection.send(p);
This builds a <presence type="subscribe" to="whoever at wherever"/>
The response back should be a 'subscribed' message. If the user is
unable to answer or defers answering, the 'ask' field in the roster
marks that the subscription request is still outstanding and waiting.
see more details at http://docs.jabber.org/jpg/
-David Waite
Leon Kwan wrote:
>
> Hello all genius,
>
> I met great problem in subscribing and unsubscribing users
> when using jabberbeans API.
>
> Below is the code of subscribe and unsubscribe.
>
> In subscribe method, I found that I can put the the
> subscribed name to the xml of the user profile but I
> cannot set the waiting state type to "subscribe".
> In the packet listener, I can see the packet sent
> contains this attribute of "waiting state type".
> So what is the proper procedure of adding a user?
>
> Moreover, exception occurs when request the roster list if
> one of the roster element is "ask=subscribe". How should
> I handle it?
>
> Unsubscribe is worse. Although I found that the packet
> sent contains attribute of "waiting state type" and also
> the "subscription type", nothing in the xml of the
> user profile is changed.
>
> public boolean subscribe(String username)
> {
> RosterItemBuilder rib=new RosterItemBuilder();
> rib.setJID(createJID(username));
> rib.setSubscriptionType("both");
> rib.setWaitingStateType("subscribe");
> rib.setFriendlyName(username);
>
> InfoQueryBuilder iqbuild = new InfoQueryBuilder();
>
> RosterItem ri;
> try
> {
> ri = (RosterItem) rib.build();
> RosterExtensionBuilder reb = new RosterExtensionBuilder();
> reb.addRosterItem(ri);
> reb.setIQRoster(true);
> iqbuild.reset();
> iqbuild.setType("set");
> iqbuild.addExtension(reb.build());
> //build and send presence
> connection.send(iqbuild.build());
> }
> catch (InstantiationException e)
> {
> e.printStackTrace(System.err);
> return false;
> }
> return true;
> }
>
>
>
> public boolean remove(String username)
> {
> RosterItemBuilder rib=new RosterItemBuilder();
> rib.setJID(createJID(username));
> rib.setSubscriptionType("both");
> rib.setWaitingStateType("unsubscribe");
> rib.setFriendlyName(username);
>
> InfoQueryBuilder iqbuild = new InfoQueryBuilder();
>
> RosterItem ri;
> try
> {
> ri = (RosterItem) rib.build();
> RosterExtensionBuilder reb = new RosterExtensionBuilder();
> reb.addRosterItem(ri);
> reb.setIQRoster(true);
> iqbuild.reset();
> iqbuild.setType("set");
> iqbuild.addExtension(reb.build());
> //build and send presence
> connection.send(iqbuild.build());
> }
> catch (InstantiationException e)
> {
> e.printStackTrace(System.err);
> return false;
> }
> return true;
> }
>
>
> -Leon Kwan
>
>
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev
>
>
>
More information about the JDev
mailing list