From b0780224b5bdd68d74ef514e64e14ce9d37d7b90 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 5 May 2018 20:28:04 +0200 Subject: introduces new message state model --- .../services/filetransfer/FileTransferManager.java | 9 +++++---- .../filetransfer/http/download/AutomaticFileDownload.java | 8 -------- .../services/filetransfer/http/download/HttpRetrieveHead.java | 8 ++++---- .../filetransfer/http/upload/HttpUploadFileTransferEntity.java | 4 ++-- .../filetransfer/http/upload/HttpUploadFileTransferService.java | 3 ++- 5 files changed, 13 insertions(+), 19 deletions(-) (limited to 'src/main/java/de/thedevstack/conversationsplus/services/filetransfer') diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java index 63f1547f..62fed29b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/FileTransferManager.java @@ -9,6 +9,7 @@ import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.enums.MessageStatus; import de.thedevstack.conversationsplus.services.FileTransferService; import de.thedevstack.conversationsplus.services.filetransfer.http.upload.HttpUploadFileTransferEntity; import de.thedevstack.conversationsplus.utils.MessageUtil; @@ -124,9 +125,8 @@ public class FileTransferManager implements FileTransferStatusListener { } } } - if (!retransferStarted) { - entity.getMessage().getFileParams().setFileStatus(FileStatus.UPLOAD_FAILED); - MessageUtil.markMessage(entity.getMessage(), Message.STATUS_SEND_FAILED); + if (!retransferStarted && (entity instanceof HttpUploadFileTransferEntity)) { + MessageUtil.setAndSaveFileStatus(entity.getMessage(), FileStatus.UPLOAD_FAILED); } } } @@ -134,12 +134,13 @@ public class FileTransferManager implements FileTransferStatusListener { @Override public void onCancel(FileTransferEntity entity) { this.activeTransfers.remove(entity.getMessage().getUuid()); - MessageUtil.markMessage(entity.getMessage(), Message.STATUS_SEND_CANCELED); + MessageUtil.setAndSaveMessageStatus(entity.getMessage(), MessageStatus.CANCELED); } @Override public void onSuccess(FileTransferEntity entity) { this.activeTransfers.remove(entity.getMessage().getUuid()); + MessageUtil.setAndSaveMessageStatus(entity.getMessage(), MessageStatus.TRANSMITTED); } private boolean startFileTransfer(Message message, boolean delayed, WeightedTransferService wts) { diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java index 5885e2e1..4401fb06 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/AutomaticFileDownload.java @@ -12,20 +12,12 @@ import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; * */ public class AutomaticFileDownload implements HttpHeadRetrievedListener { - private boolean notify; - - public AutomaticFileDownload(boolean notify) { - this.notify = notify; - } @Override public void onFileSizeRetrieved(long size, Message message) { if (!this.transferFile(message)) { } - if (this.notify) { - XmppConnectionServiceAccessor.xmppConnectionService.getNotificationService().push(message); - } } /** diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java index 1313bcca..62c1af59 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpRetrieveHead.java @@ -10,6 +10,7 @@ import de.thedevstack.conversationsplus.http.Http; import de.thedevstack.conversationsplus.http.HttpClient; import de.thedevstack.conversationsplus.http.HttpHeadRetrievedListener; import de.thedevstack.conversationsplus.persistance.DatabaseBackend; +import de.thedevstack.conversationsplus.utils.MessageParserUtil; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.UiUpdateHelper; import okhttp3.Call; @@ -36,12 +37,11 @@ public class HttpRetrieveHead implements Http, Callback { * If this code is reached and the URL is null something went wrong. * Try again to extract the file parameters from the message. */ - MessageUtil.extractFileParamsFromBody(message); + MessageParserUtil.extractFileParamsFromBody(message); this.url = (null != message.getFileParams()) ? message.getFileParams().getUrl() : null; if (null == this.url) { - message.setTreatAsDownloadable(Message.Decision.NEVER); // TODO find sth better if (null != message.getFileParams()) { - MessageUtil.setAndSaveFileStatus(message, FileStatus.UNDEFINED); + MessageUtil.setAndSaveFileStatus(message, FileStatus.NOT_FOUND); } } } @@ -89,7 +89,7 @@ public class HttpRetrieveHead implements Http, Callback { fileParams.setSize(size); fileParams.setMimeType(contentType); if (0 < size) { - fileParams.setFileStatus(FileStatus.NEEDS_DOWNLOAD); + MessageUtil.setFileStatus(message, FileStatus.NEEDS_DOWNLOAD); } DatabaseBackend.getInstance().updateMessage(message); UiUpdateHelper.updateConversationUi(); diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java index 54186983..19c965e2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferEntity.java @@ -32,7 +32,7 @@ public class HttpUploadFileTransferEntity extends FileTransferEntity { fileParams = new FileParams(); this.getMessage().setFileParams(fileParams); } - fileParams.setFileStatus(FileStatus.NEEDS_UPLOAD); + MessageUtil.setFileStatus(this.getMessage(), FileStatus.NEEDS_DOWNLOAD); if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) { @@ -96,7 +96,7 @@ public class HttpUploadFileTransferEntity extends FileTransferEntity { getUrl = new URL(getUrl.toString() + "#" + CryptoHelper.bytesToHex(this.getKey())); } - this.getMessage().getFileParams().setFileStatus(FileStatus.UPLOADED); + MessageUtil.setFileStatus(getMessage(), FileStatus.UPLOADED); MessageUtil.updateFileParams(this.getMessage(), getUrl); } catch (MalformedURLException e) { Logging.e("httpupload", "Not a valid get url"); diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java index 28bb3a1c..b901ae4b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java @@ -9,6 +9,7 @@ import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.enums.MessageStatus; import de.thedevstack.conversationsplus.services.AbstractConnectionManager; import de.thedevstack.conversationsplus.services.FileTransferService; import de.thedevstack.conversationsplus.services.filetransfer.AbstractFileTransferService; @@ -62,7 +63,7 @@ public class HttpUploadFileTransferService extends AbstractFileTransferService i Logging.d("httpupload", "Requesting upload slot for file upload"); IqPacket request = HttpUploadRequestSlotPacketGenerator.generate(account, message.getContact().getJid(), file.getName(), file.getSize(), file.getMimeType()); XmppSendUtil.sendIqPacket(account, request, new HttpUploadSlotRequestReceived(entity)); - MessageUtil.markMessage(message, Message.STATUS_UNSEND); + MessageUtil.setAndSaveMessageStatus(message, MessageStatus.TRANSMITTING); Logging.d("httpupload", "Upload slot for file upload requested"); started = true; -- cgit v1.2.3