More database migration, update defaults and indexes
This commit is contained in:
parent
20fe944c2d
commit
7da735b844
|
@ -31,7 +31,7 @@ public class ContactDetailsDialog : Gtk.Dialog {
|
||||||
.with(plugin.db.identity_meta.identity_id, "=", account.id)
|
.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.address_name, "=", device[plugin.db.identity_meta.address_name])
|
||||||
.with(plugin.db.identity_meta.device_id, "=", device[plugin.db.identity_meta.device_id])
|
.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) {
|
if(!trust) {
|
||||||
plugin.app.stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).untrust_device(jid, device[plugin.db.identity_meta.device_id]);
|
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>();
|
toggles = new ArrayList<Widget>();
|
||||||
|
|
||||||
int i = 0;
|
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) {
|
if (device[plugin.db.identity_meta.identity_key_public_base64] == null) {
|
||||||
continue;
|
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++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int j = 0;
|
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) {
|
if (device[plugin.db.identity_meta.identity_key_public_base64] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ public class ContactDetailsDialog : Gtk.Dialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
int k = 0;
|
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]));
|
string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64]));
|
||||||
Label lbl = new Label(res)
|
Label lbl = new Label(res)
|
||||||
{ use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START };
|
{ use_markup=true, justify=Justification.RIGHT, visible=true, margin = 8, halign = Align.START };
|
||||||
|
|
|
@ -26,13 +26,14 @@ public class Database : Qlite.Database {
|
||||||
public Column<string> address_name = new Column.Text("address_name") { not_null = true };
|
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<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<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<bool> now_active = new Column.BoolInt("now_active") { default = "1" };
|
||||||
public Column<long> last_active = new Column.Long("last_active");
|
public Column<long> last_active = new Column.Long("last_active");
|
||||||
|
|
||||||
internal IdentityMetaTable(Database db) {
|
internal IdentityMetaTable(Database db) {
|
||||||
base(db, "identity_meta");
|
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_idx", {identity_id, address_name, device_id}, true);
|
||||||
index("identity_meta_list_idx", {identity_id, address_name});
|
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.address_name, address_name, true)
|
||||||
.value(this.device_id, device_id, true)
|
.value(this.device_id, device_id, true)
|
||||||
.value(this.identity_key_public_base64, Base64.encode(bundle.identity_key.serialize()))
|
.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) {
|
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)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class DeviceNotificationPopulator : NotificationPopulator, Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool has_new_devices(Jid jid) {
|
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) {
|
public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) {
|
||||||
|
|
|
@ -202,7 +202,7 @@ public class Manager : StreamInteractionModule, Object {
|
||||||
.with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
|
.with(db.identity_meta.identity_key_public_base64, "=", Base64.encode(bundle.identity_key.serialize()))
|
||||||
.single().row().is_present());
|
.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) {
|
if(untrust) {
|
||||||
trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN;
|
trusted = Database.IdentityMetaTable.TrustLevel.UNKNOWN;
|
||||||
|
|
Loading…
Reference in a new issue