mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-30 08:50:01 +01:00
properly error out if upload fails. fixes #4052
(cherry picked from commit 202bde46ed
)
This commit is contained in:
parent
eed5ad685c
commit
4df5eb1ef9
1 changed files with 15 additions and 11 deletions
|
@ -46,7 +46,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
private boolean delayed = false;
|
private boolean delayed = false;
|
||||||
private DownloadableFile file;
|
private DownloadableFile file;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
private String mime;
|
|
||||||
private SlotRequester.Slot slot;
|
private SlotRequester.Slot slot;
|
||||||
private byte[] key = null;
|
private byte[] key = null;
|
||||||
private int mStatus = Transferable.STATUS_UNKNOWN;
|
private int mStatus = Transferable.STATUS_UNKNOWN;
|
||||||
|
@ -89,11 +88,14 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
final ListenableFuture<SlotRequester.Slot> slotFuture = this.slotFuture;
|
final ListenableFuture<SlotRequester.Slot> slotFuture = this.slotFuture;
|
||||||
if (slotFuture != null && !slotFuture.isDone()) {
|
if (slotFuture != null && !slotFuture.isDone()) {
|
||||||
slotFuture.cancel(true);
|
if (slotFuture.cancel(true)) {
|
||||||
|
Log.d(Config.LOGTAG,"cancelled slot requester");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final Call call = this.mostRecentCall;
|
final Call call = this.mostRecentCall;
|
||||||
if (call != null && !call.isCanceled()) {
|
if (call != null && !call.isCanceled()) {
|
||||||
call.cancel();
|
call.cancel();
|
||||||
|
Log.d(Config.LOGTAG,"cancelled HTTP request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +107,6 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
|
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markAsCancelled() {
|
|
||||||
finish();
|
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, Message.ERROR_MESSAGE_CANCELLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void finish() {
|
private void finish() {
|
||||||
mHttpConnectionManager.finishUploadConnection(this);
|
mHttpConnectionManager.finishUploadConnection(this);
|
||||||
message.setTransferable(null);
|
message.setTransferable(null);
|
||||||
|
@ -118,10 +115,11 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
public void init(boolean delay) {
|
public void init(boolean delay) {
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||||
|
final String mime;
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
this.mime = "application/pgp-encrypted";
|
mime = "application/pgp-encrypted";
|
||||||
} else {
|
} else {
|
||||||
this.mime = this.file.getMimeType();
|
mime = this.file.getMimeType();
|
||||||
}
|
}
|
||||||
final long originalFileSize = file.getSize();
|
final long originalFileSize = file.getSize();
|
||||||
this.delayed = delay;
|
this.delayed = delay;
|
||||||
|
@ -142,7 +140,12 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
FileTransferExecutor.execute(() -> {
|
FileTransferExecutor.execute(() -> {
|
||||||
changeStatus(STATUS_UPLOADING);
|
changeStatus(STATUS_UPLOADING);
|
||||||
HttpUploadConnection.this.slot = result;
|
HttpUploadConnection.this.slot = result;
|
||||||
HttpUploadConnection.this.upload();
|
try {
|
||||||
|
HttpUploadConnection.this.upload();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
changeStatus(STATUS_FAILED);
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +159,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void upload() {
|
private void upload() {
|
||||||
final OkHttpClient client = mHttpConnectionManager.buildHttpClient(
|
final OkHttpClient client = mHttpConnectionManager.buildHttpClient(
|
||||||
slot.put,
|
slot.put,
|
||||||
|
@ -178,7 +182,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||||
final int code = response.code();
|
final int code = response.code();
|
||||||
if (code == 200 || code == 201) {
|
if (code == 200 || code == 201) {
|
||||||
Log.d(Config.LOGTAG, "finished uploading file");
|
Log.d(Config.LOGTAG, "finished uploading file");
|
||||||
|
|
Loading…
Add table
Reference in a new issue