Fix offline presence info, including test case (SMACK-219).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@8275 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2007-05-10 22:48:24 +00:00 committed by matt
parent bdc61a2db2
commit 466b7e2d08
2 changed files with 16 additions and 9 deletions

View File

@ -696,10 +696,9 @@ public class Roster {
// Otherwise, this is a normal offline presence.
else if (presenceMap.get(key) != null) {
Map<String, Presence> userPresences = presenceMap.get(key);
userPresences.remove(StringUtils.parseResource(from));
if (userPresences.isEmpty()) {
presenceMap.remove(key);
}
// Store the offline presence, as it may include extra information
// such as the user being on vacation.
userPresences.put(StringUtils.parseResource(from), presence);
}
// If the user is in the roster, fire an event.
for (RosterEntry entry : entries) {

View File

@ -229,6 +229,8 @@ public class PresenceTest extends SmackTestCase {
/**
* User1 logs in, then sets offline presence information (presence with status text). User2
* logs in and checks to see if offline presence is returned.
*
* @throws Exception if an exception occurs.
*/
public void testOfflineStatusPresence() throws Exception {
// Add a new roster entry for other user.
@ -242,14 +244,20 @@ public class PresenceTest extends SmackTestCase {
Thread.sleep(100);
}
// Sign out of conn0.
getConnection(0).disconnect();
// Sign out of conn1 with status
Presence offlinePresence = new Presence(Presence.Type.unavailable);
offlinePresence.setStatus("Offline test");
getConnection(1).disconnect(offlinePresence);
// Wait 500 ms
Thread.sleep(500);
Presence presence = getConnection(0).getRoster().getPresence(getBareJID(1));
assertTrue("Offline presence status not received.",
"Offline test".equals(presence.getStatus()));
// Sign out of conn0.
getConnection(0).disconnect();
// See if conneciton 0 can get offline status.
XMPPConnection con0 = getConnection(0);
con0.connect();
@ -257,8 +265,8 @@ public class PresenceTest extends SmackTestCase {
// Wait 500 ms
Thread.sleep(500);
Presence presence = con0.getRoster().getPresence(getBareJID(1));
assertTrue("Offline presence status not received.",
presence = con0.getRoster().getPresence(getBareJID(1));
assertTrue("Offline presence status not received after logout.",
"Offline test".equals(presence.getStatus()));
}