experimental muc message deduplication

This commit is contained in:
Daniel Gultsch 2014-08-23 15:57:39 +02:00
parent ee9872277d
commit f7437ecc36
3 changed files with 25 additions and 2 deletions

View file

@ -399,4 +399,13 @@ public class Conversation extends AbstractEntity {
return UIHelper.getContactPicture(this, size, context, false); 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;
}
} }

View file

@ -275,4 +275,12 @@ public class Message extends AbstractEntity {
public void setCounterpart(String counterpart) { public void setCounterpart(String counterpart) {
this.counterpart = 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;
}
}
} }

View file

@ -48,6 +48,7 @@ public class MessageParser extends AbstractParser implements
.getTrueCounterpart(fromParts[1])); .getTrueCounterpart(fromParts[1]));
} }
finishedMessage.setRemoteMsgId(packet.getId());
finishedMessage.setTime(getTimestamp(packet)); finishedMessage.setTime(getTimestamp(packet));
return finishedMessage; return finishedMessage;
} }
@ -113,6 +114,7 @@ public class MessageParser extends AbstractParser implements
packet.getFrom(), body, Message.ENCRYPTION_OTR, packet.getFrom(), body, Message.ENCRYPTION_OTR,
Message.STATUS_RECIEVED); Message.STATUS_RECIEVED);
finishedMessage.setTime(getTimestamp(packet)); finishedMessage.setTime(getTimestamp(packet));
finishedMessage.setRemoteMsgId(packet.getId());
return finishedMessage; return finishedMessage;
} catch (Exception e) { } catch (Exception e) {
String receivedId = packet.getId(); String receivedId = packet.getId();
@ -163,11 +165,15 @@ public class MessageParser extends AbstractParser implements
finishedMessage = new Message(conversation, counterPart, pgpBody, finishedMessage = new Message(conversation, counterPart, pgpBody,
Message.ENCRYPTION_PGP, status); Message.ENCRYPTION_PGP, status);
} }
finishedMessage.setTime(getTimestamp(packet)); finishedMessage.setRemoteMsgId(packet.getId());
if (status == Message.STATUS_RECIEVED) { if (status == Message.STATUS_RECIEVED) {
finishedMessage.setTrueCounterpart(conversation.getMucOptions() finishedMessage.setTrueCounterpart(conversation.getMucOptions()
.getTrueCounterpart(counterPart)); .getTrueCounterpart(counterPart));
} }
if (packet.hasChild("delay") && conversation.hasDuplicateMessage(finishedMessage)) {
return null;
}
finishedMessage.setTime(getTimestamp(packet));
return finishedMessage; return finishedMessage;
} }
@ -223,7 +229,7 @@ public class MessageParser extends AbstractParser implements
Message.ENCRYPTION_NONE, status); Message.ENCRYPTION_NONE, status);
} }
finishedMessage.setTime(getTimestamp(message)); finishedMessage.setTime(getTimestamp(message));
finishedMessage.setRemoteMsgId(message.getAttribute("id"));
if (conversation.getMode() == Conversation.MODE_MULTI if (conversation.getMode() == Conversation.MODE_MULTI
&& parts.length >= 2) { && parts.length >= 2) {
finishedMessage.setType(Message.TYPE_PRIVATE); finishedMessage.setType(Message.TYPE_PRIVATE);