[JDEV] Subscribe / Unsubscribe users
Leon Kwan
leon at icon.com.hk
Fri Sep 22 04:52:19 CDT 2000
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
More information about the JDev
mailing list