思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 ChatStateManager.java 源代码,内容仅作参考
package org.jivesoftware.smackx.chatstates;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.AsyncButOrdered;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.chat2.OutgoingChatMessageListener;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromTypeFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.NotFilter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
public final class ChatStateManager extends Manager {
public static final String NAMESPACE = "http://jabber.org/protocol/chatstates";
public final AsyncButOrdered<Chat> asyncButOrdered;
public final Set<ChatStateListener> chatStateListeners;
public final Map<Chat, ChatState> chatStates;
public static final Logger LOGGER = Logger.getLogger(ChatStateManager.class.getName());
public static final Map<XMPPConnection, ChatStateManager> INSTANCES = new WeakHashMap();
public static final StanzaFilter filter = new NotFilter(new StanzaExtensionFilter("http://jabber.org/protocol/chatstates"));
public static final StanzaFilter INCOMING_MESSAGE_FILTER = new AndFilter(MessageTypeFilter.NORMAL_OR_CHAT, FromTypeFilter.ENTITY_FULL_JID);
public static final StanzaFilter INCOMING_CHAT_STATE_FILTER = new AndFilter(INCOMING_MESSAGE_FILTER, new StanzaExtensionFilter("http://jabber.org/protocol/chatstates"));
public ChatStateManager(XMPPConnection xMPPConnection) {
super(xMPPConnection);
this.chatStateListeners = new HashSet();
this.chatStates = new WeakHashMap();
this.asyncButOrdered = new AsyncButOrdered<>();
ChatManager.getInstanceFor(xMPPConnection).addOutgoingListener(new OutgoingChatMessageListener() {
@Override
public void newOutgoingMessage(tw3 tw3Var, Message message, Chat chat) {
if (chat != null && ChatStateManager.filter.accept(message) && ChatStateManager.this.updateChatState(chat, ChatState.active)) {
message.addExtension(new ChatStateExtension(ChatState.active));
}
}
});
xMPPConnection.addSyncStanzaListener(new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
final ArrayList arrayList;
final Message message = (Message) stanza;
final Chat chatWith = ChatManager.getInstanceFor(ChatStateManager.this.connection()).chatWith(message.getFrom().n0().u0());
String elementName = message.getExtension("http://jabber.org/protocol/chatstates").getElementName();
try {
final ChatState valueOf = ChatState.valueOf(elementName);
synchronized (ChatStateManager.this.chatStateListeners) {
arrayList = new ArrayList(ChatStateManager.this.chatStateListeners.size());
arrayList.addAll(ChatStateManager.this.chatStateListeners);
}
ChatStateManager.this.asyncButOrdered.performAsyncButOrdered(chatWith, new Runnable() {
@Override
public void run() {
for (ChatStateListener chatStateListener : arrayList) {
chatStateListener.stateChanged(chatWith, valueOf, message);
}
}
});
} catch (Exception e) {
Logger logger = ChatStateManager.LOGGER;
Level level = Level.WARNING;
logger.log(level, "Invalid chat state element name: " + elementName, (Throwable) e);
}
}
}, INCOMING_CHAT_STATE_FILTER);
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).addFeature("http://jabber.org/protocol/chatstates");
}
public static synchronized ChatStateManager getInstance(XMPPConnection xMPPConnection) {
ChatStateManager chatStateManager;
synchronized (ChatStateManager.class) {
chatStateManager = INSTANCES.get(xMPPConnection);
if (chatStateManager == null) {
chatStateManager = new ChatStateManager(xMPPConnection);
INSTANCES.put(xMPPConnection, chatStateManager);
}
}
return chatStateManager;
}
public synchronized boolean updateChatState(Chat chat, ChatState chatState) {
if (this.chatStates.get(chat) != chatState) {
this.chatStates.put(chat, chatState);
return true;
}
return false;
}
public boolean addChatStateListener(ChatStateListener chatStateListener) {
boolean add;
synchronized (this.chatStateListeners) {
add = this.chatStateListeners.add(chatStateListener);
}
return add;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || ChatStateManager.class != obj.getClass()) {
return false;
}
return connection().equals(((ChatStateManager) obj).connection());
}
public int hashCode() {
return connection().hashCode();
}
public boolean removeChatStateListener(ChatStateListener chatStateListener) {
boolean remove;
synchronized (this.chatStateListeners) {
remove = this.chatStateListeners.remove(chatStateListener);
}
return remove;
}
public void setCurrentState(ChatState chatState, Chat chat) throws SmackException.NotConnectedException, InterruptedException {
if (chat != null && chatState != null) {
if (updateChatState(chat, chatState)) {
Message message = new Message();
message.addExtension(new ChatStateExtension(chatState));
chat.send(message);
return;
}
return;
}
throw new IllegalArgumentException("Arguments cannot be null.");
}
}