mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-24 21:37:58 +01:00
Modified in order to hold any valid JID format. SMACK-152
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2394 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
ef0d5c8fb8
commit
c4e971c350
1 changed files with 31 additions and 15 deletions
|
@ -386,16 +386,14 @@ public class Roster {
|
||||||
* Returns the roster entry associated with the given XMPP address or
|
* Returns the roster entry associated with the given XMPP address or
|
||||||
* <tt>null</tt> if the user is not an entry in the roster.
|
* <tt>null</tt> if the user is not an entry in the roster.
|
||||||
*
|
*
|
||||||
* @param user the XMPP address of the user (eg "jsmith@example.com").
|
* @param user the XMPP address of the user (eg "jsmith@example.com"). The address could be
|
||||||
|
* in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").
|
||||||
* @return the roster entry or <tt>null</tt> if it does not exist.
|
* @return the roster entry or <tt>null</tt> if it does not exist.
|
||||||
*/
|
*/
|
||||||
public RosterEntry getEntry(String user) {
|
public RosterEntry getEntry(String user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Roster entries never include a resource so remove the resource
|
|
||||||
// if it's a part of the XMPP address.
|
|
||||||
user = StringUtils.parseBareAddress(user);
|
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
||||||
RosterEntry entry = (RosterEntry)i.next();
|
RosterEntry entry = (RosterEntry)i.next();
|
||||||
|
@ -410,16 +408,14 @@ public class Roster {
|
||||||
/**
|
/**
|
||||||
* Returns true if the specified XMPP address is an entry in the roster.
|
* Returns true if the specified XMPP address is an entry in the roster.
|
||||||
*
|
*
|
||||||
* @param user the XMPP address of the user (eg "jsmith@example.com").
|
* @param user the XMPP address of the user (eg "jsmith@example.com"). The address could be
|
||||||
|
* in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").
|
||||||
* @return true if the XMPP address is an entry in the roster.
|
* @return true if the XMPP address is an entry in the roster.
|
||||||
*/
|
*/
|
||||||
public boolean contains(String user) {
|
public boolean contains(String user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Roster entries never include a resource so remove the resource
|
|
||||||
// if it's a part of the XMPP address.
|
|
||||||
user = StringUtils.parseBareAddress(user);
|
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
for (Iterator i=entries.iterator(); i.hasNext(); ) {
|
||||||
RosterEntry entry = (RosterEntry)i.next();
|
RosterEntry entry = (RosterEntry)i.next();
|
||||||
|
@ -475,12 +471,13 @@ public class Roster {
|
||||||
* If the user has several presences (one for each resource) then answer the presence
|
* If the user has several presences (one for each resource) then answer the presence
|
||||||
* with the highest priority.
|
* with the highest priority.
|
||||||
*
|
*
|
||||||
* @param user a fully qualified xmpp ID, e.g. jdoe@example.com
|
* @param user a fully qualified xmpp ID. The address could be in any valid format (e.g.
|
||||||
|
* "domain/resource", "user@domain" or "user@domain/resource").
|
||||||
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
||||||
* or if no presence information is available..
|
* or if no presence information is available..
|
||||||
*/
|
*/
|
||||||
public Presence getPresence(String user) {
|
public Presence getPresence(String user) {
|
||||||
String key = StringUtils.parseName(user) + "@" + StringUtils.parseServer(user);
|
String key = getPresenceMapKey(user);
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map) presenceMap.get(key);
|
||||||
if (userPresences == null) {
|
if (userPresences == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -512,13 +509,12 @@ public class Roster {
|
||||||
* is unavailable (offline) or if no presence information is available, such as
|
* is unavailable (offline) or if no presence information is available, such as
|
||||||
* when you are not subscribed to the user's presence updates.
|
* when you are not subscribed to the user's presence updates.
|
||||||
*
|
*
|
||||||
* @param userResource a fully qualified xmpp ID including a resource, e.g. jdoe@example.com/Home
|
* @param userResource a fully qualified xmpp ID including a resource.
|
||||||
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
||||||
* or if no presence information is available.
|
* or if no presence information is available.
|
||||||
*/
|
*/
|
||||||
public Presence getPresenceResource(String userResource) {
|
public Presence getPresenceResource(String userResource) {
|
||||||
String key =
|
String key = getPresenceMapKey(userResource);
|
||||||
StringUtils.parseName(userResource) + "@" + StringUtils.parseServer(userResource);
|
|
||||||
String resource = StringUtils.parseResource(userResource);
|
String resource = StringUtils.parseResource(userResource);
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map) presenceMap.get(key);
|
||||||
if (userPresences == null) {
|
if (userPresences == null) {
|
||||||
|
@ -539,7 +535,7 @@ public class Roster {
|
||||||
* unavailable or if no presence information is available.
|
* unavailable or if no presence information is available.
|
||||||
*/
|
*/
|
||||||
public Iterator getPresences(String user) {
|
public Iterator getPresences(String user) {
|
||||||
String key = StringUtils.parseName(user) + "@" + StringUtils.parseServer(user);
|
String key = getPresenceMapKey(user);
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map) presenceMap.get(key);
|
||||||
if (userPresences == null) {
|
if (userPresences == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -549,6 +545,25 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the key to use in the presenceMap for a fully qualified xmpp ID. The roster
|
||||||
|
* can contain any valid address format such us "domain/resource", "user@domain" or
|
||||||
|
* "user@domain/resource". If the roster contains an entry associated with the fully qualified
|
||||||
|
* xmpp ID then use the fully qualified xmpp ID as the key in presenceMap, otherwise use the
|
||||||
|
* bare address. Note: When the key in presenceMap is a fully qualified xmpp ID, the
|
||||||
|
* userPresences is useless since it will always contain one entry for the user.
|
||||||
|
*
|
||||||
|
* @param user the fully qualified xmpp ID, e.g. jdoe@example.com/Work.
|
||||||
|
* @return the key to use in the presenceMap for the fully qualified xmpp ID.
|
||||||
|
*/
|
||||||
|
private String getPresenceMapKey(String user) {
|
||||||
|
String key = user;
|
||||||
|
if (!contains(user)) {
|
||||||
|
key = StringUtils.parseBareAddress(user);
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires roster changed event to roster listeners.
|
* Fires roster changed event to roster listeners.
|
||||||
*/
|
*/
|
||||||
|
@ -584,7 +599,8 @@ public class Roster {
|
||||||
public void processPacket(Packet packet) {
|
public void processPacket(Packet packet) {
|
||||||
Presence presence = (Presence)packet;
|
Presence presence = (Presence)packet;
|
||||||
String from = presence.getFrom();
|
String from = presence.getFrom();
|
||||||
String key = StringUtils.parseBareAddress(from);
|
String key = getPresenceMapKey(from);
|
||||||
|
|
||||||
// If an "available" packet, add it to the presence map. Each presence map will hold
|
// If an "available" packet, add it to the presence map. Each presence map will hold
|
||||||
// for a particular user a map with the presence packets saved for each resource.
|
// for a particular user a map with the presence packets saved for each resource.
|
||||||
if (presence.getType() == Presence.Type.AVAILABLE) {
|
if (presence.getType() == Presence.Type.AVAILABLE) {
|
||||||
|
|
Loading…
Reference in a new issue