Search in sources :

Example 31 with Message

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

the class ConversationFragment method populateContextMenu.

private void populateContextMenu(ContextMenu menu) {
    final Message m = this.selectedMessage;
    final Transferable t = m.getTransferable();
    Message relevantForCorrection = m;
    while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
        relevantForCorrection = relevantForCorrection.next();
    }
    if (m.getType() != Message.TYPE_STATUS) {
        final boolean treatAsFile = m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE && t == null;
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED || m.getEncryption() == Message.ENCRYPTION_PGP;
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem quoteMessage = menu.findItem(R.id.quote_message);
        MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
        MenuItem correctMessage = menu.findItem(R.id.correct_message);
        MenuItem shareWith = menu.findItem(R.id.share_with);
        MenuItem sendAgain = menu.findItem(R.id.send_again);
        MenuItem copyUrl = menu.findItem(R.id.copy_url);
        MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 0);
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
            retryDecryption.setVisible(true);
        }
        if (relevantForCorrection.getType() == Message.TYPE_TEXT && relevantForCorrection.isLastCorrectableMessage() && (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
            correctMessage.setVisible(true);
        }
        if (treatAsFile || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && !m.isFileOrImage()) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost() || m.isGeoUri() || m.isXmppUri() || m.treatAsDownloadable() || (t != null && t instanceof HttpDownloadConnection)) {
            copyUrl.setVisible(true);
        }
        if ((m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED;
        if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
            cancelTransmission.setVisible(true);
        }
        if (treatAsFile) {
            String path = m.getRelativeFilePath();
            Log.d(Config.LOGTAG, "Path = " + path);
            if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null", false))) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
            showErrorMessage.setVisible(true);
        }
    }
}
Also used : TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) Transferable(de.pixart.messenger.entities.Transferable) MenuItem(android.view.MenuItem) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection)

Example 32 with Message

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

the class ConversationFragment method reInit.

private boolean reInit(final Conversation conversation, final boolean hasExtras) {
    if (conversation == null) {
        return false;
    }
    this.conversation = conversation;
    // once we set the conversation all is good and it will automatically do the right thing in onStart()
    if (this.activity == null || this.binding == null) {
        return false;
    }
    Log.d(Config.LOGTAG, "reInit(hasExtras=" + Boolean.toString(hasExtras) + ")");
    if (this.conversation.isRead() && hasExtras) {
        Log.d(Config.LOGTAG, "trimming conversation");
        this.conversation.trim();
    }
    setupIme();
    final boolean scrolledToBottomAndNoPending = this.scrolledToBottom() && pendingScrollState.peek() == null;
    this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName()));
    this.binding.textinput.setKeyboardListener(null);
    this.binding.textinput.setText("");
    this.binding.textinput.append(this.conversation.getNextMessage());
    this.binding.textinput.setKeyboardListener(this);
    messageListAdapter.updatePreferences();
    refresh(false);
    this.conversation.messagesLoaded.set(true);
    Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + Boolean.toString(scrolledToBottomAndNoPending));
    if (hasExtras || scrolledToBottomAndNoPending) {
        synchronized (this.messageList) {
            Log.d(Config.LOGTAG, "jump to first unread message");
            final Message first = conversation.getFirstUnreadMessage();
            final int bottom = Math.max(0, this.messageList.size() - 1);
            final int pos;
            if (first == null) {
                Log.d(Config.LOGTAG, "first unread message was null");
                pos = bottom;
            } else {
                int i = getIndexOf(first.getUuid(), this.messageList);
                pos = i < 0 ? bottom : i;
            }
            this.binding.messagesView.setSelection(pos);
        }
    }
    this.binding.messagesView.setOnTouchListener(new OnSwipeTouchListener(getContext()) {

        @Override
        public void onSwipeRight() {
            Log.d(Config.LOGTAG, "Swipe right detected");
            activity.onBackPressed();
        }
    });
    activity.onConversationRead(this.conversation);
    // TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it
    activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation);
    return true;
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) SuppressLint(android.annotation.SuppressLint)

Example 33 with Message

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

the class MessageGenerator method generateChat.

public MessagePacket generateChat(Message message) {
    MessagePacket packet = preparePacket(message);
    String content;
    if (message.hasFileOnRemoteHost()) {
        Message.FileParams fileParams = message.getFileParams();
        content = fileParams.url.toString();
        packet.addChild("x", Namespace.OOB).addChild("url").setContent(content);
    } else {
        content = message.getBody();
    }
    packet.setBody(content);
    return packet;
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message)

Example 34 with Message

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

the class ConversationFragment method sendImage.

private void sendImage(Conversation conversation, Uri uri) {
    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 35 with Message

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

the class ConversationFragment method searchHistory.

/**
 * Search through history from message basis either ascending or descending
 *
 * @param query           search term
 * @param basis           message to start from. If null, start from last recent message
 * @param ascendingSearch do we want to ascend or descend in our search?
 *                        If this is null, ascend to first match and return.
 * @return match or null
 */
public Message searchHistory(String query, Message basis, Boolean ascendingSearch) {
    int entryIndex;
    Message message;
    lastHistoryMessage = basis;
    if (messageList.size() == 0) {
        return null;
    }
    if (basis == null) {
        entryIndex = messageList.size() - 1;
    } else {
        int in = getIndexOf(basis.getUuid(), messageList);
        entryIndex = (in != -1 ? in : messageList.size() - 1);
    }
    int firstMatchIndex = entryIndex;
    boolean entryIndexWasMatch = true;
    do {
        message = messageList.get(firstMatchIndex);
        if (message.getType() == Message.TYPE_TEXT && messageContainsQuery(message, query)) {
            lastHistoryMessage = message;
            break;
        }
        entryIndexWasMatch = false;
        firstMatchIndex = (messageList.size() + firstMatchIndex - 1) % messageList.size();
    } while (entryIndex != firstMatchIndex);
    if (!entryIndexWasMatch && entryIndex == firstMatchIndex) {
        // No matches
        return null;
    }
    if (ascendingSearch != null) {
        int direction = ascendingSearch ? -1 : 1;
        int nextMatchIndex = firstMatchIndex;
        do {
            nextMatchIndex = (messageList.size() + nextMatchIndex + direction) % messageList.size();
            message = messageList.get(nextMatchIndex);
            if (message.getType() == Message.TYPE_TEXT && messageContainsQuery(message, query)) {
                lastHistoryMessage = message;
                break;
            }
        } while (nextMatchIndex != entryIndex);
    }
    if (lastHistoryMessage != null) {
        int pos = getIndexOf(lastHistoryMessage.getUuid(), messageList);
        setScrollPosition(getScrollPosition(pos, getView()));
        this.binding.messagesView.setSelection(pos);
    }
    return lastHistoryMessage;
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) SuppressLint(android.annotation.SuppressLint)

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