Search in sources :

Example 31 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class ConversationActivity method attachFileToConversation.

private void attachFileToConversation(Conversation conversation, Uri uri) {
    if (conversation == null) {
        return;
    }
    final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
    prepareFileToast.show();
    xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() {

        @Override
        public void inform(final String text) {
            hidePrepareFileToast(prepareFileToast);
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    replaceToast(text);
                }
            });
        }

        @Override
        public void success(Message message) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    hideToast();
                }
            });
            hidePrepareFileToast(prepareFileToast);
            xmppConnectionService.sendMessage(message);
        }

        @Override
        public void error(final int errorCode, Message message) {
            hidePrepareFileToast(prepareFileToast);
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    replaceToast(getString(errorCode));
                }
            });
        }

        @Override
        public void userInputRequried(PendingIntent pi, Message message) {
            hidePrepareFileToast(prepareFileToast);
        }
    });
}
Also used : Toast(android.widget.Toast) Message(eu.siacs.conversations.entities.Message) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 32 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class XmppConnectionService method directReply.

private void directReply(Conversation conversation, String body, final boolean dismissAfterReply) {
    Message message = new Message(conversation, body, conversation.getNextEncryption());
    message.markUnread();
    if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        getPgpEngine().encrypt(message, new UiCallback<Message>() {

            @Override
            public void success(Message message) {
                message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                sendMessage(message);
                if (dismissAfterReply) {
                    markRead(message.getConversation(), true);
                } else {
                    mNotificationService.pushFromDirectReply(message);
                }
            }

            @Override
            public void error(int errorCode, Message object) {
            }

            @Override
            public void userInputRequried(PendingIntent pi, Message object) {
            }
        });
    } else {
        sendMessage(message);
        if (dismissAfterReply) {
            markRead(conversation, true);
        } else {
            mNotificationService.pushFromDirectReply(message);
        }
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 33 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class XmppConnectionService method resendFailedMessages.

public void resendFailedMessages(final Message message) {
    final Collection<Message> messages = new ArrayList<>();
    Message current = message;
    while (current.getStatus() == Message.STATUS_SEND_FAILED) {
        messages.add(current);
        if (current.mergeable(current.next())) {
            current = current.next();
        } else {
            break;
        }
    }
    for (final Message msg : messages) {
        msg.setTime(System.currentTimeMillis());
        markMessage(msg, Message.STATUS_WAITING);
        this.resendMessage(msg, false);
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 34 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class XmppConnectionService method attachLocationToConversation.

public void attachLocationToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) {
    int encryption = conversation.getNextEncryption();
    if (encryption == Message.ENCRYPTION_PGP) {
        encryption = Message.ENCRYPTION_DECRYPTED;
    }
    Message message = new Message(conversation, uri.toString(), encryption);
    if (conversation.getNextCounterpart() != null) {
        message.setCounterpart(conversation.getNextCounterpart());
    }
    if (encryption == Message.ENCRYPTION_DECRYPTED) {
        getPgpEngine().encrypt(message, callback);
    } else {
        callback.success(message);
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) SuppressLint(android.annotation.SuppressLint)

Example 35 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class XmppConnectionService method onOtrSessionEstablished.

public void onOtrSessionEstablished(Conversation conversation) {
    final Account account = conversation.getAccount();
    final Session otrSession = conversation.getOtrSession();
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
    conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

        @Override
        public void onMessageFound(Message message) {
            SessionID id = otrSession.getSessionID();
            try {
                message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
            } catch (InvalidJidException e) {
                return;
            }
            if (message.needsUploading()) {
                mJingleConnectionManager.createNewConnection(message);
            } else {
                MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
                if (outPacket != null) {
                    mMessageGenerator.addDelay(outPacket, message.getTimeSent());
                    message.setStatus(Message.STATUS_SEND);
                    databaseBackend.updateMessage(message);
                    sendMessagePacket(account, outPacket);
                }
            }
            updateConversationUi();
        }
    });
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Aggregations

Message (eu.siacs.conversations.entities.Message)39 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)16 Conversation (eu.siacs.conversations.entities.Conversation)12 Account (eu.siacs.conversations.entities.Account)9 Jid (eu.siacs.conversations.xmpp.jid.Jid)7 PendingIntent (android.app.PendingIntent)5 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)5 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)5 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 SpannableString (android.text.SpannableString)4 NotificationCompat (android.support.v4.app.NotificationCompat)3 StyleSpan (android.text.style.StyleSpan)3 View (android.view.View)3 TextView (android.widget.TextView)3 PgpEngine (eu.siacs.conversations.crypto.PgpEngine)3 Contact (eu.siacs.conversations.entities.Contact)3 Element (eu.siacs.conversations.xml.Element)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2