aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/services
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-09-29 11:57:16 +0200
committersteckbrief <steckbrief@chefmail.de>2016-09-29 11:57:16 +0200
commit34fcdda53fa8ae1174909b62860534d2d874eb72 (patch)
tree50564c1d946ef1779567c67ad25a646b446a6403 /src/main/java/de/thedevstack/conversationsplus/services
parent297bed106efdfa619d700ae44ce047d7f2663c93 (diff)
Implements FS#235: Deletion of remote files uploaded via httpupload
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/services')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFile.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java11
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java18
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java11
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java1
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadFileTransferService.java3
8 files changed, 37 insertions, 16 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java b/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
index 18930d1c..0dcfa05e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/ExportLogsService.java
@@ -103,7 +103,7 @@ public class ExportLogsService extends Service {
break;
}
if (jid != null) {
- String body = message.hasFileOnRemoteHost() ? message.getFileParams().url.toString() : message.getBody();
+ String body = message.hasFileOnRemoteHost() ? message.getFileParams().getUrl() : message.getBody();
bw.write(String.format(MESSAGE_STRING_FORMAT, date, jid,
body.replace("\\\n", "\\ \n").replace("\n", "\\ \n")));
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
index a3142df4..f4388b21 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java
@@ -356,7 +356,8 @@ public class NotificationService {
if (message.getType() != Message.TYPE_TEXT
&& message.getTransferable() == null
&& message.getEncryption() != Message.ENCRYPTION_PGP
- && message.getFileParams().height > 0) {
+ && message.getFileParams() != null
+ && message.getFileParams().getHeight() > 0) { // TODO Use FileParams.getMimeType()
return message;
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFile.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFile.java
index 39a369ef..1549388e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFile.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFile.java
@@ -3,10 +3,10 @@ package de.thedevstack.conversationsplus.services.filetransfer.http.delete;
import android.support.annotation.NonNull;
import de.thedevstack.conversationsplus.entities.Message;
-import de.thedevstack.conversationsplus.entities.RemoteFile;
+import de.thedevstack.conversationsplus.dto.RemoteFile;
/**
- * Created by steckbrief on 22.08.2016.
+ *
*/
public class DeleteRemoteFile extends RemoteFile {
private final Message message;
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
index 2b26fd85..eb9f1b04 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
@@ -1,8 +1,13 @@
package de.thedevstack.conversationsplus.services.filetransfer.http.delete;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.enums.FileStatus;
+import de.thedevstack.conversationsplus.persistance.DatabaseBackend;
import de.thedevstack.conversationsplus.ui.listeners.SimpleUserDecisionCallback;
+import de.thedevstack.conversationsplus.utils.MessageUtil;
+import de.thedevstack.conversationsplus.utils.UiUpdateHelper;
import de.thedevstack.conversationsplus.utils.XmppSendUtil;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.FileTransferHttpDeleteSlotRequestPacketGenerator;
@@ -10,7 +15,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
/**
- * Created by steckbrief on 21.08.2016.
+ *
*/
public class DeleteRemoteFileService implements SimpleUserDecisionCallback {
private Message message;
@@ -23,14 +28,14 @@ public class DeleteRemoteFileService implements SimpleUserDecisionCallback {
if (this.message.isHttpUploaded()) {
String path = this.message.getBody();
if (this.message.hasFileOnRemoteHost()) {
- path = this.message.getFileParams().url.toString();
+ path = this.message.getFileParams().getUrl();
}
DeleteRemoteFile remoteFile = new DeleteRemoteFile(path, this.message);
Account account = this.message.getConversation().getAccount();
Jid host = account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE);
IqPacket request = FileTransferHttpDeleteSlotRequestPacketGenerator.generate(host, path);
-
+ MessageUtil.setAndSaveFileStatus(this.message, FileStatus.DELETING);
XmppSendUtil.sendIqPacket(account, request, new DeleteTokenReceived(remoteFile));
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java
index a8bef0ed..186454e4 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteTokenReceived.java
@@ -7,7 +7,7 @@ import java.io.IOException;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.entities.Account;
-import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.enums.FileStatus;
import de.thedevstack.conversationsplus.http.HttpClient;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived;
@@ -21,7 +21,7 @@ import okhttp3.Request;
import okhttp3.Response;
/**
- * Created by steckbrief on 21.08.2016.
+ *
*/
public class DeleteTokenReceived implements OnIqPacketReceived {
private static final String HEADER_NAME_DELETE_TOKEN = "X-FILETRANSFER-HTTP-DELETE-TOKEN";
@@ -47,19 +47,19 @@ public class DeleteTokenReceived implements OnIqPacketReceived {
@Override
public void onFailure(Call call, IOException e) {
Logging.e("filetransfer.http.delete", "Error while connecting to '" + call.request().url() + "': " + e.getMessage());
- MessageUtil.markMessage(remoteFile.getMessage(), Message.STATUS_REMOTE_FILE_DELETE_FAILED);
+ MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETE_FAILED);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
- MessageUtil.markMessage(remoteFile.getMessage(), Message.STATUS_REMOTE_FILE_DELETED);
+ MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETED);
Logging.i("filetransfer.http.delete", "Remote file successfully deleted '" + remoteFile.getPath() + "'");
} else {
String detailedMessage = response.body().string();
+ FileStatus fileStatus = FileStatus.DELETE_FAILED;
switch (response.code()) {
case 403:
- case 404:
case 500:
try {
JSONObject jsonObject = new JSONObject(detailedMessage);
@@ -68,16 +68,20 @@ public class DeleteTokenReceived implements OnIqPacketReceived {
Logging.e("filetransfer.http.delete", "Failed to get error message from expected json response: " + detailedMessage);
}
break;
+ case 404:
+ fileStatus = FileStatus.DELETED;
+ Logging.i("filetransfer.http.delete", "Failed to delete file - it was already deleted.");
+ break;
}
Logging.e("filetransfer.http.delete", "Could not delete remote file '" + remoteFile.getPath() + "'. Response Code: " + response.code() + ", details: " + detailedMessage);
- MessageUtil.markMessage(remoteFile.getMessage(), Message.STATUS_REMOTE_FILE_DELETE_FAILED);
+ MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), fileStatus);
}
}
});
} catch (XmppException e) {
Logging.e("filetransfer.http.delete", "Error while trying to get the delete token: " + e.getMessage());
- MessageUtil.markMessage(remoteFile.getMessage(), Message.STATUS_REMOTE_FILE_DELETE_FAILED);
+ MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETE_FAILED);
}
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java
index fbe7186b..a373d584 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileTransferEntity.java
@@ -6,7 +6,9 @@ import java.net.URL;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.enums.FileStatus;
import de.thedevstack.conversationsplus.services.filetransfer.FileTransferEntity;
import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
@@ -24,7 +26,13 @@ public class HttpFileTransferEntity extends FileTransferEntity {
public HttpFileTransferEntity(Message message, boolean delayed) {
super(message);
this.getMessage().setHttpUploaded(true);
- this.getMessage().setNoDownloadable();
+ this.getMessage().setNoDownloadable(); // TODO Set rmeote file status to uploaded
+ FileParams fileParams = this.getMessage().getFileParams();
+ if (null == fileParams) {
+ fileParams = new FileParams();
+ }
+ fileParams.setFileStatus(FileStatus.NEEDS_UPLOAD);
+ this.getMessage().setFileParams(fileParams);
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|| message.getEncryption() == Message.ENCRYPTION_OTR) {
@@ -77,6 +85,7 @@ public class HttpFileTransferEntity extends FileTransferEntity {
getUrl = new URL(getUrl.toString() + "#" + CryptoHelper.bytesToHex(this.getKey()));
}
+ this.getMessage().getFileParams().setFileStatus(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/HttpFileUploader.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java
index 318a8b8f..8cae599c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpFileUploader.java
@@ -84,6 +84,7 @@ public class HttpFileUploader implements Runnable {
// Send the URL to the counterpart
Message message = this.entity.getMessage();
+ message.setBody(this.entity.getGetUrl());
message.setCounterpart(message.getConversation().getJid().toBareJid());
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
XmppConnectionServiceAccessor.xmppConnectionService.getPgpEngine().encrypt(message, new HttpUploadedFileEncryptionUiCallback(this.entity));
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 f08e27f5..6b19cd5f 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
@@ -86,6 +86,7 @@ public class HttpUploadFileTransferService extends AbstractFileTransferService i
return null != message
&& null != message.getConversation()
&& null != message.getConversation().getAccount()
- && message.getConversation().getAccount().httpUploadAvailable(FileBackend.getFile(message, false).getSize());
+ && null != message.getFileParams()
+ && message.getConversation().getAccount().httpUploadAvailable(message.getFileParams().getSize());
}
}