导航菜单

页面标题

页面副标题

Housing v14.7.8 - QBPrivateChat.java 源代码

正在查看: Housing v14.7.8 应用的 QBPrivateChat.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.quickblox.chat;

import com.quickblox.chat.QBAbstractChat;
import com.quickblox.chat.errors.QBChatErrorsConstants;
import com.quickblox.chat.listeners.QBIsTypingListener;
import com.quickblox.chat.listeners.QBMessageListener;
import com.quickblox.chat.listeners.QBMessageSentListener;
import com.quickblox.chat.model.QBChatMarkersExtension;
import com.quickblox.chat.model.QBChatMessage;
import com.quickblox.core.QBEntityCallback;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension;

@Deprecated
public class QBPrivateChat extends QBAbstractChat<QBPrivateChat> {
    private final Set<QBMessageListener<QBPrivateChat>> a = new CopyOnWriteArraySet();
    private final Set<QBIsTypingListener<QBPrivateChat>> b = new CopyOnWriteArraySet();
    private Set<QBMessageSentListener<QBPrivateChat>> c = new CopyOnWriteArraySet();
    private QBPrivateChatManager d;
    private int e;
    private String f;

    public QBPrivateChat(QBPrivateChatManager qBPrivateChatManager, int i) {
        this.d = qBPrivateChatManager;
        this.e = i;
    }

