diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-13 21:04:05 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:34:11 +0100 |
commit | 7a90ca429bb46fae4cbd600bd4c2274f4a731a16 (patch) | |
tree | 0ec0d753e32f0c361e43bf2bac627bda39a7899d /src/main/java/eu/siacs/conversations/services | |
parent | 4c504dea7ac7b0413df89ec630408b91f4abddb4 (diff) |
basic arbitrary file transfer
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 831a54e1..36ccc632 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -56,6 +56,7 @@ import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Downloadable; +import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions.OnRenameListener; @@ -294,6 +295,27 @@ public class XmppConnectionService extends Service { return this.mAvatarService; } + public Message attachFileToConversation(Conversation conversation, final Uri uri) { + String path = getFileBackend().getOriginalPath(uri); + if (path!=null) { + Log.d(Config.LOGTAG,"file path : "+path); + Message message; + if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) { + message = new Message(conversation, "", + Message.ENCRYPTION_DECRYPTED); + } else { + message = new Message(conversation, "", + conversation.getNextEncryption(forceEncryption())); + } + message.setCounterpart(conversation.getNextCounterpart()); + message.setType(Message.TYPE_FILE); + message.setStatus(Message.STATUS_OFFERED); + message.setRelativeFilePath(path); + return message; + } + return null; + } + public Message attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) { final Message message; @@ -312,13 +334,14 @@ public class XmppConnectionService extends Service { @Override public void run() { try { - getFileBackend().copyImageToPrivateStorage(message, uri); + DownloadableFile file = getFileBackend().copyImageToPrivateStorage(message, uri); + message.setRelativeFilePath(file.getName()); if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) { getPgpEngine().encrypt(message, callback); } else { callback.success(message); } - } catch (FileBackend.ImageCopyException e) { + } catch (FileBackend.FileCopyException e) { callback.error(e.getResId(), message); } } @@ -552,7 +575,7 @@ public class XmppConnectionService extends Service { boolean send = false; if (account.getStatus() == Account.STATUS_ONLINE && account.getXmppConnection() != null) { - if (message.getType() == Message.TYPE_IMAGE) { + if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { if (message.getCounterpart() != null) { if (message.getEncryption() == Message.ENCRYPTION_OTR) { if (!conv.hasValidOtrSession()) { @@ -1988,5 +2011,15 @@ public class XmppConnectionService extends Service { return 0; } + @Override + public int getProgress() { + return 0; + } + + @Override + public String getMimeType() { + return ""; + } + } } |