aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-12-08 21:59:14 +0100
committeriNPUTmice <daniel@gultsch.de>2014-12-10 14:08:06 +0100
commit0ab530932ae559d9b2a0dd8cbc57530fa8552319 (patch)
tree8595e8968eaeafcab11757b892fdfcb6e567f84a /src/main/java/eu/siacs/conversations/entities
parent4a94389f052afab8b0424bd56af3e0741a9ee430 (diff)
added max history age (default 1w). automatically sort newly added mam messages
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/AbstractEntity.java1
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java39
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java5
3 files changed, 42 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/AbstractEntity.java b/src/main/java/eu/siacs/conversations/entities/AbstractEntity.java
index 92b8a729..957b0a14 100644
--- a/src/main/java/eu/siacs/conversations/entities/AbstractEntity.java
+++ b/src/main/java/eu/siacs/conversations/entities/AbstractEntity.java
@@ -17,5 +17,4 @@ public abstract class AbstractEntity {
public boolean equals(AbstractEntity entity) {
return this.getUuid().equals(entity.getUuid());
}
-
}
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<Message>() {
+ @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;
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 47861d06..1213f66a 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -493,6 +493,11 @@ public class Message extends AbstractEntity {
}
}
+ public void untie() {
+ this.mNextMessage = null;
+ this.mPreviousMessage = null;
+ }
+
public class ImageParams {
public URL url;
public long size = 0;