From 6a7f7826cdcac8522686d6be4a91a9a8cad711e5 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Thu, 27 Oct 2005 15:22:14 +0000 Subject: [PATCH] Added automatic acknowledge receipt for the unsubscribe notification. SMACK-98 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2998 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index d53570353..ea367d7a0 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -42,9 +42,9 @@ import java.util.*; public class Roster { /** - * Automatically accept all subscription requests. This is the default mode - * and is suitable for simple client. More complex client will likely wish to - * handle subscription requests manually. + * Automatically accept all subscription and unsubscription requests. This is + * the default mode and is suitable for simple client. More complex client will + * likely wish to handle subscription requests manually. */ public static final int SUBSCRIPTION_ACCEPT_ALL = 0; @@ -56,7 +56,8 @@ public class Roster { /** * Subscription requests are ignored, which means they must be manually * processed by registering a listener for presence packets and then looking - * for any presence requests that have the type Presence.Type.SUBSCRIBE. + * for any presence requests that have the type Presence.Type.SUBSCRIBE or + * Presence.Type.UNSUBSCRIBE. */ public static final int SUBSCRIPTION_MANUAL = 2; @@ -646,6 +647,17 @@ public class Roster { } // Otherwise, in manual mode so ignore. } + else if (presence.getType() == Presence.Type.UNSUBSCRIBE) { + if (subscriptionMode != SUBSCRIPTION_MANUAL) { + // Acknowledge and accept unsubscription notification so that the + // server will stop sending notifications saying that the contact + // has unsubscribed to our presence. + Presence response = new Presence(Presence.Type.UNSUBSCRIBED); + response.setTo(presence.getFrom()); + connection.sendPacket(response); + } + // Otherwise, in manual mode so ignore. + } } }