powered by Jive Software

Problem adding a user to a roster


I’'m trying to add a user to a roster. With the sub field in the jiveroster table having the value 3. I have tried:

private Roster r;

private RosterItem item;

private JID jid_full;

jid_full = new JID(jid);

r = rManager.getRoster(roster);

item = r.createRosterItem(jid_full, jid_full.getNode(), null, true, true); //OK


The user gets added to the roster, but the value of sub is 0 in the db even though I have called setSubStatus on the rosteritem. The got thing about this code is that the changes is immediately reflected in the Jabber client.

I have also tried:

private Roster r;

private RosterItem item;

private JID jid_full;

private RosterItemProvider rosterItemProvider;

jid_full = new JID(jid);

item = new RosterItem(jid_full, RosterItem.SUB_BOTH, RosterItem.ASK_NONE, RosterItem.RECV_NONE, jid_full.getNode(), null);

rosterItemProvider = RosterItemProvider.getInstance();

rosterItemProvider.createItem(roster, item);

This also adds the user to the roster and also sets the sub field to 3. The only problem with this code is that the changes aren’'t reflected in the Jabber client.

So I’'m trying to get the best of both worlds, I would like to set the sub field to 3 (RosterItem.SUB_BOTH) and have the changes reflected immediately in the connected Jabber clients. Any help or pointers are very welcome. Thanks.

Kind regards,


Hi Nick,

the subscription plugin uses code like this to simulate the subscription:

// Simulate that the target user has accepted the presence subscription request
Presence presence = new Presence();
private PresenceRouter router;

You could also create two presence packets and send one to every user. I guess that this is still a little bit tricky as you may want to send the right presence state (online, away, offline, …).

Maybe it makes more sense to debug your first code approach and find out why item.setSubStatus(RosterItem.SUB_BOTH); fails.