FileParams indicate unavailable file size as null

since 0 is a valid file size we should use null to indicate absence
This commit is contained in:
Daniel Gultsch 2021-05-16 15:32:53 +02:00
parent 76fb0180d6
commit 0f3181555a
5 changed files with 14 additions and 17 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}
}