From bf9fb7d2d9c124a2d82a266c50e44e33c568a1de Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 19 Jan 2015 16:14:14 +0100 Subject: [PATCH] Add Roster.isSubscribedToMyPresence(String) --- .../java/org/jivesoftware/smack/Roster.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java b/smack-core/src/main/java/org/jivesoftware/smack/Roster.java index 21bd06756..13ec034e0 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/Roster.java @@ -697,6 +697,32 @@ public class Roster { return Collections.unmodifiableList(res); } + /** + * Check if the given JID is subscribed to the user's presence. + *

+ * If the JID is subscribed to the user's presence then it is allowed to see the presence and + * will get notified about presence changes. + *

+ * Note that if the roster is not loaded, then this method will always return false. + * + * @param jid + * @return true if the given JID is allowed to see the users presence. + * @since 4.1 + */ + public boolean isSubscribedToMyPresence(String jid) { + RosterEntry entry = getEntry(jid); + if (entry == null) { + return false; + } + switch (entry.getType()) { + case from: + case both: + return true; + default: + return false; + } + } + /** * Returns the key to use in the presenceMap for a fully qualified XMPP ID. * The roster can contain any valid address format such us "domain/resource",