diff options
Diffstat (limited to 'src')
5 files changed, 36 insertions, 35 deletions
diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java index 2155dc3c7..5ed2266ef 100644 --- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java +++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java @@ -136,15 +136,22 @@ public class MessageGenerator extends AbstractGenerator { public MessagePacket generatePgpChat(Message message) { MessagePacket packet = preparePacket(message); - if (Config.supportUnencrypted()) { - packet.setBody(PGP_FALLBACK_MESSAGE); - } - if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { - packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); - } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { - packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody()); + if (message.hasFileOnRemoteHost()) { + final String url = message.getFileParams().url.toString(); + packet.setBody(url); + packet.addChild("x", Namespace.OOB).addChild("url").setContent(url); + } else { + if (Config.supportUnencrypted()) { + packet.setBody(PGP_FALLBACK_MESSAGE); + } + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); + } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { + packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody()); + } + packet.addChild("encryption", "urn:xmpp:eme:0") + .setAttribute("namespace", "jabber:x:encrypted"); } - packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "jabber:x:encrypted"); return packet; } diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 28a4d2469..84478561b 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -1,6 +1,5 @@ package de.pixart.messenger.http; -import android.app.PendingIntent; import android.os.PowerManager; import android.util.Log; import android.util.Pair; @@ -24,7 +23,6 @@ import de.pixart.messenger.parser.IqParser; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.AbstractConnectionManager; import de.pixart.messenger.services.XmppConnectionService; -import de.pixart.messenger.ui.UiCallback; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; @@ -199,27 +197,7 @@ public class HttpUploadConnection implements Transferable { mXmppConnectionService.getFileBackend().updateMediaScanner(file); message.setTransferable(null); message.setCounterpart(message.getConversation().getJid().toBareJid()); - if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { - mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() { - @Override - public void success(Message message) { - mXmppConnectionService.resendMessage(message, delayed); - } - - @Override - public void error(int errorCode, Message object) { - Log.d(Config.LOGTAG, "pgp encryption failed"); - fail("pgp encryption failed"); - } - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - fail("pgp encryption failed"); - } - }); - } else { - mXmppConnectionService.resendMessage(message, delayed); - } + mXmppConnectionService.resendMessage(message, delayed); } else { Log.d(Config.LOGTAG, "http upload failed because response code was " + code); fail("http upload failed because response code was " + code); diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index b621ef79b..90b4254f4 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -414,7 +414,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) { - Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); + final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; if (serverMsgId == null) { serverMsgId = extractStanzaId(packet, isTypeGroupChat, conversation); @@ -471,6 +471,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else if (body == null && oobUrl != null) { message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status); message.setOob(true); + if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) { + message.setEncryption(Message.ENCRYPTION_DECRYPTED); + } } else { message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); } @@ -480,7 +483,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message.setServerMsgId(serverMsgId); message.setCarbon(isCarbon); message.setTime(timestamp); - message.setOob(body != null && body.equals(oobUrl)); + if (body != null && body.equals(oobUrl)) { + message.setOob(true); + if (CryptoHelper.isPgpEncryptedUrl(oobUrl)) { + message.setEncryption(Message.ENCRYPTION_DECRYPTED); + } + } message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); if (conversationMultiMode) { final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); @@ -613,7 +621,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } } else if (!packet.hasChild("body")) { //no body - Conversation conversation = mXmppConnectionService.find(account, from.toBareJid()); + final Conversation conversation = mXmppConnectionService.find(account, from.toBareJid()); if (isTypeGroupChat) { if (packet.hasChild("subject")) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 3075bcb83..6143f382f 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -199,7 +199,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie filesize = params.size / (1024 * 1024) + " MiB"; } else if (params.size >= (1 * 1024)) { filesize = params.size / 1024 + " KiB"; - } else { + } else if (params.size > 0){ filesize = params.size + " B"; } if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) { diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java index b5d3d6c61..06fda4163 100644 --- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java @@ -243,4 +243,12 @@ public final class CryptoHelper { return url; } } + + public static boolean isPgpEncryptedUrl(String url) { + if (url == null) { + return false; + } + final String u = url.toLowerCase(); + return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://")) && u.endsWith(".pgp"); + } } |