diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-08-23 15:57:39 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-08-23 15:57:39 +0200 |
commit | f7437ecc360b8ceb2ac976172831034a7c5e4260 (patch) | |
tree | f8cf52d2bea46d9a7e2f1e926a601c39cca0a7af /src/eu/siacs | |
parent | ee9872277dd83e3109633bd7b59a962555e663b5 (diff) |
experimental muc message deduplication
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 9 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Message.java | 8 | ||||
-rw-r--r-- | src/eu/siacs/conversations/parser/MessageParser.java | 10 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index be641ea4..ce29301c 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -399,4 +399,13 @@ public class Conversation extends AbstractEntity { return UIHelper.getContactPicture(this, size, context, false); } } + + public boolean hasDuplicateMessage(Message message) { + for(int i = this.getMessages().size() -1; i >= 0; --i) { + if (this.messages.get(i).equals(message)) { + return true; + } + } + return false; + } } diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index b669efc5..6d70b66d 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -275,4 +275,12 @@ public class Message extends AbstractEntity { public void setCounterpart(String counterpart) { this.counterpart = counterpart; } + + public boolean equals(Message message) { + if ((this.remoteMsgId!=null) && (this.body != null) && (this.counterpart != null)) { + return this.remoteMsgId.equals(message.getRemoteMsgId()) && this.body.equals(message.getBody()) && this.counterpart.equals(message.getCounterpart()); + } else { + return false; + } + } } diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index e3cb1a1e..06c0923a 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -48,6 +48,7 @@ public class MessageParser extends AbstractParser implements .getTrueCounterpart(fromParts[1])); } + finishedMessage.setRemoteMsgId(packet.getId()); finishedMessage.setTime(getTimestamp(packet)); return finishedMessage; } @@ -113,6 +114,7 @@ public class MessageParser extends AbstractParser implements packet.getFrom(), body, Message.ENCRYPTION_OTR, Message.STATUS_RECIEVED); finishedMessage.setTime(getTimestamp(packet)); + finishedMessage.setRemoteMsgId(packet.getId()); return finishedMessage; } catch (Exception e) { String receivedId = packet.getId(); @@ -163,11 +165,15 @@ public class MessageParser extends AbstractParser implements finishedMessage = new Message(conversation, counterPart, pgpBody, Message.ENCRYPTION_PGP, status); } - finishedMessage.setTime(getTimestamp(packet)); + finishedMessage.setRemoteMsgId(packet.getId()); if (status == Message.STATUS_RECIEVED) { finishedMessage.setTrueCounterpart(conversation.getMucOptions() .getTrueCounterpart(counterPart)); } + if (packet.hasChild("delay") && conversation.hasDuplicateMessage(finishedMessage)) { + return null; + } + finishedMessage.setTime(getTimestamp(packet)); return finishedMessage; } @@ -223,7 +229,7 @@ public class MessageParser extends AbstractParser implements Message.ENCRYPTION_NONE, status); } finishedMessage.setTime(getTimestamp(message)); - + finishedMessage.setRemoteMsgId(message.getAttribute("id")); if (conversation.getMode() == Conversation.MODE_MULTI && parts.length >= 2) { finishedMessage.setType(Message.TYPE_PRIVATE); |