aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorbobufa <bobufa@users.noreply.github.com>2018-08-11 13:19:58 +0200
committerbobufa <bobufa@users.noreply.github.com>2018-08-13 22:39:18 +0200
commit2992a12f9fac1a7bf93a7aece5f85285c3b927ff (patch)
tree32b9c4e6068d0654b909026f466208560ac3a942 /libdino
parentc0844bdea428c10949339960bd16ea5e2a335fb8 (diff)
downloaddino-2992a12f9fac1a7bf93a7aece5f85285c3b927ff.tar.gz
dino-2992a12f9fac1a7bf93a7aece5f85285c3b927ff.zip
fix non-adjacent messages being shown before/after hit
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/database.vala31
1 files changed, 19 insertions, 12 deletions
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index bea07dda..4d8f0bd6 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -282,24 +282,21 @@ public class Database : Qlite.Database {
}
public Gee.List<Message> get_messages(Xmpp.Jid jid, Account account, Message.Type? type, int count, DateTime? before, DateTime? after, int id) {
- QueryBuilder select = message.select()
- .with(message.counterpart_id, "=", get_jid_id(jid))
- .with(message.account_id, "=", account.id)
- .limit(count);
- if (jid.resourcepart != null) {
- select.with(message.counterpart_resource, "=", jid.resourcepart);
- }
- if (type != null) {
- select.with(message.type_, "=", (int) type);
- }
+ QueryBuilder select = message.select();
+
if (before != null) {
- select.with(message.local_time, "<", (long) before.to_unix());
if (id > 0) {
+ select.where(@"local_time < ? OR (local_time = ? AND id < ?)", { before.to_unix().to_string(), before.to_unix().to_string(), id.to_string() });
+ } else {
select.with(message.id, "<", id);
}
}
if (after != null) {
- select.with(message.local_time, ">", (long) after.to_unix());
+ if (id > 0) {
+ select.where(@"local_time > ? OR (local_time = ? AND id > ?)", { after.to_unix().to_string(), after.to_unix().to_string(), id.to_string() });
+ } else {
+ select.with(message.local_time, ">", (long) after.to_unix());
+ }
if (id > 0) {
select.with(message.id, ">", id);
}
@@ -307,6 +304,16 @@ public class Database : Qlite.Database {
select.order_by(message.id, "DESC");
}
+ select.with(message.counterpart_id, "=", get_jid_id(jid))
+ .with(message.account_id, "=", account.id)
+ .limit(count);
+ if (jid.resourcepart != null) {
+ select.with(message.counterpart_resource, "=", jid.resourcepart);
+ }
+ if (type != null) {
+ select.with(message.type_, "=", (int) type);
+ }
+
LinkedList<Message> ret = new LinkedList<Message>();
foreach (Row row in select) {
ret.insert(0, new Message.from_row(this, row));