From 71be2abb6a007fd9b4ed3164d70f5cb95d49ce69 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 29 Apr 2020 21:31:23 +0200 Subject: Store last read content item for conversations fixes #495 --- libdino/src/service/content_item_store.vala | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libdino/src/service/content_item_store.vala') diff --git a/libdino/src/service/content_item_store.vala b/libdino/src/service/content_item_store.vala index 1ea0275e..640c3fda 100644 --- a/libdino/src/service/content_item_store.vala +++ b/libdino/src/service/content_item_store.vala @@ -40,7 +40,7 @@ public class ContentItemStore : StreamInteractionModule, Object { } public Gee.List get_items_from_query(QueryBuilder select, Conversation conversation) { - Gee.TreeSet items = new Gee.TreeSet(ContentItem.compare); + Gee.TreeSet items = new Gee.TreeSet(ContentItem.compare_func); foreach (var row in select) { int provider = row[db.content_item.content_type]; @@ -113,6 +113,15 @@ public class ContentItemStore : StreamInteractionModule, Object { return item.size > 0 ? item[0] : null; } + public ContentItem? get_item_by_id(Conversation conversation, int id) { + QueryBuilder select = db.content_item.select() + .with(db.content_item.id, "=", id); + + Gee.List item = get_items_from_query(select, conversation); + + return item.size > 0 ? item[0] : null; + } + public ContentItem? get_latest(Conversation conversation) { Gee.List items = get_n_latest(conversation, 1); if (items.size > 0) { @@ -246,7 +255,11 @@ public abstract class ContentItem : Object { this.mark = mark; } - public static int compare(ContentItem a, ContentItem b) { + public int compare(ContentItem c) { + return compare_func(this, c); + } + + public static int compare_func(ContentItem a, ContentItem b) { int res = a.sort_time.compare(b.sort_time); if (res == 0) { res = a.display_time.compare(b.display_time); -- cgit v1.2.3-54-g00ecf