正在查看: Housing v14.7.8 应用的 QBIncomingMessagesManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 QBIncomingMessagesManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.quickblox.chat;
import android.os.Handler;
import com.quickblox.chat.exception.QBChatException;
import com.quickblox.chat.listeners.QBChatDialogMessageListener;
import com.quickblox.chat.model.QBChatMarkersExtension;
import com.quickblox.chat.model.QBChatMessage;
import com.quickblox.chat.utils.MessagesUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension;
public class QBIncomingMessagesManager extends Manager {
private static final Map<XMPPConnection, QBIncomingMessagesManager> INSTANCES = new WeakHashMap();
private Set<QBChatDialogMessageListener> dialogMessageListeners;
public static class a implements StanzaFilter {
private a() {
}
@Override
public boolean accept(Stanza stanza) {
if (!(stanza instanceof Message)) {
return false;
}
Message message = (Message) stanza;
return (!message.getType().equals(Message.Type.error) || MessagesUtils.isSystemNotification(message) || MessagesUtils.isCallNotification(message)) ? false : true;
}
}
public QBIncomingMessagesManager(XMPPConnection xMPPConnection) {
super(xMPPConnection);
this.dialogMessageListeners = new CopyOnWriteArraySet();
xMPPConnection.addSyncStanzaListener(new StanzaListener() {
@Override
public void processPacket(Stanza stanza) {
QBIncomingMessagesManager.this.processIncomingPacket(stanza);
}
}, new OrFilter(MessageTypeFilter.CHAT, MessageTypeFilter.GROUPCHAT, new a()));
INSTANCES.put(xMPPConnection, this);
}
public static synchronized QBIncomingMessagesManager getInstanceFor(XMPPConnection xMPPConnection) {
QBIncomingMessagesManager qBIncomingMessagesManager;
synchronized (QBIncomingMessagesManager.class) {
qBIncomingMessagesManager = INSTANCES.get(xMPPConnection);
if (qBIncomingMessagesManager == null) {
qBIncomingMessagesManager = new QBIncomingMessagesManager(xMPPConnection);
}
}
return qBIncomingMessagesManager;
}
public void processIncomingPacket(Stanza stanza) {
Handler handler;
Runnable runnable;
QBChatMarkersExtension.ChatMarker marker;
final Message message = (Message) stanza;
if (message.getType() == Message.Type.error) {
final QBChatMessage qBChatMessage = new QBChatMessage(message);
handler = QBChatService.HANDLER;
runnable = new Runnable() {
@Override
public void run() {
for (QBChatDialogMessageListener qBChatDialogMessageListener : QBIncomingMessagesManager.this.getDialogMessageListeners()) {
String dialogId = qBChatMessage.getDialogId();
QBChatException qBChatException = new QBChatException(message.getError());
QBChatMessage qBChatMessage2 = qBChatMessage;
qBChatDialogMessageListener.processError(dialogId, qBChatException, qBChatMessage2, qBChatMessage2.getSenderId());
}
}
};
} else {
CarbonExtension carbonExtension = (CarbonExtension) message.getExtension("urn:xmpp:carbons:2");
if (carbonExtension != null && carbonExtension.getDirection() == CarbonExtension.Direction.sent) {
message = (Message) carbonExtension.getForwarded().getForwardedPacket();
}
if (((ChatStateExtension) message.getExtension("http://jabber.org/protocol/chatstates")) != null) {
return;
}
QBChatMarkersExtension qBChatMarkersExtension = (QBChatMarkersExtension) message.getExtension(QBChatMarkersExtension.NAMESPACE);
if (qBChatMarkersExtension != null && ((marker = qBChatMarkersExtension.getMarker()) == QBChatMarkersExtension.ChatMarker.displayed || marker == QBChatMarkersExtension.ChatMarker.received)) {
return;
}
final QBChatMessage qBChatMessage2 = new QBChatMessage(message);
final String dialogId = qBChatMessage2.getDialogId();
handler = QBChatService.HANDLER;
runnable = new Runnable() {
@Override
public void run() {
for (QBChatDialogMessageListener qBChatDialogMessageListener : QBIncomingMessagesManager.this.getDialogMessageListeners()) {
String str = dialogId;
QBChatMessage qBChatMessage3 = qBChatMessage2;
qBChatDialogMessageListener.processMessage(str, qBChatMessage3, qBChatMessage3.getSenderId());
}
}
};
}
handler.post(runnable);
}
public void addDialogMessageListener(QBChatDialogMessageListener qBChatDialogMessageListener) {
if (qBChatDialogMessageListener == null) {
return;
}
this.dialogMessageListeners.add(qBChatDialogMessageListener);
}
public Collection<QBChatDialogMessageListener> getDialogMessageListeners() {
return Collections.unmodifiableCollection(this.dialogMessageListeners);
}
public void removeDialogMessageListrener(QBChatDialogMessageListener qBChatDialogMessageListener) {
this.dialogMessageListeners.remove(qBChatDialogMessageListener);
}
}