From 466b7e2d0818281ce63c352ea23b5af2a0fbf827 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Thu, 10 May 2007 22:48:24 +0000 Subject: [PATCH] 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 --- source/org/jivesoftware/smack/Roster.java | 7 +++---- test/org/jivesoftware/smack/PresenceTest.java | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 27597a566..20bc4cccf 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -696,10 +696,9 @@ public class Roster { // Otherwise, this is a normal offline presence. else if (presenceMap.get(key) != null) { Map 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) { diff --git a/test/org/jivesoftware/smack/PresenceTest.java b/test/org/jivesoftware/smack/PresenceTest.java index ec33f0d3d..7575a1dec 100644 --- a/test/org/jivesoftware/smack/PresenceTest.java +++ b/test/org/jivesoftware/smack/PresenceTest.java @@ -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())); }