2017-03-12 13:44:09 +00:00
|
|
|
using Qlite;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
2018-01-12 20:03:09 +00:00
|
|
|
using Xmpp;
|
2017-03-12 13:44:09 +00:00
|
|
|
|
|
|
|
namespace Dino.Plugins.OpenPgp {
|
|
|
|
|
|
|
|
public class Database : Qlite.Database {
|
|
|
|
private const int VERSION = 0;
|
|
|
|
|
|
|
|
public class AccountSetting : Table {
|
|
|
|
public Column<int> account_id = new Column.Integer("account_id") { primary_key = true };
|
|
|
|
public Column<string> key = new Column.Text("key") { not_null = true };
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal AccountSetting(Database db) {
|
2017-03-12 13:44:09 +00:00
|
|
|
base(db, "account_setting");
|
|
|
|
init({account_id, key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ContactKey : Table {
|
|
|
|
public Column<string> jid = new Column.Text("jid") { primary_key = true };
|
|
|
|
public Column<string> key = new Column.Text("key") { not_null = true };
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal ContactKey(Database db) {
|
2017-03-12 13:44:09 +00:00
|
|
|
base(db, "contact_key");
|
|
|
|
init({jid, key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public AccountSetting account_setting_table { get; private set; }
|
|
|
|
public ContactKey contact_key_table { get; private set; }
|
|
|
|
|
|
|
|
public Database(string filename) {
|
|
|
|
base(filename, VERSION);
|
|
|
|
this.account_setting_table = new AccountSetting(this);
|
|
|
|
this.contact_key_table = new ContactKey(this);
|
|
|
|
init({account_setting_table, contact_key_table});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set_contact_key(Jid jid, string key) {
|
2020-06-10 21:40:00 +00:00
|
|
|
contact_key_table.upsert()
|
|
|
|
.value(contact_key_table.jid, jid.to_string(), true)
|
2017-03-12 13:44:09 +00:00
|
|
|
.value(contact_key_table.key, key)
|
|
|
|
.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string? get_contact_key(Jid jid) {
|
|
|
|
return contact_key_table.select({contact_key_table.key})
|
2017-09-05 21:53:18 +00:00
|
|
|
.with(contact_key_table.jid, "=", jid.to_string())[contact_key_table.key];
|
2017-03-12 13:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void set_account_key(Account account, string key) {
|
2020-06-10 21:40:00 +00:00
|
|
|
account_setting_table.upsert()
|
|
|
|
.value(account_setting_table.account_id, account.id, true)
|
2017-03-12 13:44:09 +00:00
|
|
|
.value(account_setting_table.key, key)
|
|
|
|
.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string? get_account_key(Account account) {
|
|
|
|
return account_setting_table.select({account_setting_table.key})
|
|
|
|
.with(account_setting_table.account_id, "=", account.id)[account_setting_table.key];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void migrate(long oldVersion) { }
|
|
|
|
}
|
|
|
|
|
2017-09-05 21:53:18 +00:00
|
|
|
}
|