diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java new file mode 100644 index 000000000..0648d0e0c --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java @@ -0,0 +1,23 @@ +/** + * + * Copyright 2017 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.blocking; + +public interface AllJidsUnblockedListener { + + void onAllJidsUnblocked(); + +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java index 78b27c7f7..c67b82692 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java @@ -1,6 +1,6 @@ /** * - * Copyright 2016 Fernando Ramirez, Florian Schmaus + * Copyright 2016-2017 Fernando Ramirez, Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; +import java.util.concurrent.CopyOnWriteArraySet; import org.jivesoftware.smack.AbstractConnectionListener; import org.jivesoftware.smack.ConnectionCreationListener; @@ -82,6 +84,12 @@ public final class BlockingCommandManager extends Manager { return blockingCommandManager; } + private final Set allJidsUnblockedListeners = new CopyOnWriteArraySet<>(); + + private final Set jidsBlockedListeners = new CopyOnWriteArraySet<>(); + + private final Set jidsUnblockedListeners = new CopyOnWriteArraySet<>(); + private BlockingCommandManager(XMPPConnection connection) { super(connection); @@ -99,6 +107,10 @@ public final class BlockingCommandManager extends Manager { List blockedJids = blockContactIQ.getJids(); blockListCached.addAll(blockedJids); + for (JidsBlockedListener listener : jidsBlockedListeners) { + listener.onJidsBlocked(blockedJids); + } + return IQ.createResultIQ(blockContactIQ); } }); @@ -117,8 +129,14 @@ public final class BlockingCommandManager extends Manager { List unblockedJids = unblockContactIQ.getJids(); if (unblockedJids == null) { // remove all blockListCached.clear(); + for (AllJidsUnblockedListener listener : allJidsUnblockedListeners) { + listener.onAllJidsUnblocked(); + } } else { // remove only some blockListCached.removeAll(unblockedJids); + for (JidsUnblockedListener listener : jidsUnblockedListeners) { + listener.onJidsUnblocked(unblockedJids); + } } return IQ.createResultIQ(unblockContactIQ); @@ -216,4 +234,27 @@ public final class BlockingCommandManager extends Manager { connection().createStanzaCollectorAndSend(unblockContactIQ).nextResultOrThrow(); } + public void addJidsBlockedListener(JidsBlockedListener jidsBlockedListener) { + jidsBlockedListeners.add(jidsBlockedListener); + } + + public void removeJidsBlockedListener(JidsBlockedListener jidsBlockedListener) { + jidsBlockedListeners.remove(jidsBlockedListener); + } + + public void addJidsUnblockedListener(JidsUnblockedListener jidsUnblockedListener) { + jidsUnblockedListeners.add(jidsUnblockedListener); + } + + public void removeJidsUnblockedListener(JidsUnblockedListener jidsUnblockedListener) { + jidsUnblockedListeners.remove(jidsUnblockedListener); + } + + public void addAllJidsUnblockedListener(AllJidsUnblockedListener allJidsUnblockedListener) { + allJidsUnblockedListeners.add(allJidsUnblockedListener); + } + + public void removeAllJidsUnblockedListener(AllJidsUnblockedListener allJidsUnblockedListener) { + allJidsUnblockedListeners.remove(allJidsUnblockedListener); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java new file mode 100644 index 000000000..e907a7a5b --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2017 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.blocking; + +import java.util.List; + +import org.jxmpp.jid.Jid; + +public interface JidsBlockedListener { + + void onJidsBlocked(List blockedJids); + +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsUnblockedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsUnblockedListener.java new file mode 100644 index 000000000..139a9117c --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsUnblockedListener.java @@ -0,0 +1,27 @@ +/** + * + * Copyright 2017 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.blocking; + +import java.util.List; + +import org.jxmpp.jid.Jid; + +public interface JidsUnblockedListener { + + void onJidsUnblocked(List unblockedJids); + +}