From 57c72d2818dec6c713834cfbb8c4c566a1602907 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 19 Jan 2018 22:37:02 +0100 Subject: Pipeline for incoming messages in libdino --- plugins/omemo/src/manager.vala | 19 ++++++++++++++----- plugins/omemo/src/stream_module.vala | 11 ++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'plugins/omemo') diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index 6c8ce4ef..f4c5ed0f 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -13,6 +13,7 @@ public class Manager : StreamInteractionModule, Object { private StreamInteractor stream_interactor; private Database db; private Map message_states = new HashMap(Entities.Message.hash_func, Entities.Message.equals_func); + private ReceivedMessageListener received_message_listener = new ReceivedMessageListener(); private class MessageState { public Entities.Message msg { get; private set; } @@ -65,14 +66,22 @@ public class Manager : StreamInteractionModule, Object { stream_interactor.stream_negotiated.connect(on_stream_negotiated); stream_interactor.account_added.connect(on_account_added); - stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_received.connect(on_pre_message_received); + stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(received_message_listener); stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(on_pre_message_send); } - private void on_pre_message_received(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation) { - MessageFlag? flag = MessageFlag.get_flag(message_stanza); - if (flag != null && ((!)flag).decrypted) { - message.encryption = Encryption.OMEMO; + private class ReceivedMessageListener : MessageListener { + + public string[] after_actions_const = new string[]{ "" }; + public override string action_group { get { return "DECRYPT"; } } + public override string[] after_actions { get { return after_actions_const; } } + + public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { + MessageFlag? flag = MessageFlag.get_flag(stanza); + if (flag != null && ((!)flag).decrypted) { + message.encryption = Encryption.OMEMO; + } + return false; } } diff --git a/plugins/omemo/src/stream_module.vala b/plugins/omemo/src/stream_module.vala index 0b5f4ea9..4494e834 100644 --- a/plugins/omemo/src/stream_module.vala +++ b/plugins/omemo/src/stream_module.vala @@ -397,17 +397,17 @@ public class ReceivedPipelineListener : StanzaListener { this.store = store; } - public override async void run(XmppStream stream, MessageStanza message) { + public override async bool run(XmppStream stream, MessageStanza message) { StanzaNode? _encrypted = message.stanza.get_subnode("encrypted", NS_URI); - if (_encrypted == null || MessageFlag.get_flag(message) != null || message.from == null) return; + if (_encrypted == null || MessageFlag.get_flag(message) != null || message.from == null) return false; StanzaNode encrypted = (!)_encrypted; - if (!Plugin.ensure_context()) return; + if (!Plugin.ensure_context()) return false; MessageFlag flag = new MessageFlag(); message.add_flag(flag); StanzaNode? _header = encrypted.get_subnode("header"); - if (_header == null) return; + if (_header == null) return false; StanzaNode header = (!)_header; - if (header.get_attribute_int("sid") <= 0) return; + if (header.get_attribute_int("sid") <= 0) return false; foreach (StanzaNode key_node in header.get_subnodes("key")) { if (key_node.get_attribute_int("rid") == store.local_registration_id) { try { @@ -448,6 +448,7 @@ public class ReceivedPipelineListener : StanzaListener { } } } + return false; } private string arr_to_str(uint8[] arr) { -- cgit v1.2.3-70-g09d2