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/database.vala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'libdino/src/service/database.vala') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 4dfcb5b4..a24822d2 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -7,7 +7,7 @@ using Dino.Entities; namespace Dino { public class Database : Qlite.Database { - private const int VERSION = 14; + private const int VERSION = 15; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -166,13 +166,14 @@ public class Database : Qlite.Database { public Column type_ = new Column.Integer("type"); public Column encryption = new Column.Integer("encryption"); public Column read_up_to = new Column.Integer("read_up_to"); + public Column read_up_to_item = new Column.Integer("read_up_to_item") { not_null=true, default="-1", min_version=15 }; public Column notification = new Column.Integer("notification") { min_version=3 }; public Column send_typing = new Column.Integer("send_typing") { min_version=3 }; public Column send_marker = new Column.Integer("send_marker") { min_version=3 }; internal ConversationTable(Database db) { base(db, "conversation"); - init({id, account_id, jid_id, resource, active, last_active, type_, encryption, read_up_to, notification, send_typing, send_marker}); + init({id, account_id, jid_id, resource, active, last_active, type_, encryption, read_up_to, read_up_to_item, notification, send_typing, send_marker}); } } @@ -365,6 +366,20 @@ public class Database : Qlite.Database { error("Failed to upgrade to database version 12: %s", e.message); } } + if (oldVersion < 15) { + // Initialize `conversation.read_up_to_item` with the content item id corresponding to the `read_up_to` message. + try { + exec(" + update conversation + set read_up_to_item=ifnull(( + select content_item.id + from content_item + where content_item.foreign_id=conversation.read_up_to and content_type=1) + , -1);"); + } catch (Error e) { + error("Failed to upgrade to database version 15: %s", e.message); + } + } } public ArrayList get_accounts() { -- cgit v1.2.3-54-g00ecf