Search in sources :

Example 6 with Message

use of org.awesomeapp.messenger.model.Message in project Zom-Android by zom.

the class OtrDataHandler method sendRequest.

private void sendRequest(Request request) {
    MemorySessionOutputBuffer outBuf = new MemorySessionOutputBuffer();
    HttpMessageWriter writer = new HttpRequestWriter(outBuf, lineFormatter, params);
    HttpMessage req = new BasicHttpRequest(request.method, request.url, PROTOCOL_VERSION);
    String uid = UUID.randomUUID().toString();
    req.addHeader("Request-Id", uid);
    if (request.headers != null) {
        for (Entry<String, String> entry : request.headers.entrySet()) {
            req.addHeader(entry.getKey(), entry.getValue());
        }
    }
    try {
        writer.write(req);
        outBuf.write(request.body);
        outBuf.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (HttpException e) {
        throw new RuntimeException(e);
    }
    byte[] data = outBuf.getOutput();
    Message message = new Message("");
    message.setFrom(request.us);
    message.setTo(request.them);
    if (req.containsHeader("Range"))
        debug("send request " + request.method + " " + request.url + " " + req.getFirstHeader("Range"));
    else
        debug("send request " + request.method + " " + request.url);
    requestCache.put(uid, request);
    mChatSession.sendDataAsync(message, false, data);
}
Also used : HttpMessageWriter(cz.msebera.android.httpclient.io.HttpMessageWriter) HttpMessage(cz.msebera.android.httpclient.HttpMessage) Message(org.awesomeapp.messenger.model.Message) HttpRequestWriter(cz.msebera.android.httpclient.impl.io.HttpRequestWriter) HttpException(cz.msebera.android.httpclient.HttpException) IOException(java.io.IOException) HttpMessage(cz.msebera.android.httpclient.HttpMessage) BasicHttpRequest(cz.msebera.android.httpclient.message.BasicHttpRequest)

Example 7 with Message

use of org.awesomeapp.messenger.model.Message in project Zom-Android by zom.

the class OtrDataHandler method sendResponse.

private void sendResponse(Address us, Address them, int code, String statusString, String uid, byte[] body) {
    MemorySessionOutputBuffer outBuf = new MemorySessionOutputBuffer();
    HttpMessageWriter writer = new HttpResponseWriter(outBuf, lineFormatter, params);
    HttpMessage response = new BasicHttpResponse(new BasicStatusLine(PROTOCOL_VERSION, code, statusString));
    response.addHeader("Request-Id", uid);
    try {
        writer.write(response);
        outBuf.write(body);
        outBuf.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (HttpException e) {
        throw new RuntimeException(e);
    }
    byte[] data = outBuf.getOutput();
    Message message = new Message("");
    message.setFrom(us);
    message.setTo(them);
    debug("send response " + statusString + " for " + uid);
    mChatSession.sendDataAsync(message, true, data);
}
Also used : BasicHttpResponse(cz.msebera.android.httpclient.message.BasicHttpResponse) HttpMessageWriter(cz.msebera.android.httpclient.io.HttpMessageWriter) HttpResponseWriter(cz.msebera.android.httpclient.impl.io.HttpResponseWriter) HttpMessage(cz.msebera.android.httpclient.HttpMessage) Message(org.awesomeapp.messenger.model.Message) HttpException(cz.msebera.android.httpclient.HttpException) IOException(java.io.IOException) HttpMessage(cz.msebera.android.httpclient.HttpMessage) BasicStatusLine(cz.msebera.android.httpclient.message.BasicStatusLine)

Example 8 with Message

use of org.awesomeapp.messenger.model.Message 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 9 with Message

use of org.awesomeapp.messenger.model.Message in project Zom-Android by zom.

the class LoopbackConnection method getChatSessionManager.

@Override
public ChatSessionManager getChatSessionManager() {
    return new ChatSessionManager() {

        @Override
        public void sendMessageAsync(ChatSession session, Message message) {
            // Echo
            Message rec = new Message(message.getBody());
            rec.setFrom(message.getTo());
            rec.setDateTime(new Date());
            session.onReceiveMessage(rec, true);
        }

        @Override
        public boolean resourceSupportsOmemo(Jid jid) {
            return false;
        }
    };
}
Also used : Message(org.awesomeapp.messenger.model.Message) Jid(org.jxmpp.jid.Jid) ChatSessionManager(org.awesomeapp.messenger.model.ChatSessionManager) ChatSession(org.awesomeapp.messenger.model.ChatSession) Date(java.util.Date)

Aggregations

Message (org.awesomeapp.messenger.model.Message)9 IOException (java.io.IOException)4 ChatSession (org.awesomeapp.messenger.model.ChatSession)3 RemoteException (android.os.RemoteException)2 HttpException (cz.msebera.android.httpclient.HttpException)2 HttpMessage (cz.msebera.android.httpclient.HttpMessage)2 HttpMessageWriter (cz.msebera.android.httpclient.io.HttpMessageWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateException (java.security.cert.CertificateException)2 Date (java.util.Date)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ImException (org.awesomeapp.messenger.model.ImException)2 IChatSession (org.awesomeapp.messenger.service.IChatSession)2 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)2 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)2