From 0a9bba28616e594279cd659ec2eb57da2074b3cd Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 11 Jan 2017 14:55:53 +0100 Subject: Improved error handling for filetransfer:http:delete, Check for httpupload feature available extended to include filetransfer:http as well, method to check if http upload is available moved from data class 'Account' to 'AccountUtil' --- .../http/delete/DeleteRemoteFileService.java | 16 ++++++++++------ .../filetransfer/http/delete/DeleteTokenReceived.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete') 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 eb9f1b04..2085cf4b 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 @@ -31,12 +31,16 @@ public class DeleteRemoteFileService implements SimpleUserDecisionCallback { 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)); + if (null != path) { + DeleteRemoteFile remoteFile = new DeleteRemoteFile(path, this.message); + Account account = this.message.getConversation().getAccount(); + Jid host = account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE); + if (null != host) { + 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 186454e4..83a250de 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 @@ -1,16 +1,21 @@ package de.thedevstack.conversationsplus.services.filetransfer.http.delete; +import android.widget.Toast; + import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.enums.FileStatus; import de.thedevstack.conversationsplus.http.HttpClient; import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.ui.ConversationsPlusToast; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; +import de.thedevstack.conversationsplus.xmpp.exceptions.ServiceUnavailableException; import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.DeleteSlotPacketParser; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; @@ -81,6 +86,11 @@ public class DeleteTokenReceived implements OnIqPacketReceived { } catch (XmppException e) { Logging.e("filetransfer.http.delete", "Error while trying to get the delete token: " + e.getMessage()); + int messageResId = R.string.cplus_remote_file_delete_failed; + if (e instanceof ServiceUnavailableException) { + messageResId = R.string.cplus_remote_file_delete_service_unavailable; + } + ConversationsPlusToast.makeErrorToast(messageResId, Toast.LENGTH_LONG); MessageUtil.setAndSaveFileStatus(remoteFile.getMessage(), FileStatus.DELETE_FAILED); } } -- cgit v1.2.3