mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Synchronize ChatStateManager's chatStateListeners
This commit is contained in:
parent
75babfb9c6
commit
9d53363413
1 changed files with 15 additions and 3 deletions
|
@ -17,7 +17,9 @@
|
|||
|
||||
package org.jivesoftware.smackx.chatstates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
@ -146,7 +148,13 @@ public final class ChatStateManager extends Manager {
|
|||
return;
|
||||
}
|
||||
|
||||
for (ChatStateListener listener : chatStateListeners) {
|
||||
List<ChatStateListener> listeners;
|
||||
synchronized (chatStateListeners) {
|
||||
listeners = new ArrayList<>(chatStateListeners.size());
|
||||
listeners.addAll(chatStateListeners);
|
||||
}
|
||||
|
||||
for (ChatStateListener listener : listeners) {
|
||||
listener.stateChanged(chat, state, message);
|
||||
}
|
||||
}
|
||||
|
@ -162,8 +170,10 @@ public final class ChatStateManager extends Manager {
|
|||
* @return true, if the listener was not registered before
|
||||
*/
|
||||
public boolean addChatStateListener(ChatStateListener listener) {
|
||||
synchronized (chatStateListeners) {
|
||||
return chatStateListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a ChatStateListener.
|
||||
|
@ -172,8 +182,10 @@ public final class ChatStateManager extends Manager {
|
|||
* @return true, if the listener was registered before
|
||||
*/
|
||||
public boolean removeChatStateListener(ChatStateListener listener) {
|
||||
synchronized (chatStateListeners) {
|
||||
return chatStateListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue