aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/content_item_store.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-04-29 21:31:23 +0200
committerfiaxh <git@lightrise.org>2020-06-03 21:50:40 +0200
commit71be2abb6a007fd9b4ed3164d70f5cb95d49ce69 (patch)
treef4dcdb63e08ce6dc0e4933e30e18cec27c604719 /libdino/src/service/content_item_store.vala
parentb5066e0e2f4b482204f43402c797d8bf9f7ef582 (diff)
downloaddino-71be2abb6a007fd9b4ed3164d70f5cb95d49ce69.tar.gz
dino-71be2abb6a007fd9b4ed3164d70f5cb95d49ce69.zip
Store last read content item for conversations
fixes #495
Diffstat (limited to 'libdino/src/service/content_item_store.vala')
-rw-r--r--libdino/src/service/content_item_store.vala17
1 files changed, 15 insertions, 2 deletions
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<ContentItem> get_items_from_query(QueryBuilder select, Conversation conversation) {
- Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(ContentItem.compare);
+ Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(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<ContentItem> item = get_items_from_query(select, conversation);
+
+ return item.size > 0 ? item[0] : null;
+ }
+
public ContentItem? get_latest(Conversation conversation) {
Gee.List<ContentItem> 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);