1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 08:12:05 +01:00

Synchronize ChatStateManager's chatStateListeners

This commit is contained in:
Florian Schmaus 2018-04-06 19:31:32 +02:00
parent 75babfb9c6
commit 9d53363413

View file

@ -17,7 +17,9 @@
package org.jivesoftware.smackx.chatstates; package org.jivesoftware.smackx.chatstates;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
@ -146,7 +148,13 @@ public final class ChatStateManager extends Manager {
return; 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); listener.stateChanged(chat, state, message);
} }
} }
@ -162,8 +170,10 @@ public final class ChatStateManager extends Manager {
* @return true, if the listener was not registered before * @return true, if the listener was not registered before
*/ */
public boolean addChatStateListener(ChatStateListener listener) { public boolean addChatStateListener(ChatStateListener listener) {
synchronized (chatStateListeners) {
return chatStateListeners.add(listener); return chatStateListeners.add(listener);
} }
}
/** /**
* Unregister a ChatStateListener. * Unregister a ChatStateListener.
@ -172,8 +182,10 @@ public final class ChatStateManager extends Manager {
* @return true, if the listener was registered before * @return true, if the listener was registered before
*/ */
public boolean removeChatStateListener(ChatStateListener listener) { public boolean removeChatStateListener(ChatStateListener listener) {
synchronized (chatStateListeners) {
return chatStateListeners.remove(listener); return chatStateListeners.remove(listener);
} }
}
/** /**