aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/database.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2022-07-08 16:33:40 +0200
committerfiaxh <git@lightrise.org>2022-10-10 21:55:15 +0200
commit6c6e7e3aa7935ec513b7e5ea9b53a92b741ecf92 (patch)
treef92df8980bb6e65d9ce81f1395773201b664a779 /libdino/src/service/database.vala
parent9c736af765d8c62838440afbfd2ad7ee78b44951 (diff)
downloaddino-6c6e7e3aa7935ec513b7e5ea9b53a92b741ecf92.tar.gz
dino-6c6e7e3aa7935ec513b7e5ea9b53a92b741ecf92.zip
Rewrite MAM logic and add MUC MAM
Diffstat (limited to 'libdino/src/service/database.vala')
-rw-r--r--libdino/src/service/database.vala33
1 files changed, 27 insertions, 6 deletions
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<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@@ -193,6 +193,7 @@ public class Database : Qlite.Database {
public Column<int> jid_id = new Column.Integer("jid_id") { not_null = true };
public Column<string> resource = new Column.Text("resource") { min_version=1 };
public Column<bool> active = new Column.BoolInt("active");
+ public Column<long> active_last_changed = new Column.Integer("active_last_changed") { not_null=true, default="0", min_version=23 };
public Column<long> last_active = new Column.Long("last_active");
public Column<int> type_ = new Column.Integer("type");
public Column<int> 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<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
public Column<int> account_id = new Column.Integer("account_id") { not_null = true };
- public Column<bool> from_end = new Column.BoolInt("from_end");
- public Column<string> from_id = new Column.Text("from_id");
+ public Column<string> server_jid = new Column.Text("server_jid") { not_null = true };
+ public Column<string> from_id = new Column.Text("from_id") { not_null = true };
public Column<long> from_time = new Column.Long("from_time") { not_null = true };
- public Column<string> to_id = new Column.Text("to_id");
+ public Column<bool> from_end = new Column.BoolInt("from_end") { not_null = true };
+ public Column<string> to_id = new Column.Text("to_id") { not_null = true };
public Column<long> 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<Account> get_accounts() {