CryptoMessage v1.3.2版本的 MD5 值为:66c611ce56a11450659dc23697562928
以下内容为反编译后的 MultiUserChatManager.java 源代码,内容仅作参考
package org.jivesoftware.smackx.muc;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Consumer;
import java.util.logging.Logger;
import org.apache.commons.lang3.RandomStringUtils;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.contacts.ContactManager;
import org.jivesoftware.smack.db.DatabaseManager;
import org.jivesoftware.smack.db.entities.AccountEntity;
import org.jivesoftware.smack.db.entities.ContactItem;
import org.jivesoftware.smack.db.entities.MultiUserChatItem;
import org.jivesoftware.smack.extensions.TimestampExtension;
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.IQ;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.PresenceBuilder;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.util.Async;
import org.jivesoftware.smack.util.CleaningWeakReferenceMap;
import org.jivesoftware.smack.util.ExceptionCallback;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jivesoftware.smackx.bookmarks.BookmarkManager;
import org.jivesoftware.smackx.delay.DelayInformationManager;
import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager;
import org.jivesoftware.smackx.iqregister.AccountManager;
import org.jivesoftware.smackx.muc.MucEnterConfiguration;
import org.jivesoftware.smackx.muc.MultiUserChatException;
import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;
import org.jivesoftware.smackx.muc.packet.MUCInfo;
import org.jivesoftware.smackx.muc.packet.MUCItem;
import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jivesoftware.smackx.push.PUSHManager;
import org.jivesoftware.smackx.vcardtemp.packet.VCard;
import org.jivesoftware.smackx.xdata.form.FillableForm;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.util.cache.ExpirationCache;
public final class MultiUserChatManager extends Manager {
static final boolean $assertionsDisabled = false;
private static final String DISCO_NODE = "http://jabber.org/protocol/muc#rooms";
private final AccountManager accountManager;
private final XMPPConnection connection;
private final ContactManager contactManager;
private final DatabaseManager databaseManager;
private final HttpFileUploadManager httpFileUploadManager;
private final Set<InvitationListener> invitationsListeners;
private final Set<EntityBareJid> joinedRooms;
private final Set<MUCEventListener> mucEventListeners;
private final Map<EntityBareJid, WeakReference<MultiUserChat>> multiUserChats;
private final ServiceDiscoveryManager serviceDiscoveryManager;
private static final Logger logger = Logger.getLogger(MultiUserChatManager.class.getName());
private static final Map<XMPPConnection, MultiUserChatManager> INSTANCES = new WeakHashMap();
private static final StanzaFilter INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()), new NotFilter(MessageTypeFilter.ERROR));
private static final AndFilter MUC_PRESENCE_FILTER = new AndFilter(StanzaTypeFilter.PRESENCE, new StanzaExtensionFilter("x", MUCUser.NAMESPACE));
private static final ExpirationCache<DomainBareJid, Void> KNOWN_MUC_SERVICES = new ExpirationCache<>(100, 86400000);
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection xMPPConnection) {
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).addFeature("http://jabber.org/protocol/muc");
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<EntityBareJid> joinedRooms = MultiUserChatManager.getInstanceFor(xMPPConnection2).getJoinedRooms();
ArrayList arrayList = new ArrayList();
Iterator<EntityBareJid> it = joinedRooms.iterator();
while (it.hasNext()) {
arrayList.add(new DiscoverItems.Item(it.next()));
}
return arrayList;
}
});
}
});
}
private MultiUserChatManager(final XMPPConnection xMPPConnection) {
super(xMPPConnection);
this.invitationsListeners = new CopyOnWriteArraySet();
this.mucEventListeners = new CopyOnWriteArraySet();
this.joinedRooms = new CopyOnWriteArraySet();
this.multiUserChats = new CleaningWeakReferenceMap();
this.connection = xMPPConnection;
this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(xMPPConnection);
this.databaseManager = DatabaseManager.getInstance();
this.accountManager = AccountManager.getInstance(xMPPConnection);
this.contactManager = ContactManager.getInstanceFor(xMPPConnection);
this.httpFileUploadManager = HttpFileUploadManager.getInstanceFor(xMPPConnection);
xMPPConnection.addAsyncStanzaListener(new StanzaListener() {
@Override
public final void processStanza(Stanza stanza) {
MultiUserChatManager.this.handleMUCPresence(stanza);
}
}, MUC_PRESENCE_FILTER);
xMPPConnection.addAsyncStanzaListener(new StanzaListener() {
@Override
public final void processStanza(Stanza stanza) {
MultiUserChatManager.this.lambda$new$0(xMPPConnection, stanza);
}
}, INVITATION_FILTER);
}
public void lambda$new$0(XMPPConnection xMPPConnection, Stanza stanza) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
Localpart localpartOrNull = stanza.getTo().getLocalpartOrNull();
Localpart localpart = xMPPConnection.getUser().getLocalpart();
if (localpartOrNull.equals(localpart)) {
Localpart localpartOrNull2 = stanza.getFrom().getLocalpartOrNull();
Date delayTimestamp = DelayInformationManager.getDelayTimestamp(stanza);
Logger logger2 = logger;
logger2.warning(">>>>> packet.getFrom().getLocalpartOrNull() " + ((Object) localpartOrNull2));
logger2.warning(">>>>> DelayInformationManager.getDelayTimestamp inviteDate " + delayTimestamp);
Date inviteDate = getInviteDate(stanza);
logger2.warning(">>>>> getInviteDate " + inviteDate);
if (localpartOrNull2 != null) {
try {
MultiUserChatItem loadMUCFromServer = loadMUCFromServer(localpartOrNull2.toString(), true);
if (loadMUCFromServer == null) {
return;
}
logger2.warning(">>>>> invite loadMUCFromServer contacts size: " + loadMUCFromServer.getContactItems().size() + " members size: " + loadMUCFromServer.getMembers());
ContactItem contactItem = loadMUCFromServer.getContactItem();
EntityBareJid bareJid = loadMUCFromServer.getBareJid(xMPPConnection);
MultiUserChat multiUserChat = getMultiUserChat(bareJid);
Resourcepart resourceOrThrow = xMPPConnection.getUser().getResourceOrThrow();
this.contactManager.upsert(contactItem);
upsertMUC(loadMUCFromServer);
if (stanza.hasExtension(GroupChatInvitation.NAMESPACE)) {
multiUserChat.join(new MucEnterConfiguration.Builder(resourceOrThrow, connection()).requestHistorySince(inviteDate).build());
inviteMessage(bareJid.getLocalpartOrThrow().toString(), localpart.toString());
}
} catch (Exception e) {
logger.warning("не удалось войти в комнату " + ((Object) localpartOrNull2));
e.printStackTrace();
}
}
}
}
public static synchronized MultiUserChatManager getInstanceFor(XMPPConnection xMPPConnection) {
MultiUserChatManager multiUserChatManager;
synchronized (MultiUserChatManager.class) {
Map<XMPPConnection, MultiUserChatManager> map = INSTANCES;
multiUserChatManager = map.get(xMPPConnection);
if (multiUserChatManager == null) {
multiUserChatManager = new MultiUserChatManager(xMPPConnection);
map.put(xMPPConnection, multiUserChatManager);
}
}
return multiUserChatManager;
}
public void handleMUCPresence(final Stanza stanza) {
Async.go(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$handleMUCPresence$5(stanza);
}
});
}
public void lambda$handleMUCPresence$5(Stanza stanza) {
try {
Logger logger2 = logger;
logger2.warning(">>>>> handleMUCPresence");
if (stanza.hasExtension(InviteUserExtension.NAMESPACE)) {
MUCUser from = MUCUser.from(stanza);
if (from.getItem().getActor() != null && from.getItem().getJid() != null) {
inviteUser(from.getItem().getJid().getLocalpartOrNull().toString(), from.getItem().getActor().getLocalpartOrNull().toString());
return;
}
}
if (stanza.hasExtension(BanUserExtension.NAMESPACE)) {
MUCUser from2 = MUCUser.from(stanza);
if (from2.getItem().getActor() != null && from2.getItem().getJid() != null) {
banUser(from2.getItem().getJid().getLocalpartOrNull().toString(), from2.getItem().getActor().getLocalpartOrNull().toString());
return;
}
}
final MultiUserChatItem multiUserChatItem = DatabaseManager.getMultiUserChatItem(stanza.getFrom().getLocalpartOrThrow().toString());
if (multiUserChatItem == null) {
return;
}
String asUnescapedString = this.connection.getUser().getLocalpartOrThrow().asUnescapedString();
MUCUser from3 = MUCUser.from(stanza);
if (from3 == null || from3.getItem() == null) {
throw new MultiUserChatException.MUCNotFoundException("mucUser item is null");
}
String part = from3.getItem().getJid().getLocalpartOrThrow().toString();
logger2.warning(">>>>> handleMUCPresence target " + part);
if (MUCAffiliation.owner == from3.getItem().getAffiliation() && asUnescapedString.equals(part)) {
return;
}
final ContactItem loadContactItem = this.contactManager.loadContactItem(part);
if (loadContactItem == null) {
throw new NullPointerException("Целевой пользователь не найден ");
}
final ContactItem contactItem = null;
if (from3.getItem().getActor() != null) {
contactItem = this.contactManager.loadContactItem(from3.getItem().getActor().getLocalpartOrThrow().toString());
}
logger2.warning(">>>>> handleMUCPresence mucUser.getItem().getAffiliation() == MUCAffiliation.outcast " + from3.getItem().getAffiliation());
if (from3.getItem().getAffiliation() == MUCAffiliation.outcast) {
if (part.equals(asUnescapedString)) {
multiUserChatItem.setAvailable($assertionsDisabled);
}
multiUserChatItem.getMembers().remove(part);
multiUserChatItem.getContactItems().remove(loadContactItem);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onKickingUser(MultiUserChatItem.this, loadContactItem, contactItem, "");
}
});
this.databaseManager.getMultiUserChatDao().update(multiUserChatItem);
return;
}
logger2.warning(">>>>> handleMUCPresence (MUCAffiliation.member == mucUser.getItem().getAffiliation() " + from3.getItem().getAffiliation());
if (MUCAffiliation.member == from3.getItem().getAffiliation()) {
multiUserChatItem.getMembers().add(part);
multiUserChatItem.getContactItems().add(loadContactItem);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onAddingUser(MultiUserChatItem.this, loadContactItem, contactItem);
}
});
this.databaseManager.getMultiUserChatDao().update(multiUserChatItem);
return;
}
logger2.warning(">>>>> handleMUCPresence mucUser.getItem().getRole() == MUCRole.moderator " + from3.getItem().getRole());
if (from3.getItem().getRole() == MUCRole.moderator) {
multiUserChatItem.getAdmins().add(part);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onAddingAdmin(MultiUserChatItem.this, loadContactItem, contactItem);
}
});
this.databaseManager.getMultiUserChatDao().update(multiUserChatItem);
return;
}
logger2.warning(">>>>> handleMUCPresence mucUser.getItem().getRole() == MUCRole.participant " + from3.getItem().getRole());
if (from3.getItem().getRole() == MUCRole.participant) {
multiUserChatItem.getAdmins().remove(part);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onRevokingAdmin(MultiUserChatItem.this, loadContactItem);
}
});
this.databaseManager.getMultiUserChatDao().update(multiUserChatItem);
} else {
logger2.warning(">>>>> handleMUCPresence loadMUCFromServer");
this.contactManager.upsert(multiUserChatItem.getContactItem());
upsertMUC(multiUserChatItem);
}
} catch (Exception e) {
logger.warning("Handle MUC presence failed " + e);
e.printStackTrace();
}
}
public SmackFuture<Boolean, Exception> inviteUsers(final MultiUserChatItem multiUserChatItem, final Collection<ContactItem> collection, final String str) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$inviteUsers$9(multiUserChatItem, collection, str, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$inviteUsers$9(MultiUserChatItem multiUserChatItem, Collection collection, String str, SmackFuture.InternalSmackFuture internalSmackFuture) {
final MultiUserChatItem multiUserChatItem2 = DatabaseManager.getMultiUserChatItem(multiUserChatItem.getRoom());
EntityBareJid bareJid = multiUserChatItem2.getBareJid(this.connection);
MultiUserChat multiUserChat = getMultiUserChat(multiUserChatItem2.getBareJid(this.connection));
Collection<? extends ContactItem> linkedList = new LinkedList<>();
LinkedList linkedList2 = new LinkedList();
Iterator it = collection.iterator();
while (it.hasNext()) {
final ContactItem contactItem = (ContactItem) it.next();
try {
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.SET_INVITE_DATE, bareJid.getLocalpart().toString(), contactItem.getLocalpart()));
if (mUCInfo != null && mUCInfo.getError() == null) {
Date inviteDate = getInviteDate(this.connection.getUser().getLocalpart().toString(), bareJid.getLocalpart().toString());
logger.warning(">>>>> getInviteDate " + inviteDate);
MucEnterConfiguration.Builder builder = new MucEnterConfiguration.Builder(this.connection.getUser().getResourceOrThrow(), connection());
if (inviteDate != null) {
builder.requestHistorySince(inviteDate);
}
multiUserChat.join(builder.build());
multiUserChat.invite(contactItem.getBareJid(this.connection), str);
linkedList.add(contactItem);
linkedList2.add(contactItem.getLocalpart());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onInvitingUser(MultiUserChatItem.this, contactItem);
}
});
PUSHManager.getInstanceFor(this.connection).sendPush(contactItem.getBareJid(connection()), this.connection.getUser().asEntityBareJid()).onSuccess(new SuccessCallback() {
@Override
public final void onSuccess(Object obj) {
MultiUserChatManager.lambda$inviteUsers$7((IQ) obj);
}
}).onError(new ExceptionCallback() {
@Override
public final void processException(Object obj) {
MultiUserChatManager.lambda$inviteUsers$8((Exception) obj);
}
});
}
} catch (Exception e) {
e.printStackTrace();
linkedList.remove(contactItem);
linkedList2.remove(contactItem.getLocalpart());
logger.warning("Не удалось добавить пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " в группу " + multiUserChatItem.getName());
}
}
try {
multiUserChatItem2.getContactItems().addAll(linkedList);
multiUserChatItem2.getMembers().addAll(linkedList2);
upsertMUC(multiUserChatItem2);
multiUserChatItem2.getContactItem().setMultiUserChatItem(multiUserChatItem2);
this.contactManager.upsert(multiUserChatItem2.getContactItem());
sendInviteUserMessage(multiUserChatItem2, linkedList);
internalSmackFuture.setResult(Boolean.TRUE);
} catch (Exception e2) {
e2.printStackTrace();
internalSmackFuture.setResult(Boolean.FALSE);
internalSmackFuture.setException(e2);
}
}
public static void lambda$inviteUsers$7(IQ iq) {
logger.info(">>>>> send push success ");
}
public static void lambda$inviteUsers$8(Exception exc) {
logger.warning(">>>>> send push error " + exc.getMessage());
}
public SmackFuture<Boolean, Exception> inviteUser(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, final String str) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$inviteUser$13(multiUserChatItem, contactItem, str, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$inviteUser$13(MultiUserChatItem multiUserChatItem, final ContactItem contactItem, String str, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
final MultiUserChatItem multiUserChatItem2 = DatabaseManager.getMultiUserChatItem(multiUserChatItem.getRoom());
EntityBareJid bareJid = multiUserChatItem2.getBareJid(this.connection);
MultiUserChat multiUserChat = getMultiUserChat(multiUserChatItem2.getBareJid(this.connection));
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.SET_INVITE_DATE, bareJid.getLocalpart().toString(), contactItem.getLocalpart()));
if (mUCInfo != null && mUCInfo.getError() == null) {
Date inviteDate = getInviteDate(this.connection.getUser().getLocalpart().toString(), bareJid.getLocalpart().toString());
logger.warning(">>>>> getInviteDate " + inviteDate);
MucEnterConfiguration.Builder builder = new MucEnterConfiguration.Builder(this.connection.getUser().getResourceOrThrow(), connection());
if (inviteDate != null) {
builder.requestHistorySince(inviteDate);
}
multiUserChat.join(builder.build());
multiUserChat.invite(contactItem.getBareJid(this.connection), str);
multiUserChatItem2.getMembers().add(contactItem.getLocalpart());
multiUserChatItem2.getContactItems().add(contactItem);
upsertMUC(multiUserChatItem2);
multiUserChatItem2.getContactItem().setMultiUserChatItem(multiUserChatItem2);
this.contactManager.upsert(multiUserChatItem2.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onInvitingUser(MultiUserChatItem.this, contactItem);
}
});
HashSet hashSet = new HashSet();
hashSet.add(contactItem);
sendInviteUserMessage(multiUserChatItem2, hashSet);
PUSHManager.getInstanceFor(this.connection).sendPush(contactItem.getBareJid(connection()), this.connection.getUser().asEntityBareJid()).onSuccess(new SuccessCallback() {
@Override
public final void onSuccess(Object obj) {
MultiUserChatManager.lambda$inviteUser$11((IQ) obj);
}
}).onError(new ExceptionCallback() {
@Override
public final void processException(Object obj) {
MultiUserChatManager.lambda$inviteUser$12((Exception) obj);
}
});
internalSmackFuture.setResult(Boolean.TRUE);
return;
}
internalSmackFuture.setResult(Boolean.FALSE);
} catch (InterruptedException e) {
e = e;
logger.warning("Не удалось добавить пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " в группу " + multiUserChatItem.getName());
e.printStackTrace();
internalSmackFuture.setException(e);
} catch (SmackException.NoResponseException e2) {
e2.printStackTrace();
internalSmackFuture.setException(e2);
} catch (SmackException.NotConnectedException e3) {
e = e3;
logger.warning("Не удалось добавить пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " в группу " + multiUserChatItem.getName());
e.printStackTrace();
internalSmackFuture.setException(e);
} catch (XMPPException.XMPPErrorException e4) {
e4.printStackTrace();
internalSmackFuture.setException(e4);
} catch (MultiUserChatException.NotAMucServiceException e5) {
e5.printStackTrace();
internalSmackFuture.setException(e5);
}
}
public static void lambda$inviteUser$11(IQ iq) {
logger.info(">>>>> send push success ");
}
public static void lambda$inviteUser$12(Exception exc) {
logger.warning(">>>>> send push error " + exc.getMessage());
}
public SmackFuture<Boolean, Exception> banUser(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, final String str) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$banUser$17(multiUserChatItem, contactItem, str, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$banUser$17(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, final String str, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
MultiUserChat multiUserChat = getMultiUserChat(multiUserChatItem.getBareJid(this.connection));
final ContactItem loadContactItem = this.contactManager.loadContactItem();
multiUserChat.banUser(contactItem.getBareJid(this.connection), str);
multiUserChatItem.getMembers().remove(contactItem.getLocalpart());
multiUserChatItem.getContactItems().remove(contactItem);
upsertMUC(multiUserChatItem);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onLeftMultiUserChat(MultiUserChatItem.this, contactItem, loadContactItem, str);
}
});
((MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.DELETE_INVITE, multiUserChatItem.getRoom(), contactItem.getLocalpart()))).getError();
sendBanUserMessage(multiUserChatItem, contactItem);
PUSHManager.getInstanceFor(this.connection).sendPush(contactItem.getBareJid(connection()), this.connection.getUser().asEntityBareJid()).onSuccess(new SuccessCallback() {
@Override
public final void onSuccess(Object obj) {
MultiUserChatManager.lambda$banUser$15((IQ) obj);
}
}).onError(new ExceptionCallback() {
@Override
public final void processException(Object obj) {
MultiUserChatManager.lambda$banUser$16((Exception) obj);
}
});
internalSmackFuture.setResult(Boolean.TRUE);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning("Не удалось удалить пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " из группы " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
public static void lambda$banUser$15(IQ iq) {
logger.info(">>>>> send push success ");
}
public static void lambda$banUser$16(Exception exc) {
logger.warning(">>>>> send push error " + exc.getMessage());
}
public void banUser(String str, String str2) {
final ContactItem loadContactItem;
final MultiUserChatItem multiUserChatItem = DatabaseManager.getMultiUserChatItem(str);
if (multiUserChatItem == null || (loadContactItem = this.contactManager.loadContactItem(str2)) == null) {
return;
}
multiUserChatItem.getMembers().remove(str2);
multiUserChatItem.getContactItems().remove(loadContactItem);
upsertMUC(multiUserChatItem);
multiUserChatItem.getContactItem().setMultiUserChatItem(multiUserChatItem);
this.contactManager.upsert(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onKickingUser(MultiUserChatItem.this, loadContactItem, null, "");
}
});
}
public void sendBanUserMessage(MultiUserChatItem multiUserChatItem, ContactItem contactItem) throws SmackException.NotConnectedException, InterruptedException {
logger.warning(">>>>> sendBanUserMessage multiUserChatItem.getContactItems() " + multiUserChatItem.getContactItems().size());
String part = this.connection.getUser().getLocalpart().toString();
for (ContactItem contactItem2 : multiUserChatItem.getContactItems()) {
if (!contactItem2.getLocalpart().equals(part)) {
logger.warning(">>>>> sendBanUserMessage contactItem " + contactItem2.getLocalpart());
MUCUser mUCUser = new MUCUser();
mUCUser.setItem(new MUCItem(multiUserChatItem.getBareJid(this.connection), contactItem.getBareJid(this.connection)));
this.connection.sendStanza(((PresenceBuilder) ((PresenceBuilder) ((PresenceBuilder) ((PresenceBuilder) this.connection.getStanzaFactory().buildPresenceStanza().ofType(Presence.Type.unavailable).from((Jid) this.connection.getUser().asBareJid())).to((Jid) contactItem2.getBareJid(this.connection))).addExtension(new BanUserExtension(multiUserChatItem.getContactItem().getLocalpart(), contactItem.getLocalpart()))).addExtension(mUCUser)).build());
}
}
}
public void inviteUser(String str, String str2) {
final ContactItem loadContactItem;
final MultiUserChatItem multiUserChatItem = DatabaseManager.getMultiUserChatItem(str);
if (multiUserChatItem == null || (loadContactItem = this.contactManager.loadContactItem(str2)) == null) {
return;
}
multiUserChatItem.getMembers().add(str2);
multiUserChatItem.getContactItems().add(loadContactItem);
upsertMUC(multiUserChatItem);
multiUserChatItem.getContactItem().setMultiUserChatItem(multiUserChatItem);
logger.warning(">>>>> inviteUser getMultiUserChatItem " + str + " contacts size: " + multiUserChatItem.getContactItems().size() + " members size: " + multiUserChatItem.getMembers());
this.contactManager.upsert(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onAddingUser(MultiUserChatItem.this, loadContactItem, null);
}
});
}
public void sendInviteUserMessage(MultiUserChatItem multiUserChatItem, Collection<ContactItem> collection) throws SmackException.NotConnectedException, InterruptedException {
logger.warning(">>>>> sendInviteUserMessage multiUserChatItem.getContactItems() " + multiUserChatItem.getContactItems().size() + "members: " + multiUserChatItem.getMembers());
String part = this.connection.getUser().getLocalpart().toString();
ArrayList<ContactItem> arrayList = new ArrayList();
arrayList.addAll(multiUserChatItem.getContactItems());
for (ContactItem contactItem : arrayList) {
if (!contactItem.getLocalpart().equals(part)) {
for (ContactItem contactItem2 : collection) {
logger.warning(">>>>> sendInviteUserMessage contactItem " + contactItem.getLocalpart());
MUCUser mUCUser = new MUCUser();
mUCUser.setItem(new MUCItem(multiUserChatItem.getBareJid(this.connection), contactItem2.getBareJid(this.connection)));
this.connection.sendStanza(((PresenceBuilder) ((PresenceBuilder) ((PresenceBuilder) ((PresenceBuilder) this.connection.getStanzaFactory().buildPresenceStanza().ofType(Presence.Type.available).from((Jid) this.connection.getUser().asBareJid())).to((Jid) contactItem.getBareJid(this.connection))).addExtension(new InviteUserExtension(multiUserChatItem.getContactItem().getLocalpart(), contactItem2.getLocalpart()))).addExtension(mUCUser)).build());
}
}
}
}
public boolean isUserInvite(Stanza stanza) {
TimestampExtension timestampExtension;
try {
Logger logger2 = logger;
logger2.warning(">>>> isUserInvite " + stanza.getFrom().asBareJid().getLocalpartOrNull().toString() + " " + this.connection.getUser().getLocalpart().toString());
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.GET_INVITE_DATE, stanza.getFrom().asBareJid().getLocalpartOrNull().toString(), this.connection.getUser().getLocalpart().toString()));
if (mUCInfo.getInviteDate() != null && !mUCInfo.getInviteDate().isEmpty()) {
Long valueOf = Long.valueOf(Long.parseLong(mUCInfo.getInviteDate()));
logger2.warning(">>>> isUserInvite inviteDate " + valueOf);
if (stanza.hasExtension(TimestampExtension.NAMESPACE) && (timestampExtension = (TimestampExtension) stanza.getExtension(TimestampExtension.NAMESPACE)) != null && timestampExtension.getTimestamp() > 0) {
logger2.warning(">>>> isUserInvite messageTimestamp " + timestampExtension.getTimestamp());
if (valueOf.longValue() >= timestampExtension.getTimestamp()) {
return $assertionsDisabled;
}
logger2.warning(">>>> isUserInvite true ");
return true;
}
}
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning(e.getMessage());
e.printStackTrace();
}
return true;
}
public Date getInviteDate(Stanza stanza) {
try {
Logger logger2 = logger;
logger2.warning(">>>> getDateInvite " + stanza.getFrom().asBareJid().getLocalpartOrNull().toString() + " " + this.connection.getUser().getLocalpart().toString());
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.GET_INVITE_DATE, stanza.getFrom().asBareJid().getLocalpartOrNull().toString(), this.connection.getUser().getLocalpart().toString()));
if (mUCInfo.getInviteDate() == null || mUCInfo.getInviteDate().isEmpty()) {
return null;
}
Long valueOf = Long.valueOf(Long.parseLong(mUCInfo.getInviteDate()));
logger2.warning(">>>> getDateInvite inviteDate " + valueOf);
return new Date(valueOf.longValue());
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning(e.getMessage());
e.printStackTrace();
return null;
}
}
public Date getInviteDate(String str, String str2) {
try {
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.GET_INVITE_DATE, str2, str));
if (mUCInfo.getInviteDate() == null || mUCInfo.getInviteDate().isEmpty()) {
return null;
}
Long valueOf = Long.valueOf(Long.parseLong(mUCInfo.getInviteDate()));
logger.warning(">>>> getDateInvite inviteDate " + valueOf);
return new Date(valueOf.longValue());
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning(e.getMessage());
e.printStackTrace();
return null;
}
}
public void inviteMessage(String str, String str2) {
final MultiUserChatItem multiUserChatItem = DatabaseManager.getMultiUserChatItem(str);
final ContactItem loadContactItem = this.contactManager.loadContactItem(str2);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onInvitingUser(MultiUserChatItem.this, loadContactItem);
}
});
}
public SmackFuture<Boolean, Exception> editChatName(final MultiUserChatItem multiUserChatItem) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$editChatName$21(multiUserChatItem, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$editChatName$21(MultiUserChatItem multiUserChatItem, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
MultiUserChat multiUserChat = getMultiUserChat(multiUserChatItem.getBareJid(this.connection));
FillableForm fillableForm = multiUserChat.getConfigurationForm().getFillableForm();
fillableForm.setAnswer("muc#roomconfig_roomname", multiUserChatItem.getName());
multiUserChat.sendConfigurationForm(fillableForm);
multiUserChat.changeSubject(multiUserChatItem.getName());
ContactItem contactItem = multiUserChatItem.getContactItem();
contactItem.setFirstName(multiUserChatItem.getName());
multiUserChatItem.setContactItem(contactItem);
upsertMUC(multiUserChatItem);
this.contactManager.upsert(contactItem);
setMUCVCard(contactItem);
internalSmackFuture.setResult(Boolean.TRUE);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning("Не удалось переименовать чат " + multiUserChatItem.getName());
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
public SmackFuture<Boolean, Exception> grantAdmin(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$grantAdmin$23(multiUserChatItem, contactItem, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$grantAdmin$23(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
final ContactItem loadContactItem = this.contactManager.loadContactItem();
getMultiUserChat(multiUserChatItem.getBareJid(this.connection)).grantAdmin(contactItem.getBareJid(this.connection));
multiUserChatItem.getAdmins().add(contactItem.getLocalpart());
upsertMUC(multiUserChatItem);
this.contactManager.upsert(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onAddingAdmin(MultiUserChatItem.this, contactItem, loadContactItem);
}
});
internalSmackFuture.setResult(Boolean.TRUE);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning("Не удалось добавить в администраторы пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " в группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
internalSmackFuture.setResult(Boolean.FALSE);
}
}
public SmackFuture<Boolean, Exception> revokeAdmin(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, String str) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$revokeAdmin$25(multiUserChatItem, contactItem, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$revokeAdmin$25(final MultiUserChatItem multiUserChatItem, final ContactItem contactItem, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
getMultiUserChat(multiUserChatItem.getBareJid(this.connection)).revokeAdmin(contactItem.getBareJid(this.connection));
multiUserChatItem.getAdmins().remove(contactItem.getLocalpart());
upsertMUC(multiUserChatItem);
this.contactManager.upsert(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onRevokingAdmin(MultiUserChatItem.this, contactItem);
}
});
internalSmackFuture.setResult(Boolean.TRUE);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning("Не удалось удалить пользователя " + contactItem.getFirstName() + " " + contactItem.getLastName() + " из администраторов в группе " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
internalSmackFuture.setResult(Boolean.FALSE);
}
}
public SmackFuture<ContactItem, Exception> createMultiUserChat(final String str, final Set<ContactItem> set, final String str2, final byte[] bArr, final Boolean bool) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$createMultiUserChat$28(set, bool, str, str2, bArr, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$createMultiUserChat$28(Set set, Boolean bool, String str, String str2, byte[] bArr, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
logger.warning(">>>> members.size()" + set.size());
String str3 = "muc_" + RandomStringUtils.random(16, true, true).toLowerCase();
EntityBareJid entityBareFrom = JidCreate.entityBareFrom(str3 + "@conference." + ((Object) connection().getXMPPServiceDomain()));
MultiUserChat multiUserChat = getMultiUserChat(entityBareFrom);
String part = this.connection.getUser().getLocalpartOrThrow().toString();
Resourcepart resourceOrThrow = this.connection.getUser().getResourceOrThrow();
multiUserChat.create(resourceOrThrow);
multiUserChat.join(resourceOrThrow);
FillableForm fillableForm = multiUserChat.getConfigurationForm().getFillableForm();
fillableForm.setAnswer("muc#roomconfig_publicroom", bool.booleanValue());
fillableForm.setAnswer("muc#roomconfig_roomname", str);
fillableForm.setAnswer("muc#roomconfig_persistentroom", true);
fillableForm.setAnswer(MucConfigFormManager.MUC_ROOMCONFIG_MEMBERSONLY, true);
fillableForm.setAnswer("muc#roomconfig_moderatedroom", true);
fillableForm.setAnswer("muc#roomconfig_maxusers", 100);
multiUserChat.sendConfigurationForm(fillableForm);
MultiUserChatItem multiUserChatItem = new MultiUserChatItem();
multiUserChatItem.setRoom(str3);
multiUserChatItem.setName(str);
multiUserChatItem.setIsPublicRoom(bool.booleanValue());
multiUserChatItem.setReason(str2);
multiUserChatItem.getOwners().add(part);
multiUserChatItem.getAdmins().add(part);
multiUserChatItem.setAvailable(true);
ContactItem contactItem = new ContactItem();
contactItem.setFirstName(str);
if (bArr != null) {
contactItem.setAvatar(bArr);
}
contactItem.setLocalpart(str3);
contactItem.setMultiUserChat(true);
setMUCVCard(contactItem);
Collection<? extends ContactItem> linkedList = new LinkedList<>();
LinkedList linkedList2 = new LinkedList();
Iterator it = set.iterator();
while (it.hasNext()) {
ContactItem contactItem2 = (ContactItem) it.next();
if (!part.equals(contactItem2.getLocalpart())) {
try {
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.SET_INVITE_DATE, entityBareFrom.getLocalpart().toString(), contactItem2.getLocalpart()));
if (mUCInfo != null && mUCInfo.getError() == null) {
multiUserChat.invite(contactItem2.getBareJid(this.connection), str2);
linkedList.add(contactItem2);
linkedList2.add(contactItem2.getLocalpart());
PUSHManager.getInstanceFor(this.connection).sendPush(contactItem2.getBareJid(connection()), this.connection.getUser().asEntityBareJid()).onSuccess(new SuccessCallback() {
@Override
public final void onSuccess(Object obj) {
MultiUserChatManager.lambda$createMultiUserChat$26((IQ) obj);
}
}).onError(new ExceptionCallback() {
@Override
public final void processException(Object obj) {
MultiUserChatManager.lambda$createMultiUserChat$27((Exception) obj);
}
});
}
} catch (Exception unused) {
linkedList.remove(contactItem2);
linkedList2.remove(contactItem2.getLocalpart());
}
}
}
multiUserChatItem.getMembers().addAll(linkedList2);
multiUserChatItem.getContactItems().add(this.contactManager.loadContactItem());
multiUserChatItem.getContactItems().addAll(linkedList);
logger.warning(">>>> multiUserChatItem.getContactItems().size()" + multiUserChatItem.getContactItems().size());
contactItem.setMultiUserChatItem(multiUserChatItem);
multiUserChatItem.setContactItem(contactItem);
this.contactManager.upsert(multiUserChatItem.getContactItem());
upsertMUC(multiUserChatItem);
sendInviteUserMessage(multiUserChatItem, linkedList);
internalSmackFuture.setResult(contactItem);
} catch (Exception e) {
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
public static void lambda$createMultiUserChat$26(IQ iq) {
logger.info(">>>>> send push success ");
}
public static void lambda$createMultiUserChat$27(Exception exc) {
logger.warning(">>>>> send push error " + exc.getMessage());
}
public void setMUCVCard(ContactItem contactItem) throws SmackException.NotConnectedException, InterruptedException {
VCard vCard = new VCard();
vCard.setType(IQ.Type.set);
vCard.setFirstName(contactItem.getFirstName());
vCard.setAvatar(contactItem.getAvatar());
vCard.setTo(contactItem.getBareJid(this.connection));
connection().sendStanza(vCard);
}
public SmackFuture<Boolean, Exception> deleteMultiUserChat(final MultiUserChatItem multiUserChatItem) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$deleteMultiUserChat$29(multiUserChatItem, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$deleteMultiUserChat$29(MultiUserChatItem multiUserChatItem, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
EntityBareJid bareJid = multiUserChatItem.getBareJid(this.connection);
getMultiUserChat(bareJid).leave();
BookmarkManager.getBookmarkManager(connection()).removeBookmarkedConference(bareJid);
deleteMuc(multiUserChatItem);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | MultiUserChatException.MucNotJoinedException e) {
logger.warning("Не удалось удалить группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
public SmackFuture<Boolean, Exception> destroyMultiUserChat(final MultiUserChatItem multiUserChatItem, final String str) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$destroyMultiUserChat$30(multiUserChatItem, str, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$destroyMultiUserChat$30(MultiUserChatItem multiUserChatItem, String str, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
EntityBareJid bareJid = multiUserChatItem.getBareJid(this.connection);
getMultiUserChat(bareJid).destroy(str, null);
BookmarkManager.getBookmarkManager(connection()).removeBookmarkedConference(bareJid);
deleteMuc(multiUserChatItem);
} catch (InterruptedException e) {
e = e;
logger.warning("Не удалось удалить группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
} catch (SmackException.NoResponseException e2) {
e = e2;
logger.warning("Не удалось удалить группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
} catch (SmackException.NotConnectedException e3) {
e = e3;
logger.warning("Не удалось удалить группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
} catch (XMPPException.XMPPErrorException e4) {
if (e4.getStanzaError().getCondition().equals(StanzaError.Condition.forbidden)) {
logger.warning("Не удалось удалить группу " + multiUserChatItem.getName() + " " + e4.getMessage());
e4.printStackTrace();
internalSmackFuture.setException(new Exception("Только создатель имеет право удалять групповой чат"));
}
}
}
public void leaveUser(final String str, final Jid jid) {
try {
if (((MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.IS_MEMBER, str, jid.asEntityBareJidIfPossible().toString()))).getIsMember().booleanValue()) {
return;
}
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$leaveUser$32(str, jid, internalSmackFuture);
}
});
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
logger.warning(e.getMessage());
e.printStackTrace();
}
}
public void lambda$leaveUser$32(String str, Jid jid, SmackFuture.InternalSmackFuture internalSmackFuture) {
String str2;
final String str3;
final MultiUserChatItem multiUserChatItem;
String str4 = "";
try {
str3 = "Пользователь покинул группу";
multiUserChatItem = DatabaseManager.getMultiUserChatItem(str);
str2 = multiUserChatItem.getName();
} catch (Exception e) {
e = e;
str2 = "";
}
try {
final ContactItem loadContactItem = this.contactManager.loadContactItem(jid.getLocalpartOrNull().toString());
str4 = loadContactItem.getFirstName() + " " + loadContactItem.getLastName();
final ContactItem loadContactItem2 = this.contactManager.loadContactItem();
multiUserChatItem.getMembers().remove(loadContactItem.getLocalpart());
multiUserChatItem.getContactItems().remove(loadContactItem);
upsertMUC(multiUserChatItem);
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onLeftMultiUserChat(MultiUserChatItem.this, loadContactItem, loadContactItem2, str3);
}
});
internalSmackFuture.setResult(Boolean.TRUE);
} catch (Exception e2) {
e = e2;
logger.warning("Пользователь " + str4 + " не смог покинуть группу " + str2 + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
public SmackFuture<Boolean, Exception> leaveMUC(final MultiUserChatItem multiUserChatItem) {
final SmackFuture.InternalSmackFuture internalSmackFuture = new SmackFuture.InternalSmackFuture();
internalSmackFuture.doAsync(new Runnable() {
@Override
public final void run() {
MultiUserChatManager.this.lambda$leaveMUC$34(multiUserChatItem, internalSmackFuture);
}
});
return internalSmackFuture;
}
public void lambda$leaveMUC$34(final MultiUserChatItem multiUserChatItem, SmackFuture.InternalSmackFuture internalSmackFuture) {
try {
EntityBareJid bareJid = multiUserChatItem.getBareJid(this.connection);
MultiUserChat multiUserChat = getMultiUserChat(bareJid);
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.BAN_USER, bareJid.getLocalpart().toString(), this.connection.getUser().asBareJid().toString()));
if (mUCInfo.getError() != null) {
if (StanzaError.Condition.item_not_found == mUCInfo.getError().getCondition()) {
logger.warning("Групповой чат не найден");
}
if (StanzaError.Condition.forbidden == mUCInfo.getError().getCondition()) {
logger.warning("Вы не являетесь участником группового чата " + bareJid.getLocalpart().toString());
}
throw new IllegalStateException("Неизвестная ошибка");
}
multiUserChat.leave();
BookmarkManager.getBookmarkManager(connection()).removeBookmarkedConference(bareJid);
multiUserChatItem.setAvailable($assertionsDisabled);
multiUserChatItem.getContactItems().remove(this.contactManager.loadContactItem());
multiUserChatItem.getMembers().remove(this.contactManager.loadContactItem().getLocalpart());
multiUserChatItem.getContactItem().setMultiUserChatItem(multiUserChatItem);
upsertMUC(multiUserChatItem);
this.contactManager.upsert(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onLeaveMultiUserChat(MultiUserChatItem.this);
}
});
internalSmackFuture.setResult(null);
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | MultiUserChatException.MucNotJoinedException e) {
logger.warning("Не удалось покинуть группу " + multiUserChatItem.getName() + " " + e.getMessage());
e.printStackTrace();
internalSmackFuture.setException(e);
}
}
private synchronized void upsertMUC(MultiUserChatItem multiUserChatItem) {
if (!this.databaseManager.getMultiUserChatDao().isExist(multiUserChatItem).booleanValue()) {
this.databaseManager.getMultiUserChatDao().create(multiUserChatItem);
} else {
this.databaseManager.getMultiUserChatDao().update(multiUserChatItem);
}
}
private void deleteMuc(final MultiUserChatItem multiUserChatItem) {
this.httpFileUploadManager.deleteFiles(multiUserChatItem.getContactItem());
this.databaseManager.getMultiUserChatDao().remove(multiUserChatItem);
this.databaseManager.getContactsDao().remove(multiUserChatItem.getContactItem());
this.databaseManager.getMessagesDao().deleteAllMessages(multiUserChatItem.getContactItem());
this.mucEventListeners.forEach(new Consumer() {
@Override
public final void accept(Object obj) {
((MUCEventListener) obj).onDeleteMultiUserChat(MultiUserChatItem.this);
}
});
}
public boolean canEditMuc(MultiUserChatItem multiUserChatItem) {
AccountEntity defaultAccount = this.accountManager.getDefaultAccount();
Objects.requireNonNull(defaultAccount);
return multiUserChatItem.getAdmins().contains(defaultAccount.getUsername());
}
public MultiUserChatItem loadMUC(String str) {
return DatabaseManager.getMultiUserChatItem(str);
}
public synchronized MultiUserChatItem loadMUCFromServer(String str, boolean z) {
try {
String part = this.connection.getUser().getLocalpartOrThrow().toString();
MUCInfo mUCInfo = (MUCInfo) connection().sendIqRequestAndWaitForResponse(new MUCInfo(MUCInfo.INSTRUCTION_GET_INFO, str, part));
if (mUCInfo.getError() != null) {
if (StanzaError.Condition.item_not_found == mUCInfo.getError().getCondition()) {
logger.warning("Групповой чат не найден");
return null;
}
if (StanzaError.Condition.forbidden == mUCInfo.getError().getCondition()) {
logger.warning("Вы не являетесь участником группового чата " + str);
return null;
}
throw new IllegalStateException("Неизвестная ошибка");
}
MultiUserChatItem multiUserChatItem = mUCInfo.getMultiUserChatItem();
if (multiUserChatItem == null) {
throw new MultiUserChatException.MUCNotFoundException("Не удалось загрузить групповой чат");
}
if (z && multiUserChatItem.getOwners().contains(part)) {
logger.warning(">>>> User " + part + " is owner. Return");
return null;
}
Iterator<String> it = multiUserChatItem.getOwners().iterator();
while (it.hasNext()) {
String next = it.next();
ContactItem loadContactItem = this.contactManager.loadContactItem(next);
if (loadContactItem == null) {
logger.warning("get contactItem failed. member:" + next);
} else {
multiUserChatItem.getContactItems().add(loadContactItem);
}
}
for (String str2 : multiUserChatItem.getAdmins()) {
ContactItem loadContactItem2 = this.contactManager.loadContactItem(str2);
if (loadContactItem2 == null) {
logger.warning("get contactItem failed. member:" + str2);
} else {
multiUserChatItem.getContactItems().add(loadContactItem2);
}
}
Logger logger2 = logger;
logger2.warning(">>> 2 multiUserChatItem.getMembers().size():" + multiUserChatItem.getMembers().size());
logger2.warning(">>> 2 multiUserChatItem.getMembers():" + multiUserChatItem.getMembers());
for (String str3 : multiUserChatItem.getMembers()) {
ContactItem loadContactItem3 = this.contactManager.loadContactItem(str3);
if (loadContactItem3 == null) {
logger.warning("get contactItem failed. member:" + str3);
} else {
multiUserChatItem.getContactItems().add(loadContactItem3);
}
}
Iterator<String> it2 = multiUserChatItem.getOccupants().iterator();
while (it2.hasNext()) {
String next2 = it2.next();
ContactItem loadContactItem4 = this.contactManager.loadContactItem(next2);
if (loadContactItem4 == null) {
logger.warning("get contactItem failed. member:" + next2);
} else {
multiUserChatItem.getContactItems().add(loadContactItem4);
}
}
Iterator<String> it3 = multiUserChatItem.getOutcasts().iterator();
while (it3.hasNext()) {
String next3 = it3.next();
ContactItem loadContactItem5 = this.contactManager.loadContactItem(next3);
if (loadContactItem5 == null) {
logger.warning("get contactItem failed. member:" + next3);
} else {
multiUserChatItem.getContactItems().remove(loadContactItem5);
}
}
logger.warning(">>> 2 multiUserChatItem.getContactItems().size():" + multiUserChatItem.getContactItems().size());
multiUserChatItem.setAvailable(multiUserChatItem.getContactItems().contains(this.contactManager.loadContactItem(part)));
ContactItem loadContactItemFromServer = this.contactManager.loadContactItemFromServer(str);
loadContactItemFromServer.setMultiUserChatItem(multiUserChatItem);
multiUserChatItem.setContactItem(loadContactItemFromServer);
this.contactManager.upsert(loadContactItemFromServer);
return this.databaseManager.getMultiUserChatDao().upsert(multiUserChatItem);
} catch (Exception e) {
logger.warning("Не удалось загрузить групповой чат с сервера " + e.getMessage());
e.printStackTrace();
return null;
}
}
public void addMUCEventListener(MUCEventListener mUCEventListener) {
this.mucEventListeners.add(mUCEventListener);
}
public void removeMUCEventListener(MUCEventListener mUCEventListener) {
this.mucEventListeners.remove(mUCEventListener);
}
public synchronized MultiUserChat getMultiUserChat(EntityBareJid entityBareJid) {
WeakReference<MultiUserChat> weakReference = this.multiUserChats.get(entityBareJid);
if (weakReference == null) {
return createNewMucAndAddToMap(entityBareJid);
}
MultiUserChat multiUserChat = weakReference.get();
if (multiUserChat != null) {
return multiUserChat;
}
return createNewMucAndAddToMap(entityBareJid);
}
private MultiUserChat createNewMucAndAddToMap(EntityBareJid entityBareJid) {
MultiUserChat multiUserChat = new MultiUserChat(connection(), entityBareJid, this);
this.multiUserChats.put(entityBareJid, new WeakReference<>(multiUserChat));
return multiUserChat;
}
public boolean isServiceEnabled(Jid jid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return this.serviceDiscoveryManager.supportsFeature(jid, "http://jabber.org/protocol/muc");
}
public Set<EntityBareJid> getJoinedRooms() {
return Collections.unmodifiableSet(this.joinedRooms);
}
public List<EntityBareJid> getJoinedRooms(EntityFullJid entityFullJid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
List<DiscoverItems.Item> items = this.serviceDiscoveryManager.discoverItems(entityFullJid, DISCO_NODE).getItems();
ArrayList arrayList = new ArrayList(items.size());
for (DiscoverItems.Item item : items) {
EntityBareJid asEntityBareJidIfPossible = item.getEntityID().asEntityBareJidIfPossible();
if (asEntityBareJidIfPossible == null) {
logger.warning("Not a bare JID: " + ((Object) item.getEntityID()));
} else {
arrayList.add(asEntityBareJidIfPossible);
}
}
return arrayList;
}
public RoomInfo getRoomInfo(EntityBareJid entityBareJid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return new RoomInfo(this.serviceDiscoveryManager.discoverInfo(entityBareJid));
}
public List<DomainBareJid> getMucServiceDomains() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return this.serviceDiscoveryManager.findServices("http://jabber.org/protocol/muc", $assertionsDisabled, $assertionsDisabled);
}
@Deprecated
public List<DomainBareJid> getXMPPServiceDomains() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return getMucServiceDomains();
}
public boolean providesMucService(DomainBareJid domainBareJid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
ExpirationCache<DomainBareJid, Void> expirationCache = KNOWN_MUC_SERVICES;
boolean containsKey = expirationCache.containsKey(domainBareJid);
if (containsKey || !this.serviceDiscoveryManager.supportsFeature(domainBareJid, "http://jabber.org/protocol/muc")) {
return containsKey;
}
expirationCache.put(domainBareJid, null);
return true;
}
public Map<EntityBareJid, HostedRoom> getRoomsHostedBy(DomainBareJid domainBareJid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, MultiUserChatException.NotAMucServiceException {
if (!providesMucService(domainBareJid)) {
throw new MultiUserChatException.NotAMucServiceException(domainBareJid);
}
List<DiscoverItems.Item> items = this.serviceDiscoveryManager.discoverItems(domainBareJid).getItems();
HashMap hashMap = new HashMap(items.size());
Iterator<DiscoverItems.Item> it = items.iterator();
while (it.hasNext()) {
HostedRoom hostedRoom = new HostedRoom(it.next());
}
return hashMap;
}
public void decline(EntityBareJid entityBareJid, EntityBareJid entityBareJid2, String str) throws SmackException.NotConnectedException, InterruptedException {
XMPPConnection connection = connection();
MessageBuilder messageBuilder = (MessageBuilder) connection.getStanzaFactory().buildMessageStanza().to((Jid) entityBareJid);
MUCUser mUCUser = new MUCUser();
mUCUser.setDecline(new MUCUser.Decline(str, entityBareJid2));
messageBuilder.addExtension(mUCUser);
connection.sendStanza(messageBuilder.build());
}
public void addInvitationListener(InvitationListener invitationListener) {
this.invitationsListeners.add(invitationListener);
}
public void removeInvitationListener(InvitationListener invitationListener) {
this.invitationsListeners.remove(invitationListener);
}
public void addJoinedRoom(EntityBareJid entityBareJid) {
this.joinedRooms.add(entityBareJid);
}
public void removeJoinedRoom(EntityBareJid entityBareJid) {
this.joinedRooms.remove(entityBareJid);
}
public void clearListeners() {
this.mucEventListeners.clear();
}
}