show cancelled instead of delivery failed if user requested to abort transfer

This commit is contained in:
Daniel Gultsch 2018-10-07 14:59:08 +02:00
parent 284861de65
commit de0741bdf7
4 changed files with 13 additions and 9 deletions

View file

@ -73,6 +73,8 @@ public class Message extends AbstractEntity {
public static final String MARKABLE = "markable";
public static final String ME_COMMAND = "/me ";
public static final String ERROR_MESSAGE_CANCELLED = "eu.siacs.conversations.cancelled";
public boolean markable = false;
protected String conversationUuid;

View file

@ -2,11 +2,8 @@ package eu.siacs.conversations.http;
import android.os.PowerManager;
import android.util.Log;
import android.util.Pair;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
@ -43,7 +40,7 @@ public class HttpUploadConnection implements Transferable {
private final SlotRequester mSlotRequester;
private final Method method;
private final boolean mUseTor;
private boolean canceled = false;
private boolean cancelled = false;
private boolean delayed = false;
private DownloadableFile file;
private Message message;
@ -86,13 +83,13 @@ public class HttpUploadConnection implements Transferable {
@Override
public void cancel() {
this.canceled = true;
this.cancelled = true;
}
private void fail(String errorMessage) {
mHttpConnectionManager.finishUploadConnection(this);
message.setTransferable(null);
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, errorMessage);
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
}
public void init(Message message, boolean delay) {
@ -132,7 +129,7 @@ public class HttpUploadConnection implements Transferable {
this.mSlotRequester.request(method, account, file, mime, md5, new SlotRequester.OnSlotRequested() {
@Override
public void success(SlotRequester.Slot slot) {
if (!canceled) {
if (!cancelled) {
HttpUploadConnection.this.slot = slot;
new Thread(HttpUploadConnection.this::upload).start();
}
@ -185,7 +182,7 @@ public class HttpUploadConnection implements Transferable {
transmitted = 0;
int count;
byte[] buffer = new byte[4096];
while (((count = innerInputStream.read(buffer)) != -1) && !canceled) {
while (((count = innerInputStream.read(buffer)) != -1) && !cancelled) {
transmitted += count;
os.write(buffer, 0, count);
mHttpConnectionManager.updateConversationUi(false);

View file

@ -255,7 +255,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
break;
case Message.STATUS_SEND_FAILED:
info = getContext().getString(R.string.send_failed);
if (Message.ERROR_MESSAGE_CANCELLED.equals(message.getErrorMessage())) {
info = getContext().getString(R.string.cancelled);
} else {
info = getContext().getString(R.string.send_failed);
}
error = true;
break;
default:

View file

@ -744,4 +744,5 @@
<string name="pref_video_compression_summary">Lower quality means smaller files</string>
<string name="video_360p">Medium (360p)</string>
<string name="video_720p">High (720p)</string>
<string name="cancelled">cancelled</string>
</resources>