正在查看: Housing v14.7.8 应用的 QBGroupChat.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 QBGroupChat.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.quickblox.chat;
import com.quickblox.chat.QBAbstractChat;
import com.quickblox.chat.errors.QBChatErrorsConstants;
import com.quickblox.chat.exception.QBChatException;
import com.quickblox.chat.listeners.QBIsTypingListener;
import com.quickblox.chat.listeners.QBMessageListener;
import com.quickblox.chat.listeners.QBMessageSentListener;
import com.quickblox.chat.listeners.QBParticipantListener;
import com.quickblox.chat.model.QBChatMarkersExtension;
import com.quickblox.chat.model.QBChatMessage;
import com.quickblox.chat.model.QBPresence;
import com.quickblox.chat.utils.ThreadTaskEx;
import com.quickblox.core.QBEntityCallback;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PresenceListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.DefaultExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.MultiUserChatManager;
import org.jivesoftware.smackx.muc.packet.MUCUser;
@Deprecated
public class QBGroupChat extends QBAbstractChat<QBGroupChat> {
private final Set<QBMessageListener<QBGroupChat>> a = new CopyOnWriteArraySet();
private Set<QBMessageSentListener<QBGroupChat>> b = new CopyOnWriteArraySet();
private final Set<QBIsTypingListener<QBGroupChat>> c = new CopyOnWriteArraySet();
private final Set<QBParticipantListener> d = new CopyOnWriteArraySet();
private QBGroupChatManager e;
private MultiUserChat f;
private String g;
private String h;
public class a extends ThreadTaskEx {
private final QBEntityCallback b;
private final DiscussionHistory c;
public a(DiscussionHistory discussionHistory, QBEntityCallback qBEntityCallback) {
super(null, QBChatService.getInstance().getThreadPoolExecutor());
this.c = discussionHistory;
this.b = qBEntityCallback;
execute();
}
@Override
public void performInAsync() {
try {
QBGroupChat.this.join(this.c);
QBGroupChat.this.notifySuccessResult(this.b);
} catch (SmackException | XMPPException e) {
QBGroupChat.this.notifyFailResult(this.b, e.getMessage() != null ? e.getMessage() : QBChatErrorsConstants.ERROR_ON_JOIN);
}
}
}
public class b implements PresenceListener {
private b() {
}
@Override
public void processPresence(final Presence presence) {
QBChatService.HANDLER.post(new Runnable() {
@Override
public void run() {
Iterator it = QBGroupChat.this.d.iterator();
while (it.hasNext()) {
((QBParticipantListener) it.next()).processPresence(QBGroupChat.this, new QBPresence(presence));
}
}
});
}
}
public class c extends ThreadTaskEx {
private final QBChatMessage b;
private final QBEntityCallback c;
public c(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
super(null, QBChatService.getInstance().getThreadPoolExecutor());
this.b = qBChatMessage;
this.c = qBEntityCallback;
execute();
}
@Override
public void performInAsync() {
QBMessageListener<QBGroupChat> qBMessageListener = new QBMessageListener<QBGroupChat>() {
@Override
public void processError(QBGroupChat qBGroupChat, QBChatException qBChatException, QBChatMessage qBChatMessage) {
c cVar = c.this;
QBGroupChat.this.notifyFailResult(cVar.c, qBChatException.getMessage());
QBGroupChat.this.removeMessageListener(this);
}
@Override
public void processMessage(QBGroupChat qBGroupChat, QBChatMessage qBChatMessage) {
c cVar = c.this;
QBGroupChat.this.notifySuccessResult(cVar.c);
QBGroupChat.this.removeMessageListener(this);
}
};
QBGroupChat.this.addMessageListener(qBMessageListener);
try {
QBGroupChat.this.sendMessageWithoutJoin(this.b);
} catch (SmackException.NotConnectedException e) {
QBGroupChat.this.notifyFailResult(this.c, e.getMessage() != null ? e.getMessage() : QBChatErrorsConstants.ERROR_ON_SEND_MESSAGE);
QBGroupChat.this.removeMessageListener(qBMessageListener);
}
}
}
public QBGroupChat(QBGroupChatManager qBGroupChatManager, String str) {
this.e = qBGroupChatManager;
this.g = str;
this.f = MultiUserChatManager.getInstanceFor(qBGroupChatManager.connection()).getMultiUserChat(str);
this.h = JIDHelper.INSTANCE.dialogIdFromRoomJid(str);
}
public static boolean c(Message message) {
String body = message.getBody();
if (body == null) {
return false;
}
return "Welcome! You created new Multi User Chat Room. Room is locked now. Configure it please!".equals(body) || "Room is now unlocked".equals(body);
}
@Override
public void addIsTypingListener(QBIsTypingListener<QBGroupChat> qBIsTypingListener) {
if (qBIsTypingListener == null) {
return;
}
this.c.add(qBIsTypingListener);
}
@Override
public void addMessageListener(QBMessageListener<QBGroupChat> qBMessageListener) {
if (qBMessageListener == null) {
return;
}
this.a.add(qBMessageListener);
}
@Override
public void addMessageSentListener(QBMessageSentListener<QBGroupChat> qBMessageSentListener) {
if (qBMessageSentListener == null) {
return;
}
this.b.add(qBMessageSentListener);
}
public void addParticipantListener(QBParticipantListener qBParticipantListener) {
if (qBParticipantListener != null) {
this.d.add(qBParticipantListener);
}
}
public void b(Message message) {
String body = message.getBody();
body.equals("Welcome! You created new Multi User Chat Room. Room is locked now. Configure it please!");
body.equals("Room is now unlocked");
}
@Override
public void deliverMessage(QBChatMessage qBChatMessage) throws XMPPException, SmackException.NotConnectedException, IllegalStateException {
if (qBChatMessage.getSenderId() == null) {
throw new IllegalStateException(QBChatErrorsConstants.SENDER_ID_NULL);
}
if (qBChatMessage.getId() == null) {
throw new IllegalStateException(QBChatErrorsConstants.ID_NULL);
}
this.e.b(qBChatMessage);
}
@Override
public String getDialogId() {
return this.h;
}
@Override
public Collection<QBIsTypingListener<QBGroupChat>> getIsTypingListeners() {
return Collections.unmodifiableCollection(this.c);
}
public String getJid() {
return this.g;
}
@Override
public Collection<QBMessageListener<QBGroupChat>> getMessageListeners() {
return Collections.unmodifiableCollection(this.a);
}
@Override
public Collection<QBMessageSentListener<QBGroupChat>> getMessageSentListeners() {
return Collections.unmodifiableCollection(this.b);
}
public Collection<Integer> getOnlineUsers() throws XMPPException {
ArrayList arrayList = new ArrayList();
for (String str : this.f.getOccupants()) {
if (this.f.getOccupantPresence(str).isAvailable()) {
arrayList.add(JIDHelper.INSTANCE.parseRoomOccupant(str));
}
}
return arrayList;
}
public Collection<QBParticipantListener> getParticipantListeners() {
return Collections.unmodifiableCollection(this.d);
}
public boolean isJoined() {
return this.f.isJoined();
}
public synchronized void join(DiscussionHistory discussionHistory) throws XMPPException, SmackException, IllegalStateException {
String user = this.e.connection().getUser();
if (user == null) {
throw new IllegalStateException(QBChatErrorsConstants.NOT_LOGGED_IN);
}
String valueOf = String.valueOf(JIDHelper.INSTANCE.parseUserId(user));
PacketCollector createPacketCollector = this.e.connection().createPacketCollector(new AndFilter(FromMatchesFilter.createFull(this.g + "/" + valueOf), new StanzaTypeFilter(Presence.class)));
this.f.join(valueOf, null, discussionHistory, (long) SmackConfiguration.getDefaultPacketReplyTimeout());
a(createPacketCollector);
this.f.addParticipantListener(new b());
}
public void leave() throws XMPPException, SmackException.NotConnectedException {
this.f.leave();
}
@Override
public void readMessage(QBChatMessage qBChatMessage) throws XMPPException, SmackException.NotConnectedException, IllegalStateException {
if (qBChatMessage.getSenderId() == null) {
throw new IllegalStateException(QBChatErrorsConstants.SENDER_ID_NULL);
}
if (qBChatMessage.getId() == null) {
throw new IllegalStateException(QBChatErrorsConstants.ID_NULL);
}
this.e.a(qBChatMessage);
}
@Override
public void removeIsTypingListener(QBIsTypingListener<QBGroupChat> qBIsTypingListener) {
this.c.remove(qBIsTypingListener);
}
@Override
public void removeMessageListener(QBMessageListener<QBGroupChat> qBMessageListener) {
this.a.remove(qBMessageListener);
}
@Override
public void removeMessageSentListener(QBMessageSentListener<QBGroupChat> qBMessageSentListener) {
this.b.remove(qBMessageSentListener);
}
public void removeParticipantListener(QBParticipantListener qBParticipantListener) {
this.d.remove(qBParticipantListener);
}
public Collection<Integer> requestOnlineUsers() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
ArrayList arrayList = new ArrayList();
Iterator<DiscoverItems.Item> it = ServiceDiscoveryManager.getInstanceFor(this.e.connection()).discoverItems(this.g).getItems().iterator();
while (it.hasNext()) {
arrayList.add(Integer.valueOf(JIDHelper.INSTANCE.parseResource(it.next().getEntityID())));
}
return arrayList;
}
@Override
public void sendIsTypingNotification() throws XMPPException, SmackException.NotConnectedException {
this.e.a(this.g, Message.Type.groupchat, ChatState.composing);
}
@Override
public void sendMessage(QBChatMessage qBChatMessage) throws SmackException.NotConnectedException, IllegalStateException {
if (!isJoined()) {
throw new IllegalStateException(QBChatErrorsConstants.NOT_JOINED_ROOM);
}
this.e.b(qBChatMessage, (QBChatMessage) this);
}
public void sendMessageWithoutJoin(QBChatMessage qBChatMessage) throws SmackException.NotConnectedException, IllegalStateException {
this.e.b(qBChatMessage, (QBChatMessage) this);
}
public void sendPresence(Map<String, String> map) throws XMPPException, SmackException.NotConnectedException, IllegalStateException {
if (!isJoined()) {
throw new IllegalStateException(QBChatErrorsConstants.NOT_JOINED_ROOM);
}
Stanza presence = new Presence(Presence.Type.available);
presence.setTo(JIDHelper.INSTANCE.getRoomJid(this.f.getRoom()) + "/" + QBChatService.getInstance().getUser().getId().intValue());
DefaultExtensionElement defaultExtensionElement = new DefaultExtensionElement("x", Consts.QB_PRESENCE_EXTENSION_NAMESPACE);
for (String str : map.keySet()) {
defaultExtensionElement.setValue(str, map.get(str));
}
presence.addExtension(defaultExtensionElement);
this.e.connection().sendStanza(presence);
}
@Override
public void sendStopTypingNotification() throws XMPPException, SmackException.NotConnectedException {
this.e.a(this.g, Message.Type.groupchat, ChatState.paused);
}
public MultiUserChat a() {
return this.f;
}
@Override
public void deliverMessage(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
new QBAbstractChat.b(false, qBChatMessage, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
}
public void join(DiscussionHistory discussionHistory, QBEntityCallback qBEntityCallback) {
new a(discussionHistory, qBEntityCallback);
}
@Override
public void readMessage(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
new QBAbstractChat.b(true, qBChatMessage, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
}
@Override
public void sendIsTypingNotification(QBEntityCallback<Void> qBEntityCallback) {
new QBAbstractChat.c(true, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
}
@Override
public void sendMessage(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
new QBAbstractChat.a(qBChatMessage, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
}
public void sendMessageWithoutJoin(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
new c(qBChatMessage, qBEntityCallback);
}
@Override
public void sendStopTypingNotification(QBEntityCallback<Void> qBEntityCallback) {
new QBAbstractChat.c(false, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
}
private void a(PacketCollector packetCollector) throws XMPPException, SmackException {
Presence presence = (Presence) packetCollector.nextResultOrThrow();
if (presence != null && a(presence)) {
throw new XMPPException.XMPPErrorException(QBChatErrorsConstants.CHAT_OPERATION_IS_NOT_ALOWED, new XMPPError(XMPPError.Condition.not_allowed));
}
}
@Override
public void sendMessage(String str) throws SmackException.NotConnectedException {
if (!isJoined()) {
throw new IllegalStateException(QBChatErrorsConstants.NOT_JOINED_ROOM);
}
QBChatMessage qBChatMessage = new QBChatMessage();
qBChatMessage.setBody(str);
sendMessage(qBChatMessage);
}
public void a(final Message message) {
if (message.getType() == Message.Type.error) {
QBChatService.HANDLER.post(new Runnable() {
@Override
public void run() {
QBGroupChat qBGroupChat = QBGroupChat.this;
qBGroupChat.notifyMessageListeners(qBGroupChat, message, true);
}
});
return;
}
ChatStateExtension chatStateExtension = (ChatStateExtension) message.getExtension("http://jabber.org/protocol/chatstates");
if (chatStateExtension != null) {
final ChatState valueOf = ChatState.valueOf(chatStateExtension.getElementName());
final Integer parseRoomOccupant = JIDHelper.INSTANCE.parseRoomOccupant(message.getFrom());
QBChatService.HANDLER.post(new Runnable() {
@Override
public void run() {
QBGroupChat qBGroupChat = QBGroupChat.this;
qBGroupChat.notifyTypingListeners(qBGroupChat, valueOf, parseRoomOccupant);
}
});
return;
}
QBChatMarkersExtension qBChatMarkersExtension = (QBChatMarkersExtension) message.getExtension(QBChatMarkersExtension.NAMESPACE);
if (qBChatMarkersExtension != null && qBChatMarkersExtension.getMarker() == QBChatMarkersExtension.ChatMarker.markable) {
JIDHelper jIDHelper = JIDHelper.INSTANCE;
Integer valueOf2 = Integer.valueOf(jIDHelper.parseUserId(message.getTo()));
Integer parseRoomOccupant2 = jIDHelper.parseRoomOccupant(message.getFrom());
Integer id = QBChatService.getInstance().getUser().getId();
if (valueOf2.equals(id) && !parseRoomOccupant2.equals(id) && QBChatService.getInstance().isAutoMarkMessagesDelivered()) {
try {
this.e.d(message);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
}
QBChatService.HANDLER.post(new Runnable() {
@Override
public void run() {
QBGroupChat qBGroupChat = QBGroupChat.this;
qBGroupChat.notifyMessageListeners(qBGroupChat, message, false);
}
});
}
@Override
public void sendMessage(String str, QBEntityCallback<Void> qBEntityCallback) {
QBChatMessage qBChatMessage = new QBChatMessage();
qBChatMessage.setBody(str);
sendMessage(qBChatMessage, qBEntityCallback);
}
private boolean a(Presence presence) {
MUCUser from = MUCUser.from(presence);
return from != null && from.getStatus().contains(MUCUser.Status.ROOM_CREATED_201);
}
}