diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 5b8adb9cf..6c53134aa 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -8,6 +8,7 @@ import android.util.Log; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Longs; import org.json.JSONException; @@ -849,10 +850,10 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable fileParams.height = parseInt(parts[3]); case 2: fileParams.url = URL.tryParse(parts[0]); - fileParams.size = parseLong(parts[1]); + fileParams.size = Longs.tryParse(parts[1]); break; case 3: - fileParams.size = parseLong(parts[0]); + fileParams.size = Longs.tryParse(parts[0]); fileParams.width = parseInt(parts[1]); fileParams.height = parseInt(parts[2]); break; @@ -861,14 +862,6 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable return fileParams; } - private static long parseLong(String value) { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return 0; - } - } - private static int parseInt(String value) { try { return Integer.parseInt(value); @@ -905,10 +898,14 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable public static class FileParams { public String url; - public long size = 0; + public Long size = null; public int width = 0; public int height = 0; public int runtime = 0; + + public long getSize() { + return size == null ? 0 : size; + } } public void setFingerprint(String fingerprint) { diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 09e9121ba..b41962d78 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -83,7 +83,7 @@ public class HttpDownloadConnection implements Transferable { final Message.FileParams fileParams = message.getFileParams(); if (message.hasFileOnRemoteHost()) { mUrl = AesGcmURL.of(fileParams.url); - } else if (message.isOOb() && fileParams.url != null && fileParams.size > 0) { + } else if (message.isOOb() && fileParams.url != null && fileParams.size != null) { mUrl = AesGcmURL.of(fileParams.url); } else { mUrl = AesGcmURL.of(message.getBody().split("\n")[0]); @@ -106,8 +106,8 @@ public class HttpDownloadConnection implements Transferable { this.message.setEncryption(Message.ENCRYPTION_NONE); } //TODO add auth tag size to knownFileSize - final long knownFileSize = message.getFileParams().size; - if (knownFileSize > 0 && interactive) { + final Long knownFileSize = message.getFileParams().size; + if (knownFileSize != null && interactive) { this.file.setExpectedSize(knownFileSize); download(true); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 27858484e..7bbd4c8e5 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1863,7 +1863,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (!message.hasFileOnRemoteHost() && xmppConnection != null && conversation.getMode() == Conversational.MODE_SINGLE - && !xmppConnection.getFeatures().httpUpload(message.getFileParams().size)) { + && !xmppConnection.getFeatures().httpUpload(message.getFileParams().getSize())) { activity.selectPresence(conversation, () -> { message.setCounterpart(conversation.getNextCounterpart()); activity.xmppConnectionService.resendFailedMessages(message); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index caba4ce64..587e834b3 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -184,7 +184,7 @@ public class MessageAdapter extends ArrayAdapter { && message.getMergedStatus() <= Message.STATUS_RECEIVED; if (message.isFileOrImage() || transferable != null || MessageUtils.unInitiatedButKnownSize(message)) { FileParams params = message.getFileParams(); - filesize = params.size > 0 ? UIHelper.filesizeToString(params.size) : null; + filesize = params.size != null ? UIHelper.filesizeToString(params.size) : null; if (transferable != null && (transferable.getStatus() == Transferable.STATUS_FAILED || transferable.getStatus() == Transferable.STATUS_CANCELLED)) { error = true; } diff --git a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java index 9fc6c5ca8..3cb6338db 100644 --- a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java @@ -115,6 +115,6 @@ public class MessageUtils { } 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; + return message.getType() == Message.TYPE_TEXT && message.getTransferable() == null && message.isOOb() && message.getFileParams().size != null && message.getFileParams().url != null; } }