From 88bf2528a2a737ef62b627ecf5817f2bd2255814 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 9 Aug 2016 11:38:26 +0200 Subject: [PATCH] Add RosterUtil.askForSubscriptionIfRequired(Roster, BareJid) --- .../java/org/jivesoftware/smack/roster/RosterUtil.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterUtil.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterUtil.java index 7f13a4aff..1ee9cbaa8 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterUtil.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterUtil.java @@ -23,6 +23,8 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jivesoftware.smack.SmackException.NotLoggedInException; import org.jxmpp.jid.BareJid; import org.jxmpp.jid.Jid; @@ -80,4 +82,12 @@ public class RosterUtil { roster.removeRosterListener(rosterListener); } } + + public static void askForSubscriptionIfRequired(Roster roster, BareJid jid) + throws NotLoggedInException, NotConnectedException, InterruptedException { + RosterEntry entry = roster.getEntry(jid); + if (entry == null || !(entry.canSeeHisPresence() || entry.isSubscriptionPending())) { + roster.sendSubscriptionRequest(jid); + } + } }