diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-14 00:28:39 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:34:11 +0100 |
commit | dac12be53e18962c80fd471421adac29b5c92f06 (patch) | |
tree | 554839625546e0bd6e36361a199fc810389a0e76 /src/main/java/eu/siacs/conversations/services | |
parent | 02cbda68a7af5c500f2044cb97507c680ef2bc41 (diff) |
copy non local files to private storage first
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index abcc92be..babcce26 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -295,29 +295,41 @@ public class XmppConnectionService extends Service { return this.mAvatarService; } - public Message attachFileToConversation(Conversation conversation, final Uri uri) { + public void attachFileToConversation(Conversation conversation, final Uri uri, final UiCallback<Message> callback) { + final 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); 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); getFileBackend().updateFileParams(message); - return message; + callback.success(message); + } else { + new Thread(new Runnable() { + @Override + public void run() { + try { + getFileBackend().copyFileToPrivateStorage(message, uri); + getFileBackend().updateFileParams(message); + callback.success(message); + } catch (FileBackend.FileCopyException e) { + callback.error(e.getResId(),message); + } + } + }).start(); + } - return null; } - public Message attachImageToConversation(final Conversation conversation, + public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) { final Message message; if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) { @@ -346,7 +358,6 @@ public class XmppConnectionService extends Service { } } }).start(); - return message; } public Conversation find(Bookmark bookmark) { |