aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/message_storage.vala
diff options
context:
space:
mode:
authorfiaxh <fiaxh@users.noreply.github.com>2018-08-31 16:25:51 +0200
committerGitHub <noreply@github.com>2018-08-31 16:25:51 +0200
commitecb18afdb51b3230ea451a27a5b345cf5100f02e (patch)
tree44bae666c4cc31afce3a5d6891f6b4f65dfcebb1 /libdino/src/service/message_storage.vala
parent9e93a77a624aed24402cf1ece69c05aaa0aab600 (diff)
parentf5547076d2397cec5c9d7374bd161f93327488c4 (diff)
downloaddino-ecb18afdb51b3230ea451a27a5b345cf5100f02e.tar.gz
dino-ecb18afdb51b3230ea451a27a5b345cf5100f02e.zip
Merge pull request #415 from bobufa/message-search
Message search
Diffstat (limited to 'libdino/src/service/message_storage.vala')
-rw-r--r--libdino/src/service/message_storage.vala58
1 files changed, 40 insertions, 18 deletions
diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala
index 35e05074..50fc94b3 100644
--- a/libdino/src/service/message_storage.vala
+++ b/libdino/src/service/message_storage.vala
@@ -1,4 +1,5 @@
using Gee;
+using Qlite;
using Dino.Entities;
@@ -51,26 +52,47 @@ public class MessageStorage : StreamInteractionModule, Object {
return null;
}
- public Gee.List<Message>? get_messages_before_message(Conversation? conversation, Message message, int count = 20) {
- SortedSet<Message>? before = messages[conversation].head_set(message);
- if (before != null && before.size >= count) {
- Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
- Iterator<Message> iter = before.iterator();
- iter.next();
- for (int from_index = before.size - count; iter.has_next() && from_index > 0; from_index--) iter.next();
- while(iter.has_next()) {
- Message m = iter.get();
- ret.add(m);
- iter.next();
- }
- return ret;
- } else {
- Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, message.local_time);
- return db_messages;
+ public Gee.List<MessageItem> get_messages_before_message(Conversation? conversation, DateTime before, int id, int count = 20) {
+// SortedSet<Message>? before = messages[conversation].head_set(message);
+// if (before != null && before.size >= count) {
+// Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
+// Iterator<Message> iter = before.iterator();
+// iter.next();
+// for (int from_index = before.size - count; iter.has_next() && from_index > 0; from_index--) iter.next();
+// while(iter.has_next()) {
+// Message m = iter.get();
+// ret.add(m);
+// iter.next();
+// }
+// return ret;
+// } else {
+ Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, before, null, id);
+ Gee.List<MessageItem> ret = new ArrayList<MessageItem>();
+ foreach (Message message in db_messages) {
+ ret.add(new MessageItem(message, conversation, -1));
+ }
+ return ret;
+// }
+ }
+
+ public Gee.List<MessageItem> get_messages_after_message(Conversation? conversation, DateTime after, int id, int count = 20) {
+ Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, null, after, id);
+ Gee.List<MessageItem> ret = new ArrayList<MessageItem>();
+ foreach (Message message in db_messages) {
+ ret.add(new MessageItem(message, conversation, -1));
+ }
+ return ret;
+ }
+
+ public Message? get_message_by_id(int id, Conversation conversation) {
+ init_conversation(conversation);
+ foreach (Message message in messages[conversation]) {
+ if (message.id == id) return message;
}
+ return null;
}
- public Message? get_message_by_id(string stanza_id, Conversation conversation) {
+ public Message? get_message_by_stanza_id(string stanza_id, Conversation conversation) {
init_conversation(conversation);
foreach (Message message in messages[conversation]) {
if (message.stanza_id == stanza_id) return message;
@@ -100,7 +122,7 @@ public class MessageStorage : StreamInteractionModule, Object {
}
return res;
});
- Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null);
+ Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null, null, -1);
messages[conversation].add_all(db_messages);
}
}