From 322292cad937f0f53ceb77c9e9ca4327a4d976b3 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Tue, 13 Feb 2007 02:23:28 +0000 Subject: [PATCH] Added ability to sign off with a custom presence packet (SMACK-195). git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7081 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/PacketReader.java | 2 +- .../jivesoftware/smack/XMPPConnection.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index 8693adf9a..eb4d07101 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -213,7 +213,7 @@ class PacketReader { void notifyConnectionError(Exception e) { done = true; // Closes the connection temporary. A reconnection is possible - connection.shutdown(); + connection.shutdown(new Presence(Presence.Type.unavailable)); // Print the stack trace to help catch the problem e.printStackTrace(); // Notify connection listeners of the error. diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index 7cdc1b5df..1bbf02815 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -556,10 +556,12 @@ public class XMPPConnection { * dealing with an unexpected disconnection. Unlike {@link #disconnect()} the connection's * packet reader, packet writer, and {@link Roster} will not be removed; thus * connection's state is kept. + * + * @param unavailablePresence the presence packet to send during shutdown. */ - protected void shutdown() { + protected void shutdown(Presence unavailablePresence) { // Set presence to offline. - packetWriter.sendPacket(new Presence(Presence.Type.unavailable)); + packetWriter.sendPacket(unavailablePresence); packetReader.shutdown(); packetWriter.shutdown(); // Wait 150 ms for processes to clean-up, then shutdown. @@ -602,7 +604,21 @@ public class XMPPConnection { * again. */ public void disconnect() { - this.shutdown(); + disconnect(new Presence(Presence.Type.unavailable)); + } + + /** + * Closes the connection. A custom unavailable presence is sent to the server, followed + * by closing the stream. The XMPPConnection can still be used for connecting to the server + * again. A custom unavilable presence is useful for communicating offline presence + * information such as "On vacation". Typically, just the status text of the presence + * packet is set with online information, but most XMPP servers will deliver the full + * presence packet with whatever data is set. + * + * @param unavailablePresence the presence packet to send during shutdown. + */ + public void disconnect(Presence unavailablePresence) { + this.shutdown(unavailablePresence); this.roster = null;