思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 MultiUserChatManager.java 源代码,内容仅作参考
package org.jivesoftware.smackx.muc;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
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.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Async;
import org.jivesoftware.smack.util.CleaningWeakReferenceMap;
import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muc.MultiUserChatException;
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
import org.jivesoftware.smackx.muc.packet.MUCUser;
public final class MultiUserChatManager extends Manager {
public static final boolean $assertionsDisabled = false;
public static final String DISCO_NODE = "http://jabber.org/protocol/muc#rooms";
public static final Map<XMPPConnection, MultiUserChatManager> INSTANCES;
public static final StanzaFilter INVITATION_FILTER;
public static final Logger LOGGER = Logger.getLogger(MultiUserChatManager.class.getName());
public AutoJoinFailedCallback autoJoinFailedCallback;
public boolean autoJoinOnReconnect;
public final Set<InvitationListener> invitationsListeners;
public final Set<tw3> joinedRooms;
public final Map<tw3, WeakReference<MultiUserChat>> multiUserChats;
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection xMPPConnection) {
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).addFeature(MUCInitialPresence.NAMESPACE);
final WeakReference weakReference = new WeakReference(xMPPConnection);
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).setNodeInformationProvider(MultiUserChatManager.DISCO_NODE, new AbstractNodeInformationProvider() {
@Override
public List<DiscoverItems.Item> getNodeItems() {
XMPPConnection xMPPConnection2 = (XMPPConnection) weakReference.get();
if (xMPPConnection2 == null) {
return Collections.emptyList();
}
Set<tw3> joinedRooms = MultiUserChatManager.getInstanceFor(xMPPConnection2).getJoinedRooms();
ArrayList arrayList = new ArrayList();
for (tw3 tw3Var : joinedRooms) {
arrayList.add(new DiscoverItems.Item(tw3Var));
}
return arrayList;
}
});
}
});
INSTANCES = new WeakHashMap();
INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()), new NotFilter(MessageTypeFilter.ERROR));
}
public MultiUserChatManager(XMPPConnection xMPPConnection) {
super(xMPPConnection);
this.invitationsListeners = new CopyOnWriteArraySet();
this.joinedRooms = new CopyOnWriteArraySet();
this.multiUserChats = new CleaningWeakReferenceMap();
xMPPConnection.addAsyncStanzaListener(new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
Message message = (Message) stanza;
MUCUser from = MUCUser.from(message);
if (from.getInvite() != null) {
tw3 k0 = message.getFrom().k0();
if (k0 == null) {
Logger logger = MultiUserChatManager.LOGGER;
logger.warning("Invite to non bare JID: '" + ((Object) message.toXML((String) null)) + "'");
return;
}
MultiUserChat multiUserChat = MultiUserChatManager.this.getMultiUserChat(k0);
XMPPConnection connection = MultiUserChatManager.this.connection();
MUCUser.Invite invite = from.getInvite();
vw3 from2 = invite.getFrom();
String reason = invite.getReason();
String password = from.getPassword();
for (InvitationListener invitationListener : MultiUserChatManager.this.invitationsListeners) {
invitationListener.invitationReceived(connection, multiUserChat, from2, reason, password, message, invite);
}
}
}
}, INVITATION_FILTER);
xMPPConnection.addConnectionListener(new AbstractConnectionListener() {
@Override
public void authenticated(XMPPConnection xMPPConnection2, boolean z) {
if (!z && MultiUserChatManager.this.autoJoinOnReconnect) {
final Set<tw3> joinedRooms = MultiUserChatManager.this.getJoinedRooms();
if (joinedRooms.isEmpty()) {
return;
}
Async.go(new Runnable() {
@Override
public void run() {
hx3 nickname;
AutoJoinFailedCallback autoJoinFailedCallback = MultiUserChatManager.this.autoJoinFailedCallback;
for (tw3 tw3Var : joinedRooms) {
MultiUserChat multiUserChat = MultiUserChatManager.this.getMultiUserChat(tw3Var);
if (!multiUserChat.isJoined() || (nickname = multiUserChat.getNickname()) == null) {
return;
}
try {
multiUserChat.leave();
try {
multiUserChat.join(nickname);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | MultiUserChatException.NotAMucServiceException e) {
if (autoJoinFailedCallback == null) {
MultiUserChatManager.LOGGER.log(Level.WARNING, "Could not leave room", (Throwable) e);
return;
} else {
autoJoinFailedCallback.autoJoinFailed(multiUserChat, e);
return;
}
}
} catch (InterruptedException | SmackException.NotConnectedException e2) {
if (autoJoinFailedCallback == null) {
MultiUserChatManager.LOGGER.log(Level.WARNING, "Could not leave room", (Throwable) e2);
return;
} else {
autoJoinFailedCallback.autoJoinFailed(multiUserChat, e2);
return;
}
}
}
}
});
}
}
});
}
private MultiUserChat createNewMucAndAddToMap(tw3 tw3Var) {
MultiUserChat multiUserChat = new MultiUserChat(connection(), tw3Var, this);
this.multiUserChats.put(tw3Var, new WeakReference<>(multiUserChat));
return multiUserChat;
}
public static synchronized MultiUserChatManager getInstanceFor(XMPPConnection xMPPConnection) {
MultiUserChatManager multiUserChatManager;
synchronized (MultiUserChatManager.class) {
multiUserChatManager = INSTANCES.get(xMPPConnection);
if (multiUserChatManager == null) {
multiUserChatManager = new MultiUserChatManager(xMPPConnection);
INSTANCES.put(xMPPConnection, multiUserChatManager);
}
}
return multiUserChatManager;
}
public void addInvitationListener(InvitationListener invitationListener) {
this.invitationsListeners.add(invitationListener);
}
public void addJoinedRoom(tw3 tw3Var) {
this.joinedRooms.add(tw3Var);
}
public void decline(tw3 tw3Var, tw3 tw3Var2, String str) throws SmackException.NotConnectedException, InterruptedException {
Stanza message = new Message(tw3Var);
MUCUser mUCUser = new MUCUser();
mUCUser.setDecline(new MUCUser.Decline(str, tw3Var2));
message.addExtension(mUCUser);
connection().sendStanza(message);
}
@Deprecated
public List<HostedRoom> getHostedRooms(qw3 qw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, MultiUserChatException.NotAMucServiceException {
return new ArrayList(getRoomsHostedBy(qw3Var).values());
}
public Set<tw3> getJoinedRooms() {
return Collections.unmodifiableSet(this.joinedRooms);
}
public List<qw3> getMucServiceDomains() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).findServices(MUCInitialPresence.NAMESPACE, false, false);
}
public synchronized MultiUserChat getMultiUserChat(tw3 tw3Var) {
WeakReference<MultiUserChat> weakReference = this.multiUserChats.get(tw3Var);
if (weakReference == null) {
return createNewMucAndAddToMap(tw3Var);
}
MultiUserChat multiUserChat = weakReference.get();
if (multiUserChat == null) {
return createNewMucAndAddToMap(tw3Var);
}
return multiUserChat;
}
public RoomInfo getRoomInfo(tw3 tw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return new RoomInfo(ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(tw3Var));
}
public Map<tw3, HostedRoom> getRoomsHostedBy(qw3 qw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, MultiUserChatException.NotAMucServiceException {
if (providesMucService(qw3Var)) {
List<DiscoverItems.Item> items = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(qw3Var).getItems();
HashMap hashMap = new HashMap(items.size());
for (DiscoverItems.Item item : items) {
HostedRoom hostedRoom = new HostedRoom(item);
HostedRoom hostedRoom2 = (HostedRoom) hashMap.put(hostedRoom.getJid(), hostedRoom);
}
return hashMap;
}
throw new MultiUserChatException.NotAMucServiceException(qw3Var);
}
@Deprecated
public List<qw3> getXMPPServiceDomains() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return getMucServiceDomains();
}
public boolean isServiceEnabled(xw3 xw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(xw3Var, MUCInitialPresence.NAMESPACE);
}
public boolean providesMucService(qw3 qw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(qw3Var, MUCInitialPresence.NAMESPACE);
}
public void removeInvitationListener(InvitationListener invitationListener) {
this.invitationsListeners.remove(invitationListener);
}
public void removeJoinedRoom(tw3 tw3Var) {
this.joinedRooms.remove(tw3Var);
}
public void setAutoJoinFailedCallback(AutoJoinFailedCallback autoJoinFailedCallback) {
this.autoJoinFailedCallback = autoJoinFailedCallback;
if (autoJoinFailedCallback != null) {
setAutoJoinOnReconnect(true);
}
}
public void setAutoJoinOnReconnect(boolean z) {
this.autoJoinOnReconnect = z;
}
public List<tw3> getJoinedRooms(vw3 vw3Var) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
List<DiscoverItems.Item> items = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(vw3Var, DISCO_NODE).getItems();
ArrayList arrayList = new ArrayList(items.size());
for (DiscoverItems.Item item : items) {
tw3 k0 = item.getEntityID().k0();
if (k0 == null) {
Logger logger = LOGGER;
logger.warning("Not a bare JID: " + ((Object) item.getEntityID()));
} else {
arrayList.add(k0);
}
}
return arrayList;
}
}