2017-03-11 00:29:38 +00:00
|
|
|
using Gee;
|
|
|
|
using Qlite;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
namespace Dino.Plugins.Omemo {
|
2017-03-11 00:29:38 +00:00
|
|
|
|
|
|
|
public class Database : Qlite.Database {
|
|
|
|
private const int VERSION = 0;
|
|
|
|
|
|
|
|
public class IdentityTable : 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") { unique = true, not_null = true };
|
|
|
|
public Column<int> device_id = new Column.Integer("device_id") { not_null = true };
|
2017-04-18 15:55:20 +00:00
|
|
|
public Column<string> identity_key_private_base64 = new Column.NonNullText("identity_key_private_base64");
|
|
|
|
public Column<string> identity_key_public_base64 = new Column.NonNullText("identity_key_public_base64");
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal IdentityTable(Database db) {
|
2017-03-11 00:29:38 +00:00
|
|
|
base(db, "identity");
|
|
|
|
init({id, account_id, device_id, identity_key_private_base64, identity_key_public_base64});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class SignedPreKeyTable : Table {
|
|
|
|
public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true };
|
|
|
|
public Column<int> signed_pre_key_id = new Column.Integer("signed_pre_key_id") { not_null = true };
|
2017-04-18 15:55:20 +00:00
|
|
|
public Column<string> record_base64 = new Column.NonNullText("record_base64");
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal SignedPreKeyTable(Database db) {
|
2017-03-11 00:29:38 +00:00
|
|
|
base(db, "signed_pre_key");
|
|
|
|
init({identity_id, signed_pre_key_id, record_base64});
|
|
|
|
unique({identity_id, signed_pre_key_id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PreKeyTable : Table {
|
|
|
|
public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true };
|
|
|
|
public Column<int> pre_key_id = new Column.Integer("pre_key_id") { not_null = true };
|
2017-04-18 15:55:20 +00:00
|
|
|
public Column<string> record_base64 = new Column.NonNullText("record_base64");
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal PreKeyTable(Database db) {
|
2017-03-11 00:29:38 +00:00
|
|
|
base(db, "pre_key");
|
|
|
|
init({identity_id, pre_key_id, record_base64});
|
|
|
|
unique({identity_id, pre_key_id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class SessionTable : Table {
|
|
|
|
public Column<int> identity_id = new Column.Integer("identity_id") { not_null = true };
|
2017-04-18 15:55:20 +00:00
|
|
|
public Column<string> address_name = new Column.NonNullText("name");
|
2017-03-11 00:29:38 +00:00
|
|
|
public Column<int> device_id = new Column.Integer("device_id") { not_null = true };
|
2017-04-18 15:55:20 +00:00
|
|
|
public Column<string> record_base64 = new Column.NonNullText("record_base64");
|
2017-03-11 00:29:38 +00:00
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal SessionTable(Database db) {
|
2017-03-11 00:29:38 +00:00
|
|
|
base(db, "session");
|
|
|
|
init({identity_id, address_name, device_id, record_base64});
|
|
|
|
unique({identity_id, address_name, device_id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IdentityTable identity { get; private set; }
|
|
|
|
public SignedPreKeyTable signed_pre_key { get; private set; }
|
|
|
|
public PreKeyTable pre_key { get; private set; }
|
|
|
|
public SessionTable session { get; private set; }
|
|
|
|
|
2017-03-12 01:28:23 +00:00
|
|
|
public Database(string fileName) throws DatabaseError {
|
2017-03-11 00:29:38 +00:00
|
|
|
base(fileName, VERSION);
|
|
|
|
identity = new IdentityTable(this);
|
|
|
|
signed_pre_key = new SignedPreKeyTable(this);
|
|
|
|
pre_key = new PreKeyTable(this);
|
|
|
|
session = new SessionTable(this);
|
|
|
|
init({identity, signed_pre_key, pre_key, session});
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void migrate(long oldVersion) {
|
|
|
|
// new table columns are added, outdated columns are still present
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|