aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/database.vala
diff options
context:
space:
mode:
authorSamuel Hand <samuel.hand@openmailbox.org>2018-08-10 00:45:22 +0100
committerSamuel Hand <samuel.hand@openmailbox.org>2018-08-10 00:45:22 +0100
commit36cc8b039338442512f0e86d9487d951b5f2c6e3 (patch)
tree0313a349ed15b31a68fd657f07fae9810579c6f1 /plugins/omemo/src/database.vala
parente1afda10e33bdd892ee655cda7b94c066d269817 (diff)
downloaddino-36cc8b039338442512f0e86d9487d951b5f2c6e3.tar.gz
dino-36cc8b039338442512f0e86d9487d951b5f2c6e3.zip
Code cleanup - move long database queries to their own functions and improve variable names
Diffstat (limited to 'plugins/omemo/src/database.vala')
-rw-r--r--plugins/omemo/src/database.vala38
1 files changed, 34 insertions, 4 deletions
diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala
index 05864e38..8f8cb44a 100644
--- a/plugins/omemo/src/database.vala
+++ b/plugins/omemo/src/database.vala
@@ -64,6 +64,34 @@ public class Database : Qlite.Database {
.value(this.identity_key_public_base64, Base64.encode(bundle.identity_key.serialize()))
.value(this.trust_level, trust).perform();
}
+
+ public QueryBuilder get_trusted_devices(int identity_id, string address_name) {
+ return this.with_address(identity_id, address_name)
+ .with(this.trust_level, "!=", TrustLevel.UNTRUSTED)
+ .with(this.now_active, "=", true);
+ }
+
+ public QueryBuilder get_known_devices(int identity_id, string address_name) {
+ return this.with_address(identity_id, address_name)
+ .with(this.trust_level, "!=", TrustLevel.UNKNOWN)
+ .without_null(this.identity_key_public_base64);
+ }
+
+ public QueryBuilder get_unknown_devices(int identity_id, string address_name) {
+ return this.with_address(identity_id, address_name)
+ .with_null(this.identity_key_public_base64);
+ }
+
+ public QueryBuilder get_new_devices(int identity_id, string address_name) {
+ return this.with_address(identity_id, address_name)
+ .with(this.trust_level, "=", TrustLevel.UNKNOWN)
+ .without_null(this.identity_key_public_base64);
+ }
+
+ public Row? get_device(int identity_id, string address_name, int device_id) {
+ return this.with_address(identity_id, address_name)
+ .with(this.device_id, "=", device_id).single().row().inner;
+ }
}
@@ -160,10 +188,12 @@ public class Database : Qlite.Database {
}
public override void migrate(long oldVersion) {
- 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)");
+ if(oldVersion == 1) {
+ 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)");
+ }
}
}