Search in sources :

Example 36 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method attachFileToConversation.

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

        @Override
        public void inform(final String text) {
            hidePrepareFileToast(prepareFileToast);
            runOnUiThread(() -> activity.replaceToast(text));
        }

        @Override
        public void success(Message message) {
            runOnUiThread(() -> activity.hideToast());
            hidePrepareFileToast(prepareFileToast);
        }

        @Override
        public void error(final int errorCode, Message message) {
            hidePrepareFileToast(prepareFileToast);
            runOnUiThread(() -> activity.replaceToast(getString(errorCode)));
        }

        @Override
        public void userInputRequried(PendingIntent pi, Message message) {
            hidePrepareFileToast(prepareFileToast);
        }
    });
}
Also used : Toast(android.widget.Toast) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 37 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method attachImagesToConversation.

private void attachImagesToConversation(Conversation conversation, Uri uri) {
    if (conversation == null) {
        return;
    }
    final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
    prepareFileToast.show();
    activity.delegateUriPermissionsToService(uri);
    activity.xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback<Message>() {

        @Override
        public void userInputRequried(PendingIntent pi, Message object) {
            hidePrepareFileToast(prepareFileToast);
        }

        @Override
        public void success(Message message) {
            hidePrepareFileToast(prepareFileToast);
        }

        @Override
        public void error(final int error, Message message) {
            hidePrepareFileToast(prepareFileToast);
            activity.runOnUiThread(() -> activity.replaceToast(getString(error)));
        }
    });
}
Also used : Toast(android.widget.Toast) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 38 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method sendMessage.

private void sendMessage() {
    final String body = binding.textinput.getText().toString();
    final Conversation conversation = this.conversation;
    if (body.length() == 0 || conversation == null) {
        return;
    }
    final Message message;
    if (conversation.getCorrectingMessage() == null) {
        message = new Message(conversation, body, conversation.getNextEncryption());
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            final Jid nextCounterpart = conversation.getNextCounterpart();
            if (nextCounterpart != null) {
                message.setCounterpart(nextCounterpart);
                message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart));
                message.setType(Message.TYPE_PRIVATE);
            }
        }
    } else {
        message = conversation.getCorrectingMessage();
        message.setBody(body);
        message.setEdited(message.getUuid());
        message.setUuid(UUID.randomUUID().toString());
    }
    switch(message.getConversation().getNextEncryption()) {
        case Message.ENCRYPTION_OTR:
            sendOtrMessage(message);
            break;
        case Message.ENCRYPTION_PGP:
            sendPgpMessage(message);
            break;
        case Message.ENCRYPTION_AXOLOTL:
            if (!trustKeysIfNeeded(REQUEST_TRUST_KEYS_TEXT)) {
                sendAxolotlMessage(message);
            }
            break;
        default:
            sendPlainTextMessage(message);
    }
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) Jid(de.pixart.messenger.xmpp.jid.Jid) Conversation(de.pixart.messenger.entities.Conversation)

Example 39 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class ExportLogsService method writeToFile.

private void writeToFile(Conversation conversation) {
    Jid accountJid = resolveAccountUuid(conversation.getAccountUuid());
    Jid contactJid = conversation.getJid();
    File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.toBareJid().toString()));
    dir.mkdirs();
    BufferedWriter bw = null;
    try {
        for (Message message : mDatabaseBackend.getMessagesIterable(conversation)) {
            if (message == null)
                continue;
            if (message.getType() == Message.TYPE_TEXT || message.hasFileOnRemoteHost()) {
                String date = simpleDateFormat.format(new Date(message.getTimeSent()));
                if (bw == null) {
                    bw = new BufferedWriter(new FileWriter(new File(dir, contactJid.toBareJid().toString() + ".txt")));
                }
                String jid = null;
                switch(message.getStatus()) {
                    case Message.STATUS_RECEIVED:
                        jid = getMessageCounterpart(message);
                        break;
                    case Message.STATUS_SEND:
                    case Message.STATUS_SEND_RECEIVED:
                    case Message.STATUS_SEND_DISPLAYED:
                        jid = accountJid.toBareJid().toString();
                        break;
                }
                if (jid != null) {
                    String body = message.hasFileOnRemoteHost() ? message.getFileParams().url.toString() : message.getBody();
                    bw.write(String.format(MESSAGE_STRING_FORMAT, date, jid, body.replace("\\\n", "\\ \n").replace("\n", "\\ \n")));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bw != null) {
                bw.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Message(de.pixart.messenger.entities.Message) FileWriter(java.io.FileWriter) IOException(java.io.IOException) EncryptDecryptFile(de.pixart.messenger.utils.EncryptDecryptFile) File(java.io.File) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 40 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class AudioPlayer method resetPlayerUi.

private void resetPlayerUi(RelativeLayout audioPlayer) {
    if (audioPlayer == null) {
        return;
    }
    final ViewHolder viewHolder = ViewHolder.get(audioPlayer);
    final Message message = (Message) audioPlayer.getTag();
    viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp);
    if (message != null) {
        viewHolder.runtime.setText(formatTime(message.getFileParams().runtime));
    }
    viewHolder.progress.setProgress(0);
    viewHolder.progress.setEnabled(false);
}
Also used : Message(de.pixart.messenger.entities.Message)

Aggregations

Message (de.pixart.messenger.entities.Message)47 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)16 Conversation (de.pixart.messenger.entities.Conversation)13 EditMessage (de.pixart.messenger.ui.widget.EditMessage)12 SuppressLint (android.annotation.SuppressLint)11 PendingIntent (android.app.PendingIntent)7 SpannableString (android.text.SpannableString)7 Account (de.pixart.messenger.entities.Account)7 Jid (de.pixart.messenger.xmpp.jid.Jid)7 ArrayList (java.util.ArrayList)5 Uri (android.net.Uri)4 Toast (android.widget.Toast)4 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 StyleSpan (android.text.style.StyleSpan)3 RelativeLayout (android.widget.RelativeLayout)3 Element (de.pixart.messenger.xml.Element)3 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)3 Date (java.util.Date)3 SharedPreferences (android.content.SharedPreferences)2 PackageManager (android.content.pm.PackageManager)2