From ea6564c81a23c10bcdabeba7e29211e97c444d5b Mon Sep 17 00:00:00 2001 From: lookshe Date: Sun, 20 Mar 2016 17:28:39 +0100 Subject: FS#104 - Fix Message.equals() --- .../conversationsplus/entities/Message.java | 32 ++++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java index 8dbb0535..c17995c9 100644 --- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java +++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java @@ -360,29 +360,25 @@ 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.getBody() == null || this.counterpart == null) { + if (this.getServerMsgId() != null && message.getServerMsgId() != null) { + return this.getServerMsgId().equals(message.getServerMsgId()); + } else if (this.getBody() == null || this.getCounterpart() == null + || message.getBody() == null || message.getCounterpart() == null) { return false; } else { - String body, otherBody; - if (this.hasFileOnRemoteHost()) { - body = getFileParams().url.toString(); - otherBody = message.getBody() == null ? null : message.getBody(); - } else { - body = this.getBody(); - otherBody = message.getBody(); - } - if (message.getRemoteMsgId() != null) { - return (message.getRemoteMsgId().equals(this.remoteMsgId) || message.getRemoteMsgId().equals(this.uuid)) - && this.counterpart.equals(message.getCounterpart()) - && (body.equals(otherBody) + if (message.getRemoteMsgId() != null && this.getRemoteMsgId() != null) { + return (message.getRemoteMsgId().equals(this.getRemoteMsgId()) + || message.getRemoteMsgId().equals(this.getUuid()) + || message.getUuid().equals(this.getRemoteMsgId())) + && this.getCounterpart().equals(message.getCounterpart()) + && (this.getBody().equals(message.getBody()) ||(message.getEncryption() == Message.ENCRYPTION_PGP && message.getRemoteMsgId().matches("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"))) ; } else { - return this.remoteMsgId == null - && this.counterpart.equals(message.getCounterpart()) - && body.equals(otherBody); + return this.getRemoteMsgId() == null + && message.getRemoteMsgId() == null + && this.getCounterpart().equals(message.getCounterpart()) + && this.getBody().equals(message.getBody()); } } } -- cgit v1.2.3