diff options
author | Marvin W <git@larma.de> | 2017-03-10 19:34:56 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-03-10 19:50:34 +0100 |
commit | 29ca70a6d534e1cd79963718c793ae740318cff1 (patch) | |
tree | 295bc0a88b9f31f103bc970fbdcd2d940d6c83e2 /libdino/src/service/pgp_manager.vala | |
parent | cf51e1dee22273366700c41a185c4bea343dddfe (diff) | |
download | dino-29ca70a6d534e1cd79963718c793ae740318cff1.tar.gz dino-29ca70a6d534e1cd79963718c793ae740318cff1.zip |
Initial plugin system
Diffstat (limited to 'libdino/src/service/pgp_manager.vala')
-rw-r--r-- | libdino/src/service/pgp_manager.vala | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/libdino/src/service/pgp_manager.vala b/libdino/src/service/pgp_manager.vala new file mode 100644 index 00000000..6f3b63d7 --- /dev/null +++ b/libdino/src/service/pgp_manager.vala @@ -0,0 +1,54 @@ +using Gee; + +using Dino.Entities; + +namespace Dino { + public class PgpManager : StreamInteractionModule, Object { + public const string id = "pgp_manager"; + + public const string MESSAGE_ENCRYPTED = "pgp"; + + private StreamInteractor stream_interactor; + private Database db; + private HashMap<Jid, string> pgp_key_ids = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func); + + public static void start(StreamInteractor stream_interactor, Database db) { + PgpManager m = new PgpManager(stream_interactor, db); + stream_interactor.add_module(m); + } + + private PgpManager(StreamInteractor stream_interactor, Database db) { + this.stream_interactor = stream_interactor; + this.db = db; + + stream_interactor.account_added.connect(on_account_added); + } + + public string? get_key_id(Account account, Jid jid) { + return db.get_pgp_key(jid); + } + + public static PgpManager? get_instance(StreamInteractor stream_interactor) { + return (PgpManager) stream_interactor.get_module(id); + } + + internal string get_id() { + return id; + } + + private void on_account_added(Account account) { + stream_interactor.module_manager.pgp_modules[account].received_jid_key_id.connect((stream, jid, key_id) => { + on_jid_key_received(account, new Jid(jid), key_id); + }); + } + + private void on_jid_key_received(Account account, Jid jid, string key_id) { + if (!pgp_key_ids.has_key(jid) || pgp_key_ids[jid] != key_id) { + if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) { + db.set_pgp_key(jid.bare_jid, key_id); + } + } + pgp_key_ids[jid] = key_id; + } + } +}
\ No newline at end of file |