diff options
author | fiaxh <git@mx.ax.lt> | 2017-11-11 21:29:13 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-11-16 17:43:00 +0100 |
commit | 3f531d6b91edab6c79fa232143db828bad13853c (patch) | |
tree | 1083046c94e0b4a43cf16ac4a388fcea8ef91e84 /xmpp-vala/src/module/xep/0280_message_carbons.vala | |
parent | 1d0745177e7a116455811dfd26e07b848cb89b75 (diff) | |
download | dino-3f531d6b91edab6c79fa232143db828bad13853c.tar.gz dino-3f531d6b91edab6c79fa232143db828bad13853c.zip |
Read+(write) stream async
Diffstat (limited to 'xmpp-vala/src/module/xep/0280_message_carbons.vala')
-rw-r--r-- | xmpp-vala/src/module/xep/0280_message_carbons.vala | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala index b2d21646..930c5234 100644 --- a/xmpp-vala/src/module/xep/0280_message_carbons.vala +++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala @@ -18,43 +18,50 @@ namespace Xmpp.Xep.MessageCarbons { public override void attach(XmppStream stream) { stream.stream_negotiated.connect(enable); - stream.get_module(Message.Module.IDENTITY).pre_received_message.connect(pre_received_message); + stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); } public override void detach(XmppStream stream) { stream.stream_negotiated.disconnect(enable); - stream.get_module(Message.Module.IDENTITY).pre_received_message.disconnect(pre_received_message); } public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } + } + +public class ReceivedPipelineListener : StanzaListener<Message.Stanza> { + + private const string[] after_actions_const = {"EXTRACT_MESSAGE_1"}; - private void pre_received_message(XmppStream stream, Message.Stanza message) { - StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI); - StanzaNode? sent_node = received_node == null ? message.stanza.get_subnode("sent", NS_URI) : null; - StanzaNode? carbons_node = received_node != null ? received_node : sent_node; - if (carbons_node != null) { - StanzaNode? forwarded_node = carbons_node.get_subnode("forwarded", "urn:xmpp:forward:0"); - if (forwarded_node != null) { - StanzaNode? message_node = forwarded_node.get_subnode("message", Message.NS_URI); - string? from_attribute = message_node.get_attribute("from", Message.NS_URI); - // Any forwarded copies received by a Carbons-enabled client MUST be from that user's bare JID; any copies that do not meet this requirement MUST be ignored. - if (from_attribute != null && from_attribute == get_bare_jid(stream.get_flag(Bind.Flag.IDENTITY).my_jid)) { - if (received_node != null) { - message.add_flag(new MessageFlag(MessageFlag.TYPE_RECEIVED)); - } else if (sent_node != null) { - message.add_flag(new MessageFlag(MessageFlag.TYPE_SENT)); - } - message.stanza = message_node; - message.rerun_parsing = true; + public override string action_group { get { return "EXTRACT_MESSAGE_2"; } } + public override string[] after_actions { get { return after_actions_const; } } + + public override async void run(Core.XmppStream stream, Message.Stanza message) { + StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI); + StanzaNode? sent_node = received_node == null ? message.stanza.get_subnode("sent", NS_URI) : null; + StanzaNode? carbons_node = received_node != null ? received_node : sent_node; + if (carbons_node != null) { + StanzaNode? forwarded_node = carbons_node.get_subnode("forwarded", "urn:xmpp:forward:0"); + if (forwarded_node != null) { + StanzaNode? message_node = forwarded_node.get_subnode("message", Message.NS_URI); + string? from_attribute = message_node.get_attribute("from", Message.NS_URI); + // Any forwarded copies received by a Carbons-enabled client MUST be from that user's bare JID; any copies that do not meet this requirement MUST be ignored. + if (from_attribute != null && from_attribute == get_bare_jid(stream.get_flag(Bind.Flag.IDENTITY).my_jid)) { + if (received_node != null) { + message.add_flag(new MessageFlag(MessageFlag.TYPE_RECEIVED)); + } else if (sent_node != null) { + message.add_flag(new MessageFlag(MessageFlag.TYPE_SENT)); } message.stanza = message_node; message.rerun_parsing = true; } + message.stanza = message_node; + message.rerun_parsing = true; } } } +} public class MessageFlag : Message.MessageFlag { public const string ID = "message_carbons"; |