Search in sources :

Example 1 with ChatSessionAdapter

use of org.awesomeapp.messenger.service.adapters.ChatSessionAdapter in project Zom-Android by zom.

the class ChatSessionManager method createChatSession.

/**
 * Creates a new ChatSession with specified participant.
 *
 * @param participant the participant.
 * @return the created ChatSession.
 */
public ChatSession createChatSession(ImEntity participant, boolean isNewSession) {
    ChatSession session = mSessions.get(participant.getAddress().getBareAddress());
    if (session == null) {
        session = new ChatSession(participant, this);
        ChatSessionAdapter csa = mAdapter.getChatSessionAdapter(session, isNewSession);
        // this is redundant, as the getAdapter() returns the session instance itself
        session.setMessageListener(csa.getAdaptee().getMessageListener());
        mSessions.put(participant.getAddress().getBareAddress(), session);
        for (ChatSessionListener listener : mListeners) {
            listener.onChatSessionCreated(session);
        }
    } else {
        ChatSessionAdapter csa = mAdapter.getChatSessionAdapter(session, isNewSession);
        // this is redundant, as the getAdapter() returns the session instance itself
        session.setMessageListener(csa.getAdaptee().getMessageListener());
    }
    return session;
}
Also used : ChatSessionAdapter(org.awesomeapp.messenger.service.adapters.ChatSessionAdapter)

Example 2 with ChatSessionAdapter

use of org.awesomeapp.messenger.service.adapters.ChatSessionAdapter in project Zom-Android by zom.

the class OtrEngineHostImpl method injectMessage.

public void injectMessage(SessionID sessionID, String text) {
    OtrDebugLogger.log(sessionID.toString() + ": injecting message: " + text);
    ImConnectionAdapter connection = findConnection(sessionID);
    if (connection != null) {
        ChatSessionManagerAdapter chatSessionManagerAdapter = (ChatSessionManagerAdapter) connection.getChatSessionManager();
        ChatSessionAdapter chatSessionAdapter = (ChatSessionAdapter) chatSessionManagerAdapter.getChatSession(sessionID.getRemoteUserId());
        if (chatSessionAdapter != null) {
            String body = text;
            if (body == null)
                // don't allow null messages, only empty ones!
                body = "";
            Message msg = new Message(body);
            Address to = new XmppAddress(sessionID.getRemoteUserId());
            msg.setTo(to);
            if (!to.getAddress().contains("/")) {
                // always send OTR messages to a resource
                msg.setTo(appendSessionResource(sessionID, to));
            }
            boolean verified = mOtrKeyManager.isVerified(sessionID);
            if (verified) {
                msg.setType(Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED);
            } else {
                msg.setType(Imps.MessageType.OUTGOING_ENCRYPTED);
            }
            // msg ID is set by plugin
            chatSessionManagerAdapter.getChatSessionManager().sendMessageAsync(chatSessionAdapter.getAdaptee(), msg);
        } else {
            OtrDebugLogger.log(sessionID.toString() + ": could not find chatSession");
        }
    } else {
        OtrDebugLogger.log(sessionID.toString() + ": could not find ImConnection");
    }
}
Also used : Message(org.awesomeapp.messenger.model.Message) Address(org.awesomeapp.messenger.model.Address) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) ChatSessionAdapter(org.awesomeapp.messenger.service.adapters.ChatSessionAdapter) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) ImConnectionAdapter(org.awesomeapp.messenger.service.adapters.ImConnectionAdapter) ChatSessionManagerAdapter(org.awesomeapp.messenger.service.adapters.ChatSessionManagerAdapter)

Aggregations

ChatSessionAdapter (org.awesomeapp.messenger.service.adapters.ChatSessionAdapter)2 Address (org.awesomeapp.messenger.model.Address)1 Message (org.awesomeapp.messenger.model.Message)1 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)1 ChatSessionManagerAdapter (org.awesomeapp.messenger.service.adapters.ChatSessionManagerAdapter)1 ImConnectionAdapter (org.awesomeapp.messenger.service.adapters.ImConnectionAdapter)1