From 0ab530932ae559d9b2a0dd8cbc57530fa8552319 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 8 Dec 2014 21:59:14 +0100 Subject: added max history age (default 1w). automatically sort newly added mam messages --- .../siacs/conversations/entities/Conversation.java | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/entities/Conversation.java') diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 725ed27b..63f341e7 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -16,6 +16,8 @@ import org.json.JSONObject; import java.security.interfaces.DSAPublicKey; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -471,12 +473,25 @@ public class Conversation extends AbstractEntity { } } - public void setLastMessageReceived(long value) { + public boolean setLastMessageReceived(long value) { + long before = getLastMessageReceived(); this.setAttribute(ATTRIBUTE_LAST_MESSAGE_RECEIVED, String.valueOf(value)); + return (value - before > 1000); } public long getLastMessageReceived() { - return getLongAttribute(ATTRIBUTE_LAST_MESSAGE_RECEIVED,0); + long timestamp = getLongAttribute(ATTRIBUTE_LAST_MESSAGE_RECEIVED,0); + if (timestamp == 0) { + synchronized (this.messages) { + for(int i = this.messages.size() - 1; i >= 0; --i) { + Message message = this.messages.get(i); + if (message.getStatus() == Message.STATUS_RECEIVED) { + return message.getTimeSent(); + } + } + } + } + return timestamp; } public void setMutedTill(long value) { @@ -544,6 +559,26 @@ public class Conversation extends AbstractEntity { } } + public void sort() { + synchronized (this.messages) { + for(Message message : this.messages) { + message.untie(); + } + Collections.sort(this.messages,new Comparator() { + @Override + public int compare(Message left, Message right) { + if (left.getTimeSent() < right.getTimeSent()) { + return -1; + } else if (left.getTimeSent() > right.getTimeSent()) { + return 1; + } else { + return 0; + } + } + }); + } + } + public class Smp { public static final int STATUS_NONE = 0; public static final int STATUS_CONTACT_REQUESTED = 1; -- cgit v1.2.3