Creating a plugin to handle creation of rosters over http requests. Where to next?

Hi all

I’ve created a plugin that will handle the creation of roster entries via a http request, so 3rd party applications can handle users roster (namely web pages).

So far, I’ve manage to get it as fat as adding in a roster entry fine and broadcasting the roster item. How ever, if both users are currently logged in, the user being added to the other users roster, will show as off line until they log off and back on again.

Here’s the code for the function:

public RosterItem addRosterEntry(String username, JID jidUser, String nickname, List groups, boolean push, boolean persistent)           throws UserAlreadyExistsException, SharedGroupException, UserNotFoundException
     {
          // Get the user details and roster details for the user
          Roster roster = this.getRoster(username);           // Add a entry into the roster for this user
          RosterItem rosterItem = roster.createRosterItem(jidUser, nickname, groups, push, persistent);
          rosterItem.setSubStatus(RosterItem.SUB_BOTH);
          roster.broadcast(rosterItem, false);
          
          return rosterItem;
     }

I’m not sure where to go to from here. My thoughts were to check to see if the user that is having the entry added to their roster is online and if so, it’ll check to see if the being added and if so, then it will do some sort of notify (assuming a presence packet) to the user with the roster.

I looked at the User, UserManager and PresenceManagerImp classes, but most of the functions there are dealing with if the user is available, is that the same as being online?

Any help in what direction to take next?

Thanks

G

Okay, I’ve managed to get it working, but I’m not 100% happy with the way it is working. I’ve added the following code to the function

if (this.presenceManager.isAvailable(this.userManager.getUser(username))) {
               // Now check to see if the user being added is online
               if (this.presenceManager.isAvailable(this.userManager.getUser(UserNameManager.getUserName(jid)))) {
                    // Probe the user being added
                    this.presenceManager.probePresence(this.server.createJID(username, null), jid);
                    this.presenceManager.probePresence(jid, this.server.createJID(username, null));
               }
          }

My problem is the following.

  • User A is adding User B and then after that, User B will add User A.
  • In the first run of the function, neither has the other in their rosters.
  • User A adds User B to his roster, it then steps into the first if statement because User A is online.
  • Then, even though User B is online, it doesn’t and throws a UserNotFoundException.
  • Then in the 2nd run of the funtion, User B will be adding User A.
  • It steps into the first if because User B is online, but then unlike the first run, it steps into the 2nd if statment correctly and does the presence probes.

I don’t understand why this is happening, specially when the

this.presenceManager.isAvailable(this.userManager.getUser(username))

and

this.presenceManager.isAvailable(this.userManager.getUser(UserNameManager.getUserName(jid)))

have seemingly nothing to do with roster entries at all.

Can anyone explain this?

Okay, solved the problem. Seems UserNameManager.getUserName(jid) returns the user’s name, not the username.

I eventually managed to figure out that jid.getNode() returns the username. Used that and it’s all working perfectly now.