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:
parent
76fb0180d6
commit
0f3181555a
|
@ -8,6 +8,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
@ -849,10 +850,10 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
fileParams.height = parseInt(parts[3]);
|
fileParams.height = parseInt(parts[3]);
|
||||||
case 2:
|
case 2:
|
||||||
fileParams.url = URL.tryParse(parts[0]);
|
fileParams.url = URL.tryParse(parts[0]);
|
||||||
fileParams.size = parseLong(parts[1]);
|
fileParams.size = Longs.tryParse(parts[1]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
fileParams.size = parseLong(parts[0]);
|
fileParams.size = Longs.tryParse(parts[0]);
|
||||||
fileParams.width = parseInt(parts[1]);
|
fileParams.width = parseInt(parts[1]);
|
||||||
fileParams.height = parseInt(parts[2]);
|
fileParams.height = parseInt(parts[2]);
|
||||||
break;
|
break;
|
||||||
|
@ -861,14 +862,6 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
return fileParams;
|
return fileParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long parseLong(String value) {
|
|
||||||
try {
|
|
||||||
return Long.parseLong(value);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int parseInt(String value) {
|
private static int parseInt(String value) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
|
@ -905,10 +898,14 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
|
|
||||||
public static class FileParams {
|
public static class FileParams {
|
||||||
public String url;
|
public String url;
|
||||||
public long size = 0;
|
public Long size = null;
|
||||||
public int width = 0;
|
public int width = 0;
|
||||||
public int height = 0;
|
public int height = 0;
|
||||||
public int runtime = 0;
|
public int runtime = 0;
|
||||||
|
|
||||||
|
public long getSize() {
|
||||||
|
return size == null ? 0 : size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFingerprint(String fingerprint) {
|
public void setFingerprint(String fingerprint) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
final Message.FileParams fileParams = message.getFileParams();
|
final Message.FileParams fileParams = message.getFileParams();
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
mUrl = AesGcmURL.of(fileParams.url);
|
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);
|
mUrl = AesGcmURL.of(fileParams.url);
|
||||||
} else {
|
} else {
|
||||||
mUrl = AesGcmURL.of(message.getBody().split("\n")[0]);
|
mUrl = AesGcmURL.of(message.getBody().split("\n")[0]);
|
||||||
|
@ -106,8 +106,8 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
}
|
}
|
||||||
//TODO add auth tag size to knownFileSize
|
//TODO add auth tag size to knownFileSize
|
||||||
final long knownFileSize = message.getFileParams().size;
|
final Long knownFileSize = message.getFileParams().size;
|
||||||
if (knownFileSize > 0 && interactive) {
|
if (knownFileSize != null && interactive) {
|
||||||
this.file.setExpectedSize(knownFileSize);
|
this.file.setExpectedSize(knownFileSize);
|
||||||
download(true);
|
download(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1863,7 +1863,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
if (!message.hasFileOnRemoteHost()
|
if (!message.hasFileOnRemoteHost()
|
||||||
&& xmppConnection != null
|
&& xmppConnection != null
|
||||||
&& conversation.getMode() == Conversational.MODE_SINGLE
|
&& conversation.getMode() == Conversational.MODE_SINGLE
|
||||||
&& !xmppConnection.getFeatures().httpUpload(message.getFileParams().size)) {
|
&& !xmppConnection.getFeatures().httpUpload(message.getFileParams().getSize())) {
|
||||||
activity.selectPresence(conversation, () -> {
|
activity.selectPresence(conversation, () -> {
|
||||||
message.setCounterpart(conversation.getNextCounterpart());
|
message.setCounterpart(conversation.getNextCounterpart());
|
||||||
activity.xmppConnectionService.resendFailedMessages(message);
|
activity.xmppConnectionService.resendFailedMessages(message);
|
||||||
|
|
|
@ -184,7 +184,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
||||||
if (message.isFileOrImage() || transferable != null || MessageUtils.unInitiatedButKnownSize(message)) {
|
if (message.isFileOrImage() || transferable != null || MessageUtils.unInitiatedButKnownSize(message)) {
|
||||||
FileParams params = message.getFileParams();
|
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)) {
|
if (transferable != null && (transferable.getStatus() == Transferable.STATUS_FAILED || transferable.getStatus() == Transferable.STATUS_CANCELLED)) {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,6 @@ public class MessageUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean unInitiatedButKnownSize(Message message) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue