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",