aboutsummaryrefslogtreecommitdiff
path: root/libdino/src
diff options
context:
space:
mode:
authorTranslations <translations@dino.im>2017-11-18 19:42:22 +0100
committerfiaxh <git@mx.ax.lt>2017-11-18 19:43:59 +0100
commitebf8d7ab01bd9df03c3a9fda0f0e2c5da228c8ce (patch)
treeeab3a2a6be0e7ff1e7f2b238224d78d078189165 /libdino/src
parent2a514d0969f5c25d5e2d14421125a47df6b14974 (diff)
downloaddino-ebf8d7ab01bd9df03c3a9fda0f0e2c5da228c8ce.tar.gz
dino-ebf8d7ab01bd9df03c3a9fda0f0e2c5da228c8ce.zip
Update translations
Diffstat (limited to 'libdino/src')
-rw-r--r--libdino/src/service/message_storage.vala12
1 files changed, 7 insertions, 5 deletions
diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala
index 76a8e60d..97873972 100644
--- a/libdino/src/service/message_storage.vala
+++ b/libdino/src/service/message_storage.vala
@@ -32,9 +32,11 @@ public class MessageStorage : StreamInteractionModule, Object {
public Gee.List<Message> get_messages(Conversation conversation, int count = 50) {
init_conversation(conversation);
Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
- foreach (Message message in messages[conversation]) {
- if (ret.size >= count) break;
- ret.add(message);
+ BidirIterator<Message> iter = messages[conversation].bidir_iterator();
+ iter.last();
+ while (iter.valid && ret.size < count) {
+ iter.previous();
+ ret.insert(0, iter.get());
}
return ret;
}
@@ -42,7 +44,7 @@ public class MessageStorage : StreamInteractionModule, Object {
public Message? get_last_message(Conversation conversation) {
init_conversation(conversation);
if (messages[conversation].size > 0) {
- return messages[conversation].first();
+ return messages[conversation].last();
}
return null;
}
@@ -62,7 +64,7 @@ public class MessageStorage : StreamInteractionModule, Object {
private void init_conversation(Conversation conversation) {
if (!messages.has_key(conversation)) {
- messages[conversation] = new Gee.TreeSet<Message>((a, b) => { return -1 * a.local_time.compare(b.local_time); });
+ messages[conversation] = new Gee.TreeSet<Message>((a, b) => { return a.local_time.compare(b.local_time); });
Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null);
messages[conversation].add_all(db_messages);
}