diff options
Diffstat (limited to 'src/main/java/de')
7 files changed, 43 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 94da0f6aa..7d3334bba 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -460,7 +460,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } boolean remoteMsgIdMatchInEdit(String id) { - for(Edit edit : this.edits) { + for (Edit edit : this.edits) { if (id.equals(edit.getEditedId())) { return true; } @@ -679,6 +679,10 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } } + public boolean isOOb() { + return oob; + } + public static class MergeSeparator { } diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index ae53f580e..4e1aa199a 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -79,8 +79,11 @@ public class HttpDownloadConnection implements Transferable { public void init(boolean interactive) { this.message.setTransferable(this); try { + final Message.FileParams fileParams = message.getFileParams(); if (message.hasFileOnRemoteHost()) { - mUrl = CryptoHelper.toHttpsUrl(message.getFileParams().url); + mUrl = CryptoHelper.toHttpsUrl(fileParams.url); + } else if (message.isOOb() && fileParams.url != null && fileParams.size > 0) { + mUrl = fileParams.url; } else { mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody().split("\n")[0])); } @@ -150,7 +153,7 @@ public class HttpDownloadConnection implements Transferable { mHttpConnectionManager.updateConversationUi(true); } - private void decryptOmemoFile() throws Exception { + private void decryptOmemoFile() { final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true); if (outputFile.getParentFile().mkdirs()) { @@ -182,9 +185,6 @@ public class HttpDownloadConnection implements Transferable { } private void finish() throws Exception { - if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { - decryptOmemoFile(); - } message.setTransferable(null); mHttpConnectionManager.finishConnection(this); boolean notify = acceptedAutomatically && !message.isRead(); @@ -200,6 +200,12 @@ public class HttpDownloadConnection implements Transferable { }); } + private void decryptIfNeeded() { + if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { + decryptOmemoFile(); + } + } + private void changeStatus(int status) { this.mStatus = status; mHttpConnectionManager.updateConversationUi(true); @@ -306,10 +312,10 @@ public class HttpDownloadConnection implements Transferable { retrieveFailed(e); return; } - //TODO at this stage we probably also want to persist the file size in the body of the - // message via a similar mechansim as updateFileParams() - essentially body needs to read - // "url|filesize" - // afterwards a file that failed to download mid way will not display 'check file size' anymore + final Message.FileParams fileParams = message.getFileParams(); + FileBackend.updateFileParams(message, fileParams.url, size); + message.setOob(true); + mXmppConnectionService.databaseBackend.updateMessage(message, true); file.setExpectedSize(size); message.resetFileParams(); if (mHttpConnectionManager.hasStoragePermission() @@ -396,8 +402,9 @@ public class HttpDownloadConnection implements Transferable { try { changeStatus(STATUS_DOWNLOADING); download(); - finish(); + decryptIfNeeded(); updateImageBounds(); + finish(); } catch (SSLHandshakeException e) { changeStatus(STATUS_OFFER); } catch (Exception e) { diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index a074eca4f..c6d6448af 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -49,7 +49,6 @@ import java.net.URL; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.acl.LastOwnerException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -1167,6 +1166,12 @@ public class FileBackend { message.setType(privateMessage ? Message.TYPE_PRIVATE_FILE : (image ? Message.TYPE_IMAGE : Message.TYPE_FILE)); } + public static void updateFileParams(Message message, URL url, long size) { + final StringBuilder body = new StringBuilder(); + body.append(url.toString()).append('|').append(size); + message.setBody(body.toString()); + } + private int getMediaRuntime(File file) { try { MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index ed52a8e17..b0d985f63 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1688,8 +1688,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Log.d(Config.LOGTAG, "type: " + transferable.getClass().getName()); Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT).show(); } - } else if (message.treatAsDownloadable() || message.hasFileOnRemoteHost()) { + } else if (message.treatAsDownloadable() || message.hasFileOnRemoteHost() || MessageUtils.unInitiatedButKnownSize(message)) { createNewConnection(message); + } else { + Log.d(Config.LOGTAG, message.getConversation().getAccount() + ": unable to start downloadable"); } } 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 96e5b5b5e..d6f04f718 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -81,6 +81,7 @@ import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.EmojiWrapper; import de.pixart.messenger.utils.Emoticons; import de.pixart.messenger.utils.GeoHelper; +import de.pixart.messenger.utils.MessageUtils; import de.pixart.messenger.utils.RichPreview; import de.pixart.messenger.utils.StylingHelper; import de.pixart.messenger.utils.UIHelper; @@ -234,7 +235,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie final Transferable transferable = message.getTransferable(); boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getMergedStatus() <= Message.STATUS_RECEIVED; - if (message.isFileOrImage() || transferable != null) { + if (message.isFileOrImage() || transferable != null || MessageUtils.unInitiatedButKnownSize(message)) { FileParams params = message.getFileParams(); filesize = params.size > 0 ? UIHelper.filesizeToString(params.size) : null; if (transferable != null && (transferable.getStatus() == Transferable.STATUS_FAILED || transferable.getStatus() == Transferable.STATUS_CANCELLED)) { @@ -1072,8 +1073,9 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie }); final Transferable transferable = message.getTransferable(); - if (message.isFileDeleted() || (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING)) { - if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER) { + final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(message); + if (unInitiatedButKnownSize || message.isFileDeleted() || (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING)) { + if (unInitiatedButKnownSize || transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER) { displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)), darkBackground); } else if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) { displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)), darkBackground); diff --git a/src/main/java/de/pixart/messenger/utils/MessageUtils.java b/src/main/java/de/pixart/messenger/utils/MessageUtils.java index 4ad0e84a5..72e47578e 100644 --- a/src/main/java/de/pixart/messenger/utils/MessageUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MessageUtils.java @@ -41,6 +41,7 @@ public class MessageUtils { private static final Pattern LTR_RTL = Pattern.compile("(\\u200E[^\\u200F]*\\u200F){3,}"); private static final String EMPTY_STRING = ""; + public static String prepareQuote(Message message) { final StringBuilder builder = new StringBuilder(); final String body = message.getMergedBody().toString(); @@ -89,4 +90,8 @@ public class MessageUtils { public static String filterLtrRtl(String body) { return LTR_RTL.matcher(body).replaceFirst(EMPTY_STRING); } + + public static boolean unInitiatedButKnownSize(Message message) { + return message.getType() == Message.TYPE_TEXT && message.getTransferable() == null && message.isOOb() && message.getFileParams().size > 0 && message.getFileParams().url != null; + } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index dcbe51b53..c74b34d41 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -307,7 +307,7 @@ public class UIHelper { return new Pair<>(context.getString(R.string.location), true); } else if (message.isXmppUri()) { return new Pair<>(context.getString(R.string.contact), true); - } else if (message.treatAsDownloadable()) { + } else if (message.treatAsDownloadable() || MessageUtils.unInitiatedButKnownSize(message)) { return new Pair<>(context.getString(R.string.x_file_offered_for_download, getFileDescriptionString(context, message)), true); } else { @@ -520,7 +520,7 @@ public class UIHelper { final Account account = conversation.getAccount(); final Jid jid = account.getJid(); final String displayName = account.getDisplayName(); - if (displayName != null ) { + if (displayName != null) { return displayName; } else { if (jid.getLocal() != null) { |