diff options
author | Samuel Hand <samuel.hand@openmailbox.org> | 2018-07-06 20:14:51 +0100 |
---|---|---|
committer | Samuel Hand <samuel.hand@openmailbox.org> | 2018-07-06 20:14:51 +0100 |
commit | 7da735b844da1b80a11135d22b011cabf54ad0fe (patch) | |
tree | e1b312fa68a4e3e71a2bf7f09eb79befb0415f6c | |
parent | 20fe944c2d2ef790e93abd6f36e10489802465ab (diff) | |
download | dino-7da735b844da1b80a11135d22b011cabf54ad0fe.tar.gz dino-7da735b844da1b80a11135d22b011cabf54ad0fe.zip |
More database migration, update defaults and indexes
-rw-r--r-- | plugins/omemo/src/contact_details_dialog.vala | 10 | ||||
-rw-r--r-- | plugins/omemo/src/database.vala | 12 | ||||
-rw-r--r-- | plugins/omemo/src/device_notification_populator.vala | 2 | ||||
-rw-r--r-- | plugins/omemo/src/manager.vala | 2 |
4 files changed, 15 insertions, 11 deletions
diff --git a/plugins/omemo/src/contact_details_dialog.vala b/plugins/omemo/src/contact_details_dialog.vala index af0d165b..aa1b2a5f 100644 --- a/plugins/omemo/src/contact_details_dialog.vala +++ b/plugins/omemo/src/contact_details_dialog.vala @@ -31,7 +31,7 @@ public class ContactDetailsDialog : Gtk.Dialog { .with(plugin.db.identity_meta.identity_id, "=", account.id) .with(plugin.db.identity_meta.address_name, "=", device[plugin.db.identity_meta.address_name]) .with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id]) - .set(plugin.db.identity_meta.trusted_identity, trust_level).perform(); + .set(plugin.db.identity_meta.trust_level, trust_level).perform(); if(!trust) { plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).untrust_device(jid, device[plugin.db.identity_meta.device_id]); @@ -66,18 +66,18 @@ public class ContactDetailsDialog : Gtk.Dialog { toggles = new ArrayList<Widget>(); int i = 0; - foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.trusted_identity, "!=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trust_level, "!=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).with(plugin.db.identity_meta.trust_level, "!=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; } - add_fingerprint(device, i, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trusted_identity]); + add_fingerprint(device, i, (Database.IdentityMetaTable.TrustLevel) device[plugin.db.identity_meta.trust_level]); i++; } int j = 0; - foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN)) { + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).with(plugin.db.identity_meta.trust_level, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN)) { if (device[plugin.db.identity_meta.identity_key_public_base64] == null) { continue; } @@ -142,7 +142,7 @@ public class ContactDetailsDialog : Gtk.Dialog { } int k = 0; - foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).without_null(plugin.db.identity_meta.identity_key_public_base64).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { + foreach (Row device in plugin.db.identity_meta.with_address(account.id, jid.to_string()).without_null(plugin.db.identity_meta.identity_key_public_base64).with(plugin.db.identity_meta.trust_level, "=", Database.IdentityMetaTable.TrustLevel.VERIFIED)) { string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); Label lbl = new Label(res) { use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START }; diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala index 3f24e9f6..05864e38 100644 --- a/plugins/omemo/src/database.vala +++ b/plugins/omemo/src/database.vala @@ -26,13 +26,14 @@ public class Database : Qlite.Database { public Column<string> address_name = new Column.Text("address_name") { not_null = true }; public Column<int> device_id = new Column.Integer("device_id") { not_null = true }; public Column<string?> identity_key_public_base64 = new Column.Text("identity_key_public_base64"); - public Column<int> trusted_identity = new Column.Integer("trusted_identity") { not_null = true, default = TrustLevel.UNKNOWN.to_string() }; + public Column<bool> trusted_identity = new Column.BoolInt("trusted_identity") { default = "0", max_version = 1 }; + public Column<int> trust_level = new Column.Integer("trust_level") { default = TrustLevel.UNKNOWN.to_string(), min_version = 2 }; public Column<bool> now_active = new Column.BoolInt("now_active") { default = "1" }; public Column<long> last_active = new Column.Long("last_active"); internal IdentityMetaTable(Database db) { base(db, "identity_meta"); - init({identity_id, address_name, device_id, identity_key_public_base64, trusted_identity, now_active, last_active}); + init({identity_id, address_name, device_id, identity_key_public_base64, trusted_identity, trust_level, now_active, last_active}); index("identity_meta_idx", {identity_id, address_name, device_id}, true); index("identity_meta_list_idx", {identity_id, address_name}); } @@ -61,7 +62,7 @@ public class Database : Qlite.Database { .value(this.address_name, address_name, true) .value(this.device_id, device_id, true) .value(this.identity_key_public_base64, Base64.encode(bundle.identity_key.serialize())) - .value(this.trusted_identity, trust).perform(); + .value(this.trust_level, trust).perform(); } } @@ -159,7 +160,10 @@ public class Database : Qlite.Database { } public override void migrate(long oldVersion) { - // new table columns are added, outdated columns are still present + exec("DROP INDEX identity_meta_idx"); + exec("DROP INDEX identity_meta_list_idx"); + exec("CREATE UNIQUE INDEX identity_meta_idx ON identity_meta (identity_id, address_name, device_id)"); + exec("CREATE INDEX identity_meta_list_idx ON identity_meta (identity_id, address_name)"); } } diff --git a/plugins/omemo/src/device_notification_populator.vala b/plugins/omemo/src/device_notification_populator.vala index a6a51742..6940c723 100644 --- a/plugins/omemo/src/device_notification_populator.vala +++ b/plugins/omemo/src/device_notification_populator.vala @@ -20,7 +20,7 @@ public class DeviceNotificationPopulator : NotificationPopulator, Object { } public bool has_new_devices(Jid jid) { - return plugin.db.identity_meta.with_address(current_conversation.account.id, jid.bare_jid.to_string()).with(plugin.db.identity_meta.trusted_identity, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).without_null(plugin.db.identity_meta.identity_key_public_base64).count() > 0; + return plugin.db.identity_meta.with_address(current_conversation.account.id, jid.bare_jid.to_string()).with(plugin.db.identity_meta.trust_level, "=", Database.IdentityMetaTable.TrustLevel.UNKNOWN).without_null(plugin.db.identity_meta.identity_key_public_base64).count() > 0; } public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) { diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index dffe9fc2..e1f3ee56 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -202,7 +202,7 @@ public class Manager : StreamInteractionModule, Object { .with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize())) .single().row().is_present()); - Database.IdentityMetaTable.TrustLevel trusted = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with(db.identity_meta.device_id, "=", device_id).single()[db.identity_meta.trusted_identity, Database.IdentityMetaTable.TrustLevel.UNKNOWN]; + Database.IdentityMetaTable.TrustLevel trusted = (Database.IdentityMetaTable.TrustLevel) db.identity_meta.with_address(account.id, jid.bare_jid.to_string()).with(db.identity_meta.device_id, "=", device_id).single()[db.identity_meta.trust_level, Database.IdentityMetaTable.TrustLevel.UNKNOWN]; if(untrust) { trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN; |