1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Handle outgoing 'unavailabe' presences in Roster

Fixes SMACK-733
This commit is contained in:
Florian Schmaus 2017-01-03 10:48:11 +01:00
parent 0b19c1b8ef
commit 1bce31fcd9

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2003-2007 Jive Software, 2016 Florian Schmaus. * Copyright 2003-2007 Jive Software, 2016-2017 Florian Schmaus.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -315,6 +315,19 @@ public final class Roster extends Manager {
} }
}); });
connection.addPacketSendingListener(new StanzaListener() {
@Override
public void processPacket(Stanza stanzav) throws NotConnectedException, InterruptedException {
// Once we send an unavailable presence, the server is allowed to suppress sending presence status
// information to us as optimization (RFC 6121 § 4.4.2). Thus XMPP clients which are unavailable, should
// consider the presence information of their contacts as not up-to-date. We make the user obvious of
// this situation by setting the presences of all contacts to unavailable (while keeping the roster
// state).
setOfflinePresences();
}
}, PresenceTypeFilter.UNAVAILABLE);
// If the connection is already established, call reload // If the connection is already established, call reload
if (connection.isAuthenticated()) { if (connection.isAuthenticated()) {
try { try {
@ -324,6 +337,7 @@ public final class Roster extends Manager {
LOGGER.log(Level.SEVERE, "Could not reload Roster", e); LOGGER.log(Level.SEVERE, "Could not reload Roster", e);
} }
} }
} }
/** /**
@ -1159,11 +1173,9 @@ public final class Roster extends Manager {
/** /**
* Changes the presence of available contacts offline by simulating an unavailable * Changes the presence of available contacts offline by simulating an unavailable
* presence sent from the server. After a disconnection, every Presence is set * presence sent from the server.
* to offline.
* @throws NotConnectedException
*/ */
private void setOfflinePresencesAndResetLoaded() { private void setOfflinePresences() {
Presence packetUnavailable; Presence packetUnavailable;
outerloop: for (Jid user : presenceMap.keySet()) { outerloop: for (Jid user : presenceMap.keySet()) {
Map<Resourcepart, Presence> resources = presenceMap.get(user); Map<Resourcepart, Presence> resources = presenceMap.get(user);
@ -1190,6 +1202,15 @@ public final class Roster extends Manager {
} }
} }
} }
}
/**
* Changes the presence of available contacts offline by simulating an unavailable
* presence sent from the server. After a disconnection, every Presence is set
* to offline.
*/
private void setOfflinePresencesAndResetLoaded() {
setOfflinePresences();
rosterState = RosterState.uninitialized; rosterState = RosterState.uninitialized;
} }