aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-15 19:32:12 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-15 19:32:12 +0200
commitcb4069f0f213ed1a38ce074d981b0c367dc2cdfd (patch)
tree9004af99e6da679e640fe97bdcdbf469832b8ab5 /src/eu/siacs/conversations/entities
parent1927a3d99c3a8e23535680ceb29e7dbb78bda185 (diff)
refactored file download status. make image http download available for carbon copied (sent) messages as well
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java7
-rw-r--r--src/eu/siacs/conversations/entities/Downloadable.java14
-rw-r--r--src/eu/siacs/conversations/entities/DownloadableFile.java4
-rw-r--r--src/eu/siacs/conversations/entities/Message.java55
4 files changed, 45 insertions, 35 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index b4c99dc1a..5f204ec27 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -68,7 +68,7 @@ public class Conversation extends AbstractEntity {
private transient MucOptions mucOptions = null;
- //private transient String latestMarkableMessageId;
+ // private transient String latestMarkableMessageId;
private byte[] symmetricKey;
@@ -142,8 +142,9 @@ public class Conversation extends AbstractEntity {
if (this.messages == null) {
return null;
}
- for(int i = this.messages.size() - 1; i >= 0; --i) {
- if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED && this.messages.get(i).markable) {
+ for (int i = this.messages.size() - 1; i >= 0; --i) {
+ if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED
+ && this.messages.get(i).markable) {
if (this.messages.get(i).isRead()) {
return null;
} else {
diff --git a/src/eu/siacs/conversations/entities/Downloadable.java b/src/eu/siacs/conversations/entities/Downloadable.java
index c8ee357db..3fc94c58c 100644
--- a/src/eu/siacs/conversations/entities/Downloadable.java
+++ b/src/eu/siacs/conversations/entities/Downloadable.java
@@ -1,9 +1,19 @@
package eu.siacs.conversations.entities;
public interface Downloadable {
-
+
public final String[] VALID_EXTENSIONS = { "webp", "jpeg", "jpg", "png" };
public final String[] VALID_CRYPTO_EXTENSIONS = { "pgp", "gpg", "otr" };
-
+
+ public static final int STATUS_UNKNOWN = 0x200;
+ public static final int STATUS_CHECKING = 0x201;
+ public static final int STATUS_FAILED = 0x202;
+ public static final int STATUS_OFFER = 0x203;
+ public static final int STATUS_DOWNLOADING = 0x204;
+
public void start();
+
+ public int getStatus();
+
+ public long getFileSize();
}
diff --git a/src/eu/siacs/conversations/entities/DownloadableFile.java b/src/eu/siacs/conversations/entities/DownloadableFile.java
index 14afc826f..50b00fb87 100644
--- a/src/eu/siacs/conversations/entities/DownloadableFile.java
+++ b/src/eu/siacs/conversations/entities/DownloadableFile.java
@@ -29,7 +29,7 @@ public class DownloadableFile extends File {
private long expectedSize = 0;
private String sha1sum;
private Key aeskey;
-
+
private byte[] iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf };
@@ -81,7 +81,7 @@ public class DownloadableFile extends File {
public Key getKey() {
return this.aeskey;
}
-
+
public InputStream createInputStream() {
if (this.getKey() == null) {
try {
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index 863288bbc..a256d5150 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -14,10 +14,6 @@ public class Message extends AbstractEntity {
public static final String TABLENAME = "messages";
- public static final int STATUS_RECEIVED_CHECKING = -4;
- public static final int STATUS_RECEPTION_FAILED = -3;
- public static final int STATUS_RECEIVED_OFFER = -2;
- public static final int STATUS_RECEIVING = -1;
public static final int STATUS_RECEIVED = 0;
public static final int STATUS_UNSEND = 1;
public static final int STATUS_SEND = 2;
@@ -136,8 +132,8 @@ public class Message extends AbstractEntity {
if (this.trueCounterpart == null) {
return null;
} else {
- return this.conversation.getAccount().getRoster().getContactFromRoster(
- this.trueCounterpart);
+ return this.conversation.getAccount().getRoster()
+ .getContactFromRoster(this.trueCounterpart);
}
}
}
@@ -147,12 +143,9 @@ public class Message extends AbstractEntity {
}
public String getReadableBody(Context context) {
- if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) {
+ if (encryption == ENCRYPTION_PGP) {
return context.getText(R.string.encrypted_message_received)
.toString();
- } else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) {
- return context.getText(R.string.encrypted_image_received)
- .toString();
} else if (encryption == ENCRYPTION_DECRYPTION_FAILED) {
return context.getText(R.string.decryption_failed).toString();
} else if (type == TYPE_IMAGE) {
@@ -322,6 +315,8 @@ public class Message extends AbstractEntity {
return false;
}
return (message.getType() == Message.TYPE_TEXT
+ && this.getDownloadable() == null
+ && message.getDownloadable() == null
&& message.getEncryption() != Message.ENCRYPTION_PGP
&& this.getType() == message.getType()
&& this.getEncryption() == message.getEncryption()
@@ -368,26 +363,34 @@ public class Message extends AbstractEntity {
return prev.mergable(this);
}
}
-
+
public boolean bodyContainsDownloadable() {
Contact contact = this.getContact();
- if (contact == null || !contact.trusted()) {
+ if (status <= STATUS_RECEIVED
+ && (contact == null || !contact.trusted())) {
return false;
}
try {
URL url = new URL(this.getBody());
- if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
+ if (!url.getProtocol().equalsIgnoreCase("http")
+ && !url.getProtocol().equalsIgnoreCase("https")) {
return false;
}
- if (url.getPath()==null) {
+ if (url.getPath() == null) {
return false;
}
String[] pathParts = url.getPath().split("/");
String filename = pathParts[pathParts.length - 1];
String[] extensionParts = filename.split("\\.");
- if (extensionParts.length == 2 && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(extensionParts[extensionParts.length -1])) {
+ if (extensionParts.length == 2
+ && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
+ extensionParts[extensionParts.length - 1])) {
return true;
- } else if (extensionParts.length == 3 && Arrays.asList(Downloadable.VALID_CRYPTO_EXTENSIONS).contains(extensionParts.length -1) && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(extensionParts[extensionParts.length -2])) {
+ } else if (extensionParts.length == 3
+ && Arrays.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
+ .contains(extensionParts.length - 1)
+ && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
+ extensionParts[extensionParts.length - 2])) {
return true;
} else {
return false;
@@ -396,27 +399,23 @@ public class Message extends AbstractEntity {
return false;
}
}
-
+
public ImageParams getImageParams() {
ImageParams params = new ImageParams();
- if (body==null) {
+ if (this.downloadable != null) {
+ params.size = this.downloadable.getFileSize();
+ }
+ if (body == null) {
return params;
}
String parts[] = body.split(",");
- if (parts.length==1) {
+ if (parts.length == 1) {
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
params.origin = parts[0];
}
- } else if (parts.length == 2) {
- params.origin = parts[0];
- try {
- params.size = Long.parseLong(parts[1]);
- } catch (NumberFormatException e) {
- params.size = 0;
- }
- } else if (parts.length==3) {
+ } else if (parts.length == 3) {
try {
params.size = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
@@ -452,7 +451,7 @@ public class Message extends AbstractEntity {
}
return params;
}
-
+
public class ImageParams {
public long size = 0;
public int width = 0;