diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/http')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpConnection.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnection.java b/src/main/java/eu/siacs/conversations/http/HttpConnection.java index 407a13d9..0810e167 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpConnection.java @@ -20,9 +20,7 @@ import org.apache.http.conn.ssl.StrictHostnameVerifier; import android.content.Intent; import android.graphics.BitmapFactory; import android.net.Uri; -import android.util.Log; -import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; @@ -38,6 +36,7 @@ public class HttpConnection implements Downloadable { private Message message; private DownloadableFile file; private int mStatus = Downloadable.STATUS_UNKNOWN; + private boolean acceptedAutomatically = false; public HttpConnection(HttpConnectionManager manager) { this.mHttpConnectionManager = manager; @@ -63,12 +62,19 @@ public class HttpConnection implements Downloadable { this.message.setDownloadable(this); try { mUrl = new URL(message.getBody()); + String path = mUrl.getPath(); + if (path != null && (path.endsWith(".pgp") || path.endsWith(".gpg"))) { + this.message.setEncryption(Message.ENCRYPTION_PGP); + } else if (message.getEncryption() != Message.ENCRYPTION_OTR) { + this.message.setEncryption(Message.ENCRYPTION_NONE); + } this.file = mXmppConnectionService.getFileBackend().getFile( message, false); String reference = mUrl.getRef(); if (reference != null && reference.length() == 96) { this.file.setKey(CryptoHelper.hexToBytes(reference)); } + if (this.message.getEncryption() == Message.ENCRYPTION_OTR && this.file.getKey() == null) { this.message.setEncryption(Message.ENCRYPTION_NONE); @@ -95,6 +101,10 @@ public class HttpConnection implements Downloadable { mXmppConnectionService.sendBroadcast(intent); message.setDownloadable(null); mHttpConnectionManager.finishConnection(this); + mXmppConnectionService.updateConversationUi(); + if (acceptedAutomatically) { + mXmppConnectionService.getNotificationService().push(message); + } } private void changeStatus(int status) { @@ -147,6 +157,8 @@ public class HttpConnection implements Downloadable { size = retrieveFileSize(); } catch (SSLHandshakeException e) { changeStatus(STATUS_OFFER_CHECK_FILESIZE); + HttpConnection.this.acceptedAutomatically = false; + HttpConnection.this.mXmppConnectionService.getNotificationService().push(message); return; } catch (IOException e) { cancel(); @@ -154,9 +166,12 @@ public class HttpConnection implements Downloadable { } file.setExpectedSize(size); if (size <= mHttpConnectionManager.getAutoAcceptFileSize()) { + HttpConnection.this.acceptedAutomatically = true; new Thread(new FileDownloader(interactive)).start(); } else { changeStatus(STATUS_OFFER); + HttpConnection.this.acceptedAutomatically = false; + HttpConnection.this.mXmppConnectionService.getNotificationService().push(message); } } @@ -231,8 +246,8 @@ public class HttpConnection implements Downloadable { BitmapFactory.decodeFile(file.getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; - message.setBody(mUrl.toString() + "," + file.getSize() + ',' - + imageWidth + ',' + imageHeight); + message.setBody(mUrl.toString() + "|" + file.getSize() + '|' + + imageWidth + '|' + imageHeight); message.setType(Message.TYPE_IMAGE); mXmppConnectionService.updateMessage(message); } |