aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/database.vala
diff options
context:
space:
mode:
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() {