~singpolyma/cheogram-android

1a02bcb96ce418793b7a09391d5d423ff8eb4183 — Stephen Paul Weber 1 year, 1 month ago 609f2d5
Allow files/images in replies
M src/main/java/eu/siacs/conversations/generator/MessageGenerator.java => src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +16 -9
@@ 102,18 102,25 @@ public class MessageGenerator extends AbstractGenerator {

    public MessagePacket generateChat(Message message) {
        MessagePacket packet = preparePacket(message);
        String content;
        if (message.hasFileOnRemoteHost()) {
            final Message.FileParams fileParams = message.getFileParams();
            content = fileParams.url;
            packet.addChild("x", Namespace.OOB).addChild("url").setContent(content);
            packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", Namespace.OOB)
                  .addChild("body", "urn:xmpp:fallback:0");
            message.setBody(content);
        } else {
            content = message.getBody();

            if (message.getBody().equals("")) {
                message.setBody(fileParams.url);
                packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", Namespace.OOB)
                      .addChild("body", "urn:xmpp:fallback:0");
            } else {
                long start = message.getQuoteableBody().length();
                message.appendBody(fileParams.url);
                packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", Namespace.OOB)
                      .addChild("body", "urn:xmpp:fallback:0")
                          .setAttribute("start", String.valueOf(start))
                          .setAttribute("end", String.valueOf(start + fileParams.url.length()));
            }

            packet.addChild("x", Namespace.OOB).addChild("url").setContent(fileParams.url);
        }
        packet.setBody(content);
        packet.setBody(message.getQuoteableBody());
        return packet;
    }


M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +15 -6
@@ 616,10 616,14 @@ public class XmppConnectionService extends Service {

    public void attachFileToConversation(final Conversation conversation, final Uri uri, final String type, final UiCallback<Message> callback) {
        final Message message;
        if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
            message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
        } else {
        if (conversation.getReplyTo() == null) {
            message = new Message(conversation, "", conversation.getNextEncryption());
        } else {
            message = conversation.getReplyTo().reply();
            message.setEncryption(conversation.getNextEncryption());
        }
        if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
            message.setEncryption(Message.ENCRYPTION_DECRYPTED);
        }
        message.setThread(conversation.getThread());
        if (!Message.configurePrivateFileMessage(message)) {


@@ 649,10 653,15 @@ public class XmppConnectionService extends Service {
            return;
        }
        final Message message;
        if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
            message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
        } else {

        if (conversation.getReplyTo() == null) {
            message = new Message(conversation, "", conversation.getNextEncryption());
        } else {
            message = conversation.getReplyTo().reply();
            message.setEncryption(conversation.getNextEncryption());
        }
        if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
            message.setEncryption(Message.ENCRYPTION_DECRYPTED);
        }
        message.setThread(conversation.getThread());
        if (!Message.configurePrivateFileMessage(message)) {

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +5 -2
@@ 807,7 807,10 @@ public class ConversationFragment extends XmppFragment

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



@@ 852,6 855,7 @@ public class ConversationFragment extends XmppFragment
                    @Override
                    public void success(Message message) {
                        hidePrepareFileToast(prepareFileToast);
                        runOnUiThread(() -> setupReply(null));
                    }

                    @Override


@@ 1125,7 1129,6 @@ public class ConversationFragment extends XmppFragment
        } else {
            activity.selectPresence(conversation, callback);
        }
        setupReply(null);
    }

    private static boolean anyNeedsExternalStoragePermission(