Updating a Roster on the Server

Hi everyone,

I am confused on how to update a roster on the server. I can get the roster from the server easily, but I do not understand how to put a changed roster back on the server (say because I removed a person).

Any ideas?

Thanks,

Angelo

Hi Angelo,

Actually you don’‘t directly modify the Roster and then send it to the server, instead you have to send message to the server specifying what do you want to do. There are some methods in the Roster that makes sending these messages easier in such a way that you don’'t have to worry about the messages.

This are a few examples:

Add user "angelo@server.name" to a Roster you have to send a subscription request to this user:

conn.getRoster().createEntry(“angelo@host”, “Angelo”, new String[0]);

If "angelo@server.name" accepts the subscription request then he will be in the Roster, by default Smack accepts all the subscription but you can change this.

Remove user "angelo@server.name" to a Roster:

conn.getRoster().removeEntry(conn.getRoster().getEntry(“angelo@host”));

You can print the roster entries to check if it is working

for (RosterEntry entry : conn.getRoster().getEntries()) {

System.out.println(entry);

}

Thanks, that’'s exactly what I was looking for!

-Angelo