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.java68
1 files changed, 47 insertions, 21 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index b5a1897d..8112f5de 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -36,17 +36,19 @@ public class Message extends AbstractEntity {
public static final int TYPE_STATUS = 3;
public static final int TYPE_PRIVATE = 4;
- public static String CONVERSATION = "conversationUuid";
- public static String COUNTERPART = "counterpart";
- public static String TRUE_COUNTERPART = "trueCounterpart";
- public static String BODY = "body";
- public static String TIME_SENT = "timeSent";
- public static String ENCRYPTION = "encryption";
- public static String STATUS = "status";
- public static String TYPE = "type";
- public static String REMOTE_MSG_ID = "remoteMsgId";
- public static String SERVER_MSG_ID = "serverMsgId";
- public static String RELATIVE_FILE_PATH = "relativeFilePath";
+ public static final String CONVERSATION = "conversationUuid";
+ public static final String COUNTERPART = "counterpart";
+ public static final String TRUE_COUNTERPART = "trueCounterpart";
+ public static final String BODY = "body";
+ public static final String TIME_SENT = "timeSent";
+ public static final String ENCRYPTION = "encryption";
+ public static final String STATUS = "status";
+ public static final String TYPE = "type";
+ public static final String REMOTE_MSG_ID = "remoteMsgId";
+ public static final String SERVER_MSG_ID = "serverMsgId";
+ public static final String RELATIVE_FILE_PATH = "relativeFilePath";
+ public static final String ME_COMMAND = "/me ";
+
public boolean markable = false;
protected String conversationUuid;
protected Jid counterpart;
@@ -310,12 +312,17 @@ public class Message extends AbstractEntity {
public boolean equals(Message message) {
if (this.serverMsgId != null && message.getServerMsgId() != null) {
return this.serverMsgId.equals(message.getServerMsgId());
+ } else if (this.body == null || this.counterpart == null) {
+ return false;
+ } else if (message.getRemoteMsgId() != null) {
+ return (message.getRemoteMsgId().equals(this.remoteMsgId) || message.getRemoteMsgId().equals(this.uuid))
+ && this.counterpart.equals(message.getCounterpart())
+ && this.body.equals(message.getBody());
} else {
- return this.body != null
- && this.counterpart != null
- && ((this.remoteMsgId != null && this.remoteMsgId.equals(message.getRemoteMsgId()))
- || this.uuid.equals(message.getRemoteMsgId())) && this.body.equals(message.getBody())
- && this.counterpart.equals(message.getCounterpart());
+ return this.remoteMsgId == null
+ && this.counterpart.equals(message.getCounterpart())
+ && this.body.equals(message.getBody())
+ && Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.PING_TIMEOUT * 500;
}
}
@@ -348,15 +355,34 @@ public class Message extends AbstractEntity {
}
public boolean mergeable(final Message message) {
- return message != null && (message.getType() == Message.TYPE_TEXT && this.getDownloadable() == null && message.getDownloadable() == null && message.getEncryption() != Message.ENCRYPTION_PGP && this.getType() == message.getType() && this.getStatus() == message.getStatus() && this.getEncryption() == message.getEncryption() && this.getCounterpart() != null && this.getCounterpart().equals(message.getCounterpart()) && (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) && !message.bodyContainsDownloadable() && !this.bodyContainsDownloadable());
+ return message != null &&
+ (message.getType() == Message.TYPE_TEXT &&
+ this.getDownloadable() == null &&
+ message.getDownloadable() == null &&
+ message.getEncryption() != Message.ENCRYPTION_PGP &&
+ this.getType() == message.getType() &&
+ this.getStatus() == message.getStatus() &&
+ this.getEncryption() == message.getEncryption() &&
+ this.getCounterpart() != null &&
+ this.getCounterpart().equals(message.getCounterpart()) &&
+ (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) &&
+ !message.bodyContainsDownloadable() &&
+ !this.bodyContainsDownloadable() &&
+ !message.getBody().startsWith(ME_COMMAND) &&
+ !this.getBody().startsWith(ME_COMMAND)
+ );
}
public String getMergedBody() {
- Message next = this.next();
+ final Message next = this.next();
if (this.mergeable(next)) {
- return body.trim() + '\n' + next.getMergedBody();
+ return getBody() + '\n' + next.getMergedBody();
}
- return body.trim();
+ return getBody();
+ }
+
+ public boolean hasMeCommand() {
+ return getMergedBody().startsWith(ME_COMMAND);
}
public int getMergedStatus() {
@@ -395,7 +421,7 @@ public class Message extends AbstractEntity {
String[] pathParts = url.getPath().split("/");
String filename;
if (pathParts.length > 0) {
- filename = pathParts[pathParts.length - 1];
+ filename = pathParts[pathParts.length - 1].toLowerCase();
} else {
return false;
}