aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/database.vala
diff options
context:
space:
mode:
authorSamuel Hand <samuel.hand@openmailbox.org>2018-06-19 11:26:31 +0100
committerSamuel Hand <samuel.hand@openmailbox.org>2018-06-19 11:26:31 +0100
commit2a8352c5439129798b5141ec021b3b9405840a8a (patch)
treefcacb76529c0b7535b89a496092aac126cefdbc9 /plugins/omemo/src/database.vala
parent0bcdae34a5dbe5a102281e1b1bc405f5977dc659 (diff)
downloaddino-2a8352c5439129798b5141ec021b3b9405840a8a.tar.gz
dino-2a8352c5439129798b5141ec021b3b9405840a8a.zip
Database migration and code cleanup
Diffstat (limited to 'plugins/omemo/src/database.vala')
-rw-r--r--plugins/omemo/src/database.vala29
1 files changed, 20 insertions, 9 deletions
diff --git a/plugins/omemo/src/database.vala b/plugins/omemo/src/database.vala
index 2b295322..48fddde2 100644
--- a/plugins/omemo/src/database.vala
+++ b/plugins/omemo/src/database.vala
@@ -6,14 +6,27 @@ using Dino.Entities;
namespace Dino.Plugins.Omemo {
public class Database : Qlite.Database {
- private const int VERSION = 1;
+ private const int VERSION = 2;
public class IdentityMetaTable : Table {
- public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true };
+ public enum TrustLevel {
+ VERIFIED,
+ TRUSTED,
+ UNTRUSTED,
+ UNKNOWN;
+
+ public string to_string() {
+ int val = this;
+ return val.to_string();
+ }
+ }
+
+ //Default to provide backwards compatability
+ public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true, min_version = 2, default = "-1" };
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<bool> trusted_identity = new Column.BoolInt("trusted_identity");
+ public Column<int> trusted_identity = new Column.Integer("trusted_identity") { not_null = true, default = TrustLevel.UNKNOWN.to_string() };
public Column<bool> now_active = new Column.BoolInt("now_active") { default = "1" };
public Column<long> last_active = new Column.Long("last_active");
@@ -41,16 +54,14 @@ public class Database : Qlite.Database {
}
}
- public int64 insert_device_bundle(int32 identity_id, string address_name, int device_id, Bundle bundle, bool? trust) {
+ public int64 insert_device_bundle(int32 identity_id, string address_name, int device_id, Bundle bundle, TrustLevel trust) {
if (bundle == null || bundle.identity_key == null) return -1;
- UpsertBuilder query = upsert()
+ return upsert()
.value(this.identity_id, identity_id, true)
.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()));
- if(trust != null)
- query.value(this.trusted_identity, trust);
- return query.perform();
+ .value(this.identity_key_public_base64, Base64.encode(bundle.identity_key.serialize()))
+ .value(this.trusted_identity, trust).perform();
}
}