Hi there,
I have been trying to crack this problem for some time now. I am trying to add a roster entry to a user. Here is a sample test code for me to achieve this mean. I used SUBSCRIPTION_ACCEPT_ALL
- // My own XMPP connection factory+
- roster = connectionFactory.getConnection().getRoster("user1@localhost.com");+ + Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);+ + roster.setSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL)-+ + roster.createEntry("user2@localhost.com", “myNick”, null);*
I notice that user1 can only see user2 but user2 cannot see user1. In my packetlistener (I know its supposed to be automatic, but one of my futile attemps!):
if(packet instanceof Presence)
{
Presence presence = (Presence) packet; logger.info("Packet instanceof Presence received! Type - " + presence.getType().toString());
logger.info(presence.toXML()); if (presence.getType() == Presence.Type.SUBSCRIBE)
{
Presence response = new Presence(Presence.Type.SUBSCRIBED);
response.setTo(presence.getFrom());
connectionFactory.getConnection().sendPacket(response);
logger.info("Packet response sent! -> " + response.toXML());
}
if (presence.getType() == Presence.Type.UNSUBSCRIBE)
{ Presence response = new Presence(Presence.Type.UNSUBSCRIBED);
response.setTo(presence.getFrom());
connectionFactory.getConnection().sendPacket(response);
logger.info("Packet response sent! -> " + response.toXML());
} }
In the jiveroster table
I see that user1 has a ‘sub’ value of 1 while user2 has a ‘sub’ value of 2. Can anybody please point me to the right direction. I am still struggling to find out what the problem is. I have read all the archived messages and tried every suggestion but in vain (or maybe I still dun understand what it means). I am currently using OpenFire 3.3.2 and Smack 2.2.1
Another question: What will happen if user1 try to add user2 while user2 is still offline? Will the user2 receive the Presence packet once he is online? I did not get that behaviour if its so.