powered by Jive Software

Roster.SUBSCRIPTION_MANUAL and Offline User Issue

There seems to be a bit of an issue with the Roster defaulting to SUBSCRIPTION_ACCEPT_ALL if you are writing a program that must manually handle subscriptions. Let me explain:

  • If you are offline and another user sends you a subscription request, as soon as you login using Smack that subscription is accepted…even if you set the subscription mode to manual right after login. This appears to be a result of the Roster defaulting to SUBSCRIPTION_ACCEPT_ALL.

Here is the code I’'m using to isolate & test this:

public class TestLogin

{

public TestLogin()

{

try

{

XMPPConnection con = new XMPPConnection(“myserver”);

con.login(“username”, “password”);

Roster roster = con.getRoster();

roster.setSubscriptionMode(Roster.SUBSCRIPTION_MANUAL);

con.close();

}

catch(Exception ex)

{

ex.printStackTrace();

}

}

public static void main(String[] args)

{

TestLogin testLogin = new TestLogin();

System.out.println(“Done test”);

}

}

Has anyone else experienced this or is there something else I should be doing? My current solution is that I’'ll just rebuild smack.jar with a Roster that defaults to SUBSCRIPTION_MANUAL.

Thanks,

Brodie

Brodie,

If you are using the latest Smack version (v1.3.0) you can set the default subscription mode to use before you establish the connection to the server.

Use the static method Roster.setDefaultSubscriptionMode before you send the #login message to the connection.

Example:

Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL);
   XMPPConnection con = new XMPPConnection("myserver");
   con.login("username", "password");

Regards,

– Gato