aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/database.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/database.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/database.vala')
-rw-r--r--libdino/src/service/database.vala19
1 files changed, 17 insertions, 2 deletions
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<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@@ -166,13 +166,14 @@ public class Database : Qlite.Database {
public Column<int> type_ = new Column.Integer("type");
public Column<int> encryption = new Column.Integer("encryption");
public Column<int> read_up_to = new Column.Integer("read_up_to");
+ public Column<int> read_up_to_item = new Column.Integer("read_up_to_item") { not_null=true, default="-1", min_version=15 };
public Column<int> notification = new Column.Integer("notification") { min_version=3 };
public Column<int> send_typing = new Column.Integer("send_typing") { min_version=3 };
public Column<int> 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<Account> get_accounts() {