Search in sources :

Example 16 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress 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)

Example 17 with XmppAddress

use of org.awesomeapp.messenger.plugin.xmpp.XmppAddress in project Zom-Android by zom.

the class ChatSession method sendPushWhitelistTokenAsync.

/**
 * Returns a unmodifiable list of the history messages in this session.
 *
 * @return a unmodifiable list of the history messages in this session.
 */
/**
 *    public List<Message> getHistoryMessages() {
 *        return Collections.unmodifiableList(mHistoryMessages);
 *    }
 */
public void sendPushWhitelistTokenAsync(@NonNull Message message, @NonNull String[] whitelistTokens) {
    OtrChatManager cm = OtrChatManager.getInstance();
    SessionID sId = cm.getSessionId(message.getFrom().getAddress(), mParticipant.getAddress().getAddress());
    SessionStatus otrStatus = cm.getSessionStatus(sId);
    message.setTo(new XmppAddress(sId.getRemoteUserId()));
    if (otrStatus == SessionStatus.ENCRYPTED) {
        boolean verified = cm.getKeyManager().isVerified(sId);
        if (verified) {
            message.setType(Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED);
        } else {
            message.setType(Imps.MessageType.OUTGOING_ENCRYPTED);
        }
        boolean canSend = cm.transformPushWhitelistTokenSending(message, whitelistTokens);
        if (canSend)
            mManager.sendMessageAsync(this, message);
    }
}
Also used : SessionStatus(net.java.otr4j.session.SessionStatus) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) OtrChatManager(org.awesomeapp.messenger.crypto.otr.OtrChatManager) SessionID(net.java.otr4j.session.SessionID)

Aggregations

XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)17 Contact (org.awesomeapp.messenger.model.Contact)10 RemoteException (android.os.RemoteException)8 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)5 Intent (android.content.Intent)4 IChatSession (org.awesomeapp.messenger.service.IChatSession)4 ChatSessionInitTask (org.awesomeapp.messenger.tasks.ChatSessionInitTask)4 ImApp (org.awesomeapp.messenger.ImApp)3 Activity (android.app.Activity)2 DecoderException (org.apache.commons.codec.DecoderException)2 Address (org.awesomeapp.messenger.model.Address)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)2 IImConnection (org.awesomeapp.messenger.service.IImConnection)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 View (android.view.View)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1