fix non-adjacent messages being shown before/after hit
This commit is contained in:
parent
c0844bdea4
commit
2992a12f9f
|
@ -282,8 +282,29 @@ 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) {
|
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()
|
QueryBuilder select = message.select();
|
||||||
.with(message.counterpart_id, "=", get_jid_id(jid))
|
|
||||||
|
if (before != null) {
|
||||||
|
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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
select.order_by(message.id, "DESC");
|
||||||
|
}
|
||||||
|
|
||||||
|
select.with(message.counterpart_id, "=", get_jid_id(jid))
|
||||||
.with(message.account_id, "=", account.id)
|
.with(message.account_id, "=", account.id)
|
||||||
.limit(count);
|
.limit(count);
|
||||||
if (jid.resourcepart != null) {
|
if (jid.resourcepart != null) {
|
||||||
|
@ -292,20 +313,6 @@ public class Database : Qlite.Database {
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
select.with(message.type_, "=", (int) type);
|
select.with(message.type_, "=", (int) type);
|
||||||
}
|
}
|
||||||
if (before != null) {
|
|
||||||
select.with(message.local_time, "<", (long) before.to_unix());
|
|
||||||
if (id > 0) {
|
|
||||||
select.with(message.id, "<", id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (after != null) {
|
|
||||||
select.with(message.local_time, ">", (long) after.to_unix());
|
|
||||||
if (id > 0) {
|
|
||||||
select.with(message.id, ">", id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
select.order_by(message.id, "DESC");
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedList<Message> ret = new LinkedList<Message>();
|
LinkedList<Message> ret = new LinkedList<Message>();
|
||||||
foreach (Row row in select) {
|
foreach (Row row in select) {
|
||||||
|
|
Loading…
Reference in a new issue