The title kind of says it all, but I’m writing an Openfire plugin and need a way to determine which resource Openfire will send a message to if the destination user is logged in on multiple resources (I’m assuming that the resource is always the client software name such as “pidgin” “spark” “sparkweb” etc).
So, for example, user1 is logged into a Gaim client, Sparkweb client and a Spark client all at the same time. User2 sends a message to “user1”. How does Openfire determine which of the 3 clients logged in receives the message?
Here’s what I’ve gotten so far: Sparkweb is a lower ‘priority’ than Spark/Gaim/Pidgin/, so SparkWeb won’t receive a message if the user is logged in with any of the other clients. Spark/Gaim/Pidgin are all the same priority (1), so an incoming message (from user2) goes to which ever client was ‘active’ last (meaning most recently logged in or most recently sent a message).
Because my plugin needs to do different tasks depending on which client the user is receiving the message on, how would I go about determining which was the last client to be active for a given user?
This is the default behavior of Openfire:
In the case that the user is connected from many resources the logic will be the following:
- Select resources with highest priority
- Select resources with highest show value (chat, available, away, xa, dnd)
- Select resource with most recent activity
These rules are processed top-down.
By setting Openfire system property route.all-resources to “true” you can change this. In that case all resources with highest priority will get the message.
Both things are defined in RFC 3921, page 85, section 188.8.131.52
how would I go about determining which was the last client to be active for a given user?
Check out PresenceManager#getLastActivity(User)
So to determine which resource will receive a message, I’ll have to iterate through each presence that user has, and determine (via that 3 step decision flow) which is the ‘dominate’ (highest priority, highest show, most recent activity, in that order) resource at the time? There’s no way to query the server for that information directly? No “presenceManager.getDominateResource(destinationUser)” function?
But thanks a lot for the help, I think I can make it work now.
No “presenceManager.getDominateResource(destinationUser)” function?
I think this is done in private method org.jivesoftware.openfire.spi.RoutingTableImpl#routeToBareJID.
You could at least copy&paste code from there