mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Add callbacks for block/unblock events to BlockingCommandManager
This commit is contained in:
parent
ff97d2eb35
commit
4d7b9318ce
4 changed files with 119 additions and 1 deletions
|
@ -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();
|
||||
|
||||
}
|
|
@ -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<AllJidsUnblockedListener> allJidsUnblockedListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
private final Set<JidsBlockedListener> jidsBlockedListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
private final Set<JidsUnblockedListener> jidsUnblockedListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
private BlockingCommandManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
||||
|
@ -99,6 +107,10 @@ public final class BlockingCommandManager extends Manager {
|
|||
List<Jid> 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<Jid> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Jid> blockedJids);
|
||||
|
||||
}
|
|
@ -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<Jid> unblockedJids);
|
||||
|
||||
}
|
Loading…
Reference in a new issue