aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-19 12:55:36 +0100
committerfiaxh <git@mx.ax.lt>2017-03-20 22:28:27 +0100
commitdb57a973534f099af2b150f1a1307d1948553d9f (patch)
tree238ae1d4e53412a33e3febd07318dfd38b0eb2f8 /plugins/openpgp
parent233f2b35d033cd20d1ac648bf2d723bcb7a918fc (diff)
downloaddino-db57a973534f099af2b150f1a1307d1948553d9f.tar.gz
dino-db57a973534f099af2b150f1a1307d1948553d9f.zip
Add typed identity to manager modules and stream flags
Diffstat (limited to 'plugins/openpgp')
-rw-r--r--plugins/openpgp/src/encryption_list_entry.vala2
-rw-r--r--plugins/openpgp/src/manager.vala20
-rw-r--r--plugins/openpgp/src/stream_flag.vala9
-rw-r--r--plugins/openpgp/src/stream_module.vala7
4 files changed, 14 insertions, 24 deletions
diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala
index 96607e1e..9aac3db2 100644
--- a/plugins/openpgp/src/encryption_list_entry.vala
+++ b/plugins/openpgp/src/encryption_list_entry.vala
@@ -19,7 +19,7 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
}}
public bool can_encrypt(Entities.Conversation conversation) {
- return Manager.get_instance(stream_interactor).get_key_id(conversation.account, conversation.counterpart) != null;
+ return stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart) != null;
}
}
diff --git a/plugins/openpgp/src/manager.vala b/plugins/openpgp/src/manager.vala
index 0941362e..a261c2cb 100644
--- a/plugins/openpgp/src/manager.vala
+++ b/plugins/openpgp/src/manager.vala
@@ -7,7 +7,8 @@ using Dino.Entities;
namespace Dino.Plugins.OpenPgp {
public class Manager : StreamInteractionModule, Object {
- public const string id = "pgp_manager";
+ public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("pgp_manager");
+ public string id { get { return IDENTITY.id; } }
public const string MESSAGE_ENCRYPTED = "pgp";
@@ -25,8 +26,8 @@ namespace Dino.Plugins.OpenPgp {
this.db = db;
stream_interactor.account_added.connect(on_account_added);
- MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received);
- MessageManager.get_instance(stream_interactor).pre_message_send.connect(on_pre_message_send);
+ stream_interactor.get_module(MessageManager.IDENTITY).pre_message_received.connect(on_pre_message_received);
+ stream_interactor.get_module(MessageManager.IDENTITY).pre_message_send.connect(on_pre_message_send);
}
private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
@@ -40,7 +41,8 @@ namespace Dino.Plugins.OpenPgp {
string? key_id = get_key_id(conversation.account, message.counterpart);
bool encrypted = false;
if (key_id != null) {
- encrypted = stream_interactor.get_stream(conversation.account).get_module(Module.IDENTITY).encrypt(message_stanza, key_id);
+ Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
+ if (stream != null) encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, key_id);
}
if (!encrypted) {
message.marked = Entities.Message.Marked.WONTSEND;
@@ -52,14 +54,6 @@ namespace Dino.Plugins.OpenPgp {
return db.get_contact_key(jid);
}
- public static Manager? get_instance(StreamInteractor stream_interactor) {
- return (Manager) stream_interactor.get_module(id);
- }
-
- internal string get_id() {
- return id;
- }
-
private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Module.IDENTITY).received_jid_key_id.connect((stream, jid, key_id) => {
on_jid_key_received(account, new Jid(jid), key_id);
@@ -69,7 +63,7 @@ namespace Dino.Plugins.OpenPgp {
private void on_jid_key_received(Account account, Jid jid, string key_id) {
lock (pgp_key_ids) {
if (!pgp_key_ids.has_key(jid) || pgp_key_ids[jid] != key_id) {
- if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) {
+ if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
db.set_contact_key(jid.bare_jid, key_id);
}
}
diff --git a/plugins/openpgp/src/stream_flag.vala b/plugins/openpgp/src/stream_flag.vala
index 5ace26bd..165327b9 100644
--- a/plugins/openpgp/src/stream_flag.vala
+++ b/plugins/openpgp/src/stream_flag.vala
@@ -6,20 +6,17 @@ using Xmpp.Core;
namespace Dino.Plugins.OpenPgp {
public class Flag : XmppStreamFlag {
- public const string ID = "pgp";
+ public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "pgp");
+
public HashMap<string, string> key_ids = new HashMap<string, string>();
public string? get_key_id(string jid) { return key_ids[get_bare_jid(jid)]; }
public void set_key_id(string jid, string key) { key_ids[get_bare_jid(jid)] = key; }
- public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); }
-
- public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; }
-
public override string get_ns() { return NS_URI; }
- public override string get_id() { return ID; }
+ public override string get_id() { return IDENTITY.id; }
}
} \ No newline at end of file
diff --git a/plugins/openpgp/src/stream_module.vala b/plugins/openpgp/src/stream_module.vala
index 6de97066..b9742624 100644
--- a/plugins/openpgp/src/stream_module.vala
+++ b/plugins/openpgp/src/stream_module.vala
@@ -9,8 +9,7 @@ namespace Dino.Plugins.OpenPgp {
private const string NS_URI_SIGNED = NS_URI + ":signed";
public class Module : XmppStreamModule {
- public const string ID = "0027_current_pgp_usage";
- public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID);
+ public static Core.ModuleIdentity<Module> IDENTITY = new Core.ModuleIdentity<Module>(NS_URI, "0027_current_pgp_usage");
public signal void received_jid_key_id(XmppStream stream, string jid, string key_id);
@@ -69,7 +68,7 @@ namespace Dino.Plugins.OpenPgp {
}
public override string get_ns() { return NS_URI; }
- public override string get_id() { return ID; }
+ public override string get_id() { return IDENTITY.id; }
private void on_received_presence(XmppStream stream, Presence.Stanza presence) {
StanzaNode x_node = presence.stanza.get_subnode("x", NS_URI_SIGNED);
@@ -79,7 +78,7 @@ namespace Dino.Plugins.OpenPgp {
string signed_data = presence.status == null ? "" : presence.status;
string? key_id = get_sign_key(sig, signed_data);
if (key_id != null) {
- Flag.get_flag(stream).set_key_id(presence.from, key_id);
+ stream.get_flag(Flag.IDENTITY).set_key_id(presence.from, key_id);
received_jid_key_id(stream, presence.from, key_id);
}
}