mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +01:00
1. Added reconnection support. SMACK-172
2. Set available contacts to offline when connection is closed. SMACK-171 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@5366 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
96e134e21a
commit
96e4201f61
1 changed files with 51 additions and 6 deletions
|
@ -46,7 +46,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
* @see XMPPConnection#getRoster()
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class Roster {
|
||||
public class Roster implements ConnectionListener {
|
||||
|
||||
/**
|
||||
* The default subscription processing mode to use when a Roster is created. By default
|
||||
|
@ -63,6 +63,7 @@ public class Roster {
|
|||
// The roster is marked as initialized when at least a single roster packet
|
||||
// has been recieved and processed.
|
||||
boolean rosterInitialized = false;
|
||||
private PresencePacketListener presencePacket;
|
||||
|
||||
private SubscriptionMode subscriptionMode = getDefaultSubscriptionMode();
|
||||
|
||||
|
@ -107,7 +108,10 @@ public class Roster {
|
|||
connection.addPacketListener(new RosterPacketListener(), rosterFilter);
|
||||
// Listen for any presence packets.
|
||||
PacketFilter presenceFilter = new PacketTypeFilter(Presence.class);
|
||||
connection.addPacketListener(new PresencePacketListener(), presenceFilter);
|
||||
presencePacket = new PresencePacketListener();
|
||||
connection.addPacketListener(presencePacket, presenceFilter);
|
||||
// Listen for connection events
|
||||
connection.addConnectionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,6 +308,25 @@ public class Roster {
|
|||
return Collections.unmodifiableCollection(allEntries);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 setOfflinePresences() {
|
||||
Presence packetUnavailable;
|
||||
for (String user : new ArrayList<String>(presenceMap.keySet())) {
|
||||
Map<String, Presence> resources = presenceMap.get(user);
|
||||
if (resources != null) {
|
||||
for (String resource : new ArrayList<String>(resources.keySet())) {
|
||||
packetUnavailable = new Presence(Presence.Type.unavailable);
|
||||
packetUnavailable.setFrom(user + "/" + resource);
|
||||
presencePacket.processPacket(packetUnavailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a count of the unfiled entries in the roster. An unfiled entry is
|
||||
* an entry that doesn't belong to any groups.
|
||||
|
@ -791,4 +814,26 @@ public class Roster {
|
|||
fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
|
||||
}
|
||||
}
|
||||
|
||||
public void connectionClosed() {
|
||||
// Changes the presence available contacts to unavailable
|
||||
this.setOfflinePresences();
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
// Changes the presence available contacts to unavailable
|
||||
this.setOfflinePresences();
|
||||
}
|
||||
|
||||
public void reconnectingIn(int seconds) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
public void reconectionSuccessful() {
|
||||
// Ignore
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue