From b0534dcf07e33ed8533f91dc47955b23a2c2a90d Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 8 Jul 2022 16:33:40 +0200 Subject: Rewrite MAM logic and add MUC MAM --- libdino/src/service/database.vala | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'libdino/src/service/database.vala') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 0300112a..25a6b477 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 = 22; + private const int VERSION = 23; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -193,6 +193,7 @@ public class Database : Qlite.Database { public Column jid_id = new Column.Integer("jid_id") { not_null = true }; public Column resource = new Column.Text("resource") { min_version=1 }; public Column active = new Column.BoolInt("active"); + public Column active_last_changed = new Column.Integer("active_last_changed") { not_null=true, default="0", min_version=23 }; public Column last_active = new Column.Long("last_active"); public Column type_ = new Column.Integer("type"); public Column encryption = new Column.Integer("encryption"); @@ -204,7 +205,7 @@ public class Database : Qlite.Database { internal ConversationTable(Database db) { base(db, "conversation"); - init({id, account_id, jid_id, resource, active, last_active, type_, encryption, read_up_to, read_up_to_item, notification, send_typing, send_marker}); + init({id, account_id, jid_id, resource, active, active_last_changed, last_active, type_, encryption, read_up_to, read_up_to_item, notification, send_typing, send_marker}); } } @@ -263,15 +264,16 @@ public class Database : Qlite.Database { public class MamCatchupTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; public Column account_id = new Column.Integer("account_id") { not_null = true }; - public Column from_end = new Column.BoolInt("from_end"); - public Column from_id = new Column.Text("from_id"); + public Column server_jid = new Column.Text("server_jid") { not_null = true }; + public Column from_id = new Column.Text("from_id") { not_null = true }; public Column from_time = new Column.Long("from_time") { not_null = true }; - public Column to_id = new Column.Text("to_id"); + public Column from_end = new Column.BoolInt("from_end") { not_null = true }; + public Column to_id = new Column.Text("to_id") { not_null = true }; public Column to_time = new Column.Long("to_time") { not_null = true }; internal MamCatchupTable(Database db) { base(db, "mam_catchup"); - init({id, account_id, from_end, from_id, from_time, to_id, to_time}); + init({id, account_id, server_jid, from_end, from_id, from_time, to_id, to_time}); } } @@ -474,6 +476,25 @@ public class Database : Qlite.Database { // FROM call2"); // exec("DROP TABLE call2"); } + if (oldVersion < 23) { + try { + exec("ALTER TABLE mam_catchup RENAME TO mam_catchup2"); + mam_catchup.create_table_at_version(VERSION); + exec("""INSERT INTO mam_catchup (id, account_id, server_jid, from_id, from_time, from_end, to_id, to_time) + SELECT mam_catchup2.id, account_id, bare_jid, ifnull(from_id, ""), from_time, ifnull(from_end, 0), ifnull(to_id, ""), to_time + FROM mam_catchup2 JOIN account ON mam_catchup2.account_id=account.id"""); + exec("DROP TABLE mam_catchup2"); + } catch (Error e) { + error("Failed to upgrade to database version 23 (mam_catchup): %s", e.message); + } + + try { + long active_last_updated = (long) new DateTime.now_utc().to_unix(); + exec(@"UPDATE conversation SET active_last_changed=$active_last_updated WHERE active_last_changed=0"); + } catch (Error e) { + error("Failed to upgrade to database version 23 (conversation): %s", e.message); + } + } } public ArrayList get_accounts() { -- cgit v1.2.3