From 7a90ca429bb46fae4cbd600bd4c2274f4a731a16 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 13 Nov 2014 21:04:05 +0100 Subject: basic arbitrary file transfer --- .../services/XmppConnectionService.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') 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 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 ""; + } + } } -- cgit v1.2.3 From 02cbda68a7af5c500f2044cb97507c680ef2bc41 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 13 Nov 2014 22:59:00 +0100 Subject: bug fixes and various improvements for file transfer --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 36ccc632..abcc92be 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -311,6 +311,7 @@ public class XmppConnectionService extends Service { message.setType(Message.TYPE_FILE); message.setStatus(Message.STATUS_OFFERED); message.setRelativeFilePath(path); + getFileBackend().updateFileParams(message); return message; } return null; @@ -335,7 +336,6 @@ public class XmppConnectionService extends Service { public void run() { try { DownloadableFile file = getFileBackend().copyImageToPrivateStorage(message, uri); - message.setRelativeFilePath(file.getName()); if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) { getPgpEngine().encrypt(message, callback); } else { -- cgit v1.2.3 From dac12be53e18962c80fd471421adac29b5c92f06 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 14 Nov 2014 00:28:39 +0100 Subject: copy non local files to private storage first --- .../services/XmppConnectionService.java | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') 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 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 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) { -- cgit v1.2.3 From 16847a30c88246381a026bce9f2435be2bd77422 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 14 Nov 2014 03:27:18 +0100 Subject: support for pgp files --- .../conversations/services/XmppConnectionService.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index babcce26..4565ce30 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -211,7 +211,7 @@ public class XmppConnectionService extends Service { private Integer rosterChangedListenerCount = 0; private SecureRandom mRandom; private FileObserver fileObserver = new FileObserver( - FileBackend.getConversationsDirectory()) { + FileBackend.getConversationsImageDirectory()) { @Override public void onEvent(int event, String path) { @@ -311,7 +311,11 @@ public class XmppConnectionService extends Service { if (path!=null) { message.setRelativeFilePath(path); getFileBackend().updateFileParams(message); - callback.success(message); + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } } else { new Thread(new Runnable() { @Override @@ -319,7 +323,11 @@ public class XmppConnectionService extends Service { try { getFileBackend().copyFileToPrivateStorage(message, uri); getFileBackend().updateFileParams(message); - callback.success(message); + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } } catch (FileBackend.FileCopyException e) { callback.error(e.getResId(),message); } -- cgit v1.2.3 From cc4f3702a83b5f4d4d57aa66bf50c5ba3b96e72b Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 15 Nov 2014 12:37:09 +0100 Subject: made file transfers cancelable --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 4565ce30..06137c64 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2040,5 +2040,10 @@ public class XmppConnectionService extends Service { return ""; } + @Override + public void cancel() { + + } + } } -- cgit v1.2.3 From e0f012dba1e8eba3a2d721d685d67ac7901e5c84 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 15 Nov 2014 13:19:04 +0100 Subject: fixed resending for files as well --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 06137c64..0383d6ea 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -714,7 +714,7 @@ public class XmppConnectionService extends Service { if (message.getType() == Message.TYPE_TEXT) { packet = mMessageGenerator.generateOtrChat(message, true); - } else if (message.getType() == Message.TYPE_IMAGE) { + } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { mJingleConnectionManager.createNewConnection(message); } } @@ -726,7 +726,7 @@ public class XmppConnectionService extends Service { || (message.getEncryption() == Message.ENCRYPTION_PGP)) { packet = mMessageGenerator.generatePgpChat(message, true); } - } else if (message.getType() == Message.TYPE_IMAGE) { + } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { Contact contact = message.getConversation().getContact(); Presences presences = contact.getPresences(); if ((message.getCounterpart() != null) @@ -1457,7 +1457,7 @@ public class XmppConnectionService extends Service { databaseBackend.updateMessage(msg); sendMessagePacket(account, outPacket); } - } else if (msg.getType() == Message.TYPE_IMAGE) { + } else if (msg.getType() == Message.TYPE_IMAGE || msg.getType() == Message.TYPE_FILE) { mJingleConnectionManager.createNewConnection(msg); } } -- cgit v1.2.3 From 47d44448f3c2e4527b23fcabc4ee65269094eda1 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 15 Nov 2014 14:40:43 +0100 Subject: fixed description in notifications and conversation overview --- .../services/NotificationService.java | 12 ++++- .../services/XmppConnectionService.java | 56 ++++++---------------- 2 files changed, 24 insertions(+), 44 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 4cb28145..385aab92 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -28,6 +28,7 @@ import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; 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.ui.ConversationActivity; @@ -266,14 +267,21 @@ public class NotificationService { if (message.getDownloadable() != null && (message.getDownloadable().getStatus() == Downloadable.STATUS_OFFER || message .getDownloadable().getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE)) { - return mXmppConnectionService.getText( - R.string.image_offered_for_download).toString(); + if (message.getType() == Message.TYPE_FILE) { + return mXmppConnectionService.getString(R.string.file_offered_for_download); + } else { + return mXmppConnectionService.getText( + R.string.image_offered_for_download).toString(); + } } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { return mXmppConnectionService.getText( R.string.encrypted_message_received).toString(); } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { return mXmppConnectionService.getText(R.string.decryption_failed) .toString(); + } else if (message.getType() == Message.TYPE_FILE) { + DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message); + return mXmppConnectionService.getString(R.string.file,file.getMimeType()); } else if (message.getType() == Message.TYPE_IMAGE) { return mXmppConnectionService.getText(R.string.image_file) .toString(); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 0383d6ea..2e4341f9 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -57,6 +57,7 @@ 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.DownloadablePlaceholder; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions.OnRenameListener; @@ -711,11 +712,16 @@ public class XmppConnectionService extends Service { } else { if (message.getConversation().getOtrSession() .getSessionStatus() == SessionStatus.ENCRYPTED) { - if (message.getType() == Message.TYPE_TEXT) { - packet = mMessageGenerator.generateOtrChat(message, - true); - } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { - mJingleConnectionManager.createNewConnection(message); + try { + message.setCounterpart(Jid.fromSessionID(message.getConversation().getOtrSession().getSessionID())); + if (message.getType() == Message.TYPE_TEXT) { + packet = mMessageGenerator.generateOtrChat(message, + true); + } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { + mJingleConnectionManager.createNewConnection(message); + } + } catch (InvalidJidException e) { + } } } @@ -885,10 +891,10 @@ public class XmppConnectionService extends Service { private void checkDeletedFiles(Conversation conversation) { for (Message message : conversation.getMessages()) { - if (message.getType() == Message.TYPE_IMAGE + if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP) { if (!getFileBackend().isFileAvailable(message)) { - message.setDownloadable(new DeletedDownloadable()); + message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED)); } } } @@ -901,7 +907,7 @@ public class XmppConnectionService extends Service { && message.getEncryption() != Message.ENCRYPTION_PGP && message.getUuid().equals(uuid)) { if (!getFileBackend().isFileAvailable(message)) { - message.setDownloadable(new DeletedDownloadable()); + message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED)); updateConversationUi(); } return; @@ -2012,38 +2018,4 @@ public class XmppConnectionService extends Service { return XmppConnectionService.this; } } - - private class DeletedDownloadable implements Downloadable { - - @Override - public boolean start() { - return false; - } - - @Override - public int getStatus() { - return Downloadable.STATUS_DELETED; - } - - @Override - public long getFileSize() { - return 0; - } - - @Override - public int getProgress() { - return 0; - } - - @Override - public String getMimeType() { - return ""; - } - - @Override - public void cancel() { - - } - - } } -- cgit v1.2.3