    public void a(final Message message) {
        QBChatMessage qBChatMessage = new QBChatMessage(message);
        if (qBChatMessage.getDialogId() != null) {
            this.f = qBChatMessage.getDialogId();
        }
        if (message.getType() == Message.Type.error) {
            QBChatService.HANDLER.post(new Runnable() {
                @Override
                public void run() {
                    QBPrivateChat qBPrivateChat = QBPrivateChat.this;
                    qBPrivateChat.notifyMessageListeners(qBPrivateChat, 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 valueOf2 = Integer.valueOf(JIDHelper.INSTANCE.parseUserId(message.getFrom()));
            QBChatService.HANDLER.post(new Runnable() {
                @Override
                public void run() {
                    QBPrivateChat qBPrivateChat = QBPrivateChat.this;
                    qBPrivateChat.notifyTypingListeners(qBPrivateChat, valueOf, valueOf2);
                }
            });
            return;
        }
        QBChatMarkersExtension qBChatMarkersExtension = (QBChatMarkersExtension) message.getExtension(QBChatMarkersExtension.NAMESPACE);
        if (qBChatMarkersExtension != null) {
            QBChatMarkersExtension.ChatMarker marker = qBChatMarkersExtension.getMarker();
            if (marker == QBChatMarkersExtension.ChatMarker.markable) {
                JIDHelper jIDHelper = JIDHelper.INSTANCE;
                Integer valueOf3 = Integer.valueOf(jIDHelper.parseUserId(message.getTo()));
                Integer valueOf4 = Integer.valueOf(jIDHelper.parseUserId(message.getFrom()));
                Integer id = QBChatService.getInstance().getUser().getId();
                if (valueOf3.equals(id) && !valueOf4.equals(id) && QBChatService.getInstance().isAutoMarkMessagesDelivered()) {
                    try {
                        this.d.c(message);
                    } catch (SmackException.NotConnectedException e) {
                        e.printStackTrace();
                    }
                }
            } else if (marker == QBChatMarkersExtension.ChatMarker.received || marker == QBChatMarkersExtension.ChatMarker.displayed) {
                return;
            }
        }
        CarbonExtension carbonExtension = (CarbonExtension) message.getExtension("urn:xmpp:carbons:2");
        if (carbonExtension != null && carbonExtension.getDirection() == CarbonExtension.Direction.sent) {
            message = (Message) carbonExtension.getForwarded().getForwardedPacket();
        }
        QBChatService.HANDLER.post(new Runnable() {
            @Override
            public void run() {
                QBPrivateChat qBPrivateChat = QBPrivateChat.this;
                qBPrivateChat.notifyMessageListeners(qBPrivateChat, message, false);
            }
        });
    }

    @Override
    public void addIsTypingListener(QBIsTypingListener<QBPrivateChat> qBIsTypingListener) {
        if (qBIsTypingListener == null) {
            return;
        }
        this.b.add(qBIsTypingListener);
    }

    @Override
    public void addMessageListener(QBMessageListener<QBPrivateChat> qBMessageListener) {
        if (qBMessageListener == null) {
            return;
        }
        this.a.add(qBMessageListener);
    }

    @Override
    public void addMessageSentListener(QBMessageSentListener<QBPrivateChat> qBMessageSentListener) {
        if (qBMessageSentListener == null) {
            return;
        }
        this.c.add(qBMessageSentListener);
    }

    public void close() {
        this.d.a(this);
        this.a.clear();
    }

    @Override
    public void deliverMessage(QBChatMessage qBChatMessage) throws XMPPException, SmackException.NotConnectedException, IllegalStateException {
        if (qBChatMessage.getSenderId() == null) {
            qBChatMessage.setSenderId(Integer.valueOf(getParticipant()));
        }
        if (qBChatMessage.getId() == null) {
            throw new IllegalStateException(QBChatErrorsConstants.ID_NULL);
        }
        this.d.b(qBChatMessage);
    }

    public boolean equals(Object obj) {
        return (obj instanceof QBPrivateChat) && this.e == ((QBPrivateChat) obj).getParticipant();
    }

    @Override
    public String getDialogId() {
        return this.f;
    }

    @Override
    public Collection<QBIsTypingListener<QBPrivateChat>> getIsTypingListeners() {
        return Collections.unmodifiableCollection(this.b);
    }

    @Override
    public Collection<QBMessageListener<QBPrivateChat>> getMessageListeners() {
        return Collections.unmodifiableCollection(this.a);
    }

    @Override
    public Collection<QBMessageSentListener<QBPrivateChat>> getMessageSentListeners() {
        return Collections.unmodifiableCollection(this.c);
    }

    public int getParticipant() {
        return this.e;
    }

    @Override
    public void readMessage(QBChatMessage qBChatMessage) throws XMPPException, SmackException.NotConnectedException, IllegalStateException {
        if (qBChatMessage.getSenderId() == null) {
            qBChatMessage.setSenderId(Integer.valueOf(getParticipant()));
        }
        if (qBChatMessage.getId() == null) {
            throw new IllegalStateException(QBChatErrorsConstants.ID_NULL);
        }
        this.d.a(qBChatMessage);
    }

    @Override
    public void removeIsTypingListener(QBIsTypingListener<QBPrivateChat> qBIsTypingListener) {
        this.b.remove(qBIsTypingListener);
    }

    @Override
    public void removeMessageListener(QBMessageListener<QBPrivateChat> qBMessageListener) {
        this.a.remove(qBMessageListener);
    }

    @Override
    public void removeMessageSentListener(QBMessageSentListener<QBPrivateChat> qBMessageSentListener) {
        this.c.remove(qBMessageSentListener);
    }

    @Override
    public void sendIsTypingNotification() throws XMPPException, SmackException.NotConnectedException {
        this.d.a(JIDHelper.INSTANCE.getJid(this.e), Message.Type.chat, ChatState.composing);
    }

    @Override
    public void sendMessage(QBChatMessage qBChatMessage) throws SmackException.NotConnectedException {
        Object property = qBChatMessage.getProperty(Consts.DIALOG_ID);
        if (property == null) {
            property = qBChatMessage.getDialogId();
        }
        if (property != null) {
            this.f = String.valueOf(property);
        }
        this.d.b(qBChatMessage, (QBChatMessage) this);
    }

    @Override
    public void sendStopTypingNotification() throws XMPPException, SmackException.NotConnectedException {
        this.d.a(JIDHelper.INSTANCE.getJid(this.e), Message.Type.chat, ChatState.paused);
    }

    @Override
    public void deliverMessage(QBChatMessage qBChatMessage, QBEntityCallback<Void> qBEntityCallback) {
        new QBAbstractChat.b(false, qBChatMessage, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
    }

    @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());
    }

    @Override
    public void sendStopTypingNotification(QBEntityCallback<Void> qBEntityCallback) {
        new QBAbstractChat.c(false, qBEntityCallback, QBChatService.getInstance().getThreadPoolExecutor());
    }

    @Deprecated
    public void readMessage(String str) throws XMPPException, SmackException.NotConnectedException {
        this.d.a(Integer.valueOf(getParticipant()), str, (String) null);
    }

    @Override
    public void sendMessage(String str) throws SmackException.NotConnectedException {
        QBChatMessage qBChatMessage = new QBChatMessage();
        qBChatMessage.setBody(str);
        sendMessage(qBChatMessage);
    }

    @Override
    public void sendMessage(String str, QBEntityCallback<Void> qBEntityCallback) {
        QBChatMessage qBChatMessage = new QBChatMessage();
        qBChatMessage.setBody(str);
        sendMessage(qBChatMessage, qBEntityCallback);
    }
}