aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities/Message.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Message.java')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java167
1 files changed, 31 insertions, 136 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 6faebc65..5abba478 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -6,6 +6,9 @@ import android.database.Cursor;
import java.net.MalformedURLException;
import java.net.URL;
+import de.thedevstack.conversationsplus.entities.FileParams;
+import de.thedevstack.conversationsplus.enums.FileStatus;
+
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.utils.MimeUtils;
@@ -84,6 +87,7 @@ public class Message extends AbstractEntity {
private Decision mTreatAsDownloadAble = Decision.NOT_DECIDED;
private boolean httpUploaded;
+ private FileParams fileParams;
private Message() {
@@ -335,6 +339,9 @@ public class Message extends AbstractEntity {
public void setType(int type) {
this.type = type;
+ if (null != this.fileParams && (type == Message.TYPE_FILE || type == Message.TYPE_IMAGE)) {
+ this.setFileParams(new FileParams());
+ }
}
public boolean isCarbon() {
@@ -368,17 +375,8 @@ public class Message extends AbstractEntity {
|| message.getBody() == null || message.getCounterpart() == null) {
return false;
} else {
- String body, otherBody;
- if (this.hasFileOnRemoteHost()) {
- body = this.getFileParams().url.toString();
- } else {
- body = this.getBody();
- }
- if (message.hasFileOnRemoteHost()) {
- otherBody = message.getFileParams().url.toString();
- } else {
- otherBody = message.getBody();
- }
+ String body = this.getBody();
+ String otherBody = message.getBody();
if (message.getRemoteMsgId() != null && this.getRemoteMsgId() != null) {
return (message.getRemoteMsgId().equals(this.getRemoteMsgId())
@@ -493,27 +491,10 @@ public class Message extends AbstractEntity {
}
private String extractRelevantExtension(String path) {
- if (path == null || path.isEmpty()) {
- return null;
+ return FileUtils.getRelevantExtension(path);
}
- String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
-
- final String lastPart = FileUtils.getLastExtension(filename);
-
- if (!lastPart.isEmpty()) {
- // we want the real file extension, not the crypto one
- final String secondToLastPart = FileUtils.getSecondToLastExtension(filename);
- if (!secondToLastPart.isEmpty() && Transferable.VALID_CRYPTO_EXTENSIONS.contains(lastPart)) {
- return secondToLastPart;
- } else {
- return lastPart;
- }
- }
- return null;
- }
-
- public String getMimeType() {
+ public String getMimeType() { // TODO: Move to fileparams
if (relativeFilePath != null) {
int start = relativeFilePath.lastIndexOf('.') + 1;
if (start < relativeFilePath.length()) {
@@ -592,103 +573,6 @@ public class Message extends AbstractEntity {
}
}
- public FileParams getFileParams() {
- FileParams params = getLegacyFileParams();
- if (params != null) {
- return params;
- }
- params = new FileParams();
- if (this.transferable != null) {
- params.size = this.transferable.getFileSize();
- }
- if (this.getBody() == null) {
- return params;
- }
- String parts[] = this.getBody().split("\\|");
- switch (parts.length) {
- case 1:
- try {
- params.size = Long.parseLong(parts[0]);
- } catch (NumberFormatException e) {
- try {
- params.url = new URL(parts[0]);
- } catch (MalformedURLException e1) {
- params.url = null;
- }
- }
- break;
- case 2:
- case 4:
- try {
- params.url = new URL(parts[0]);
- } catch (MalformedURLException e1) {
- params.url = null;
- }
- try {
- params.size = Long.parseLong(parts[1]);
- } catch (NumberFormatException e) {
- params.size = 0;
- }
- try {
- params.width = Integer.parseInt(parts[2]);
- } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
- params.width = 0;
- }
- try {
- params.height = Integer.parseInt(parts[3]);
- } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
- params.height = 0;
- }
- break;
- case 3:
- try {
- params.size = Long.parseLong(parts[0]);
- } catch (NumberFormatException e) {
- params.size = 0;
- }
- try {
- params.width = Integer.parseInt(parts[1]);
- } catch (NumberFormatException e) {
- params.width = 0;
- }
- try {
- params.height = Integer.parseInt(parts[2]);
- } catch (NumberFormatException e) {
- params.height = 0;
- }
- break;
- }
- return params;
- }
-
- public FileParams getLegacyFileParams() {
- FileParams params = new FileParams();
- if (this.getBody() == null) {
- return params;
- }
- String parts[] = this.getBody().split(",");
- if (parts.length == 3) {
- try {
- params.size = Long.parseLong(parts[0]);
- } catch (NumberFormatException e) {
- return null;
- }
- try {
- params.width = Integer.parseInt(parts[1]);
- } catch (NumberFormatException e) {
- return null;
- }
- try {
- params.height = Integer.parseInt(parts[2]);
- } catch (NumberFormatException e) {
- return null;
- }
- return params;
- } else {
- return null;
- }
- }
-
public void untie() {
this.mNextMessage = null;
this.mPreviousMessage = null;
@@ -698,19 +582,22 @@ public class Message extends AbstractEntity {
return type == TYPE_FILE || type == TYPE_IMAGE;
}
- public boolean hasFileOnRemoteHost() {
- return isFileOrImage() && getFileParams().url != null;
+ public boolean hasFileAttached() {
+ return isFileOrImage() || isHttpUploaded() || (null != fileParams && null != fileParams.getPath());
}
- public boolean needsUploading() {
- return isFileOrImage() && getFileParams().url == null;
+ /*
+ @TODO better
+ */
+ public boolean hasFileOnRemoteHost() {
+ return hasFileAttached() && null != getFileParams() && getFileParams().isRemoteAvailable();
}
- public class FileParams {
- public URL url;
- public long size = 0;
- public int width = 0;
- public int height = 0;
+ /*
+ @TODO better
+ */
+ public boolean needsUploading() {
+ return hasFileAttached() && getFileParams().getFileStatus() == FileStatus.NEEDS_UPLOAD;
}
public void setFingerprint(String fingerprint) {
@@ -765,6 +652,14 @@ public class Message extends AbstractEntity {
this.httpUploaded = httpUploaded;
}
+ public FileParams getFileParams() {
+ return this.fileParams;
+ }
+
+ public void setFileParams(FileParams params) {
+ this.fileParams = params;
+ }
+
private static int getCleanedEncryption(int encryption) {
if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) {
return ENCRYPTION_PGP;