aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java9
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java7
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java169
3 files changed, 40 insertions, 145 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index 4c4a1916..9b4198c8 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -20,6 +20,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.utils.SimpleCryptoUtil;
+
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OtrService;
@@ -172,6 +174,8 @@ public class Account extends AbstractEntity {
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
private final Collection<Jid> blocklist = new CopyOnWriteArraySet<>();
+ public static final String PW_SEED = "sadjgdiahsdkhashp3zt98edAFSFIOKZUIUOz23ejj12ezhez2398iehz";
+
public Account() {
this.uuid = "0";
}
@@ -210,9 +214,10 @@ public class Account extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(SERVER)), "mobile");
} catch (final InvalidJidException ignored) {
}
+ String password = SimpleCryptoUtil.decrypt(PW_SEED, cursor.getString(cursor.getColumnIndex(PASSWORD)));
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
jid,
- cursor.getString(cursor.getColumnIndex(PASSWORD)),
+ password,
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
cursor.getString(cursor.getColumnIndex(KEYS)),
@@ -342,7 +347,7 @@ public class Account extends AbstractEntity {
values.put(UUID, uuid);
values.put(USERNAME, jid.getLocalpart());
values.put(SERVER, jid.getDomainpart());
- values.put(PASSWORD, password);
+ values.put(PASSWORD, SimpleCryptoUtil.encrypt(PW_SEED, password));
values.put(OPTIONS, options);
values.put(KEYS, this.keys.toString());
values.put(ROSTERVERSION, rosterVersion);
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 7878cecd..299c5f7d 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -748,12 +748,7 @@ public class Conversation extends AbstractEntity implements Blockable {
for (int i = this.messages.size() - 1; i >= 0; --i) {
Message message = this.messages.get(i);
if (message.getStatus() == Message.STATUS_UNSEND || message.getStatus() == Message.STATUS_SEND) {
- String otherBody;
- if (message.hasFileOnRemoteHost()) {
- otherBody = message.getFileParams().url.toString();
- } else {
- otherBody = message.getBody();
- }
+ String otherBody = message.getBody();
if (otherBody != null && otherBody.equals(body)) {
return message;
}
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;
- }
-
- 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;
+ return FileUtils.getRelevantExtension(path);
}
- 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;