54 lines
1.9 KiB
Vala
54 lines
1.9 KiB
Vala
using Qlite;
|
|
using Signal;
|
|
|
|
namespace Dino.Plugins.Omemo {
|
|
|
|
private class BackedSignedPreKeyStore : SimpleSignedPreKeyStore {
|
|
private Database db;
|
|
private int identity_id;
|
|
|
|
public BackedSignedPreKeyStore(Database db, int identity_id) {
|
|
this.db = db;
|
|
this.identity_id = identity_id;
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
try {
|
|
foreach (Row row in db.signed_pre_key.select().with(db.signed_pre_key.identity_id, "=", identity_id)) {
|
|
store_signed_pre_key(row[db.signed_pre_key.signed_pre_key_id], Base64.decode(row[db.signed_pre_key.record_base64]));
|
|
}
|
|
} catch (Error e) {
|
|
print(@"OMEMO: Error while initializing signed pre key store: $(e.message)\n");
|
|
}
|
|
|
|
signed_pre_key_stored.connect(on_signed_pre_key_stored);
|
|
signed_pre_key_deleted.connect(on_signed_pre_key_deleted);
|
|
}
|
|
|
|
public void on_signed_pre_key_stored(SignedPreKeyStore.Key key) {
|
|
try {
|
|
db.signed_pre_key.insert().or("REPLACE")
|
|
.value(db.signed_pre_key.identity_id, identity_id)
|
|
.value(db.signed_pre_key.signed_pre_key_id, (int) key.key_id)
|
|
.value(db.signed_pre_key.record_base64, Base64.encode(key.record))
|
|
.perform();
|
|
} catch (Error e) {
|
|
print(@"OMEMO: Error while updating signed pre key store: $(e.message)\n");
|
|
}
|
|
|
|
}
|
|
|
|
public void on_signed_pre_key_deleted(SignedPreKeyStore.Key key) {
|
|
try {
|
|
db.signed_pre_key.delete()
|
|
.with(db.signed_pre_key.identity_id, "=", identity_id)
|
|
.with(db.signed_pre_key.signed_pre_key_id, "=", (int) key.key_id)
|
|
.perform();
|
|
} catch (Error e) {
|
|
print(@"OMEMO: Error while updating signed pre key store: $(e.message)\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
} |