~singpolyma/cheogram-android

0f3181555af9eeb40bea42d7b36ff77e2345ae01 — Daniel Gultsch 2 years ago 76fb018
FileParams indicate unavailable file size as null

since 0 is a valid file size we should use null to indicate absence
M src/main/java/eu/siacs/conversations/entities/Message.java => src/main/java/eu/siacs/conversations/entities/Message.java +8 -11
@@ 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) {

M src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java => src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +3 -3
@@ 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 {

M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +1 -1
@@ 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);

M src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java => src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +1 -1
@@ 184,7 184,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
                && 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;
            }

M src/main/java/eu/siacs/conversations/utils/MessageUtils.java => src/main/java/eu/siacs/conversations/utils/MessageUtils.java +1 -1
@@ 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;
    }
}