From de133218dab0ac1729dbfc32177979133c15f53b Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 21 Nov 2017 23:27:27 +0100 Subject: Disconnect stanza listeners from pipeline --- xmpp-vala/src/module/util.vala | 9 +++++++-- xmpp-vala/src/module/xep/0085_chat_state_notifications.vala | 5 ++++- xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala | 5 ++++- xmpp-vala/src/module/xep/0203_delayed_delivery.vala | 8 ++++++-- xmpp-vala/src/module/xep/0280_message_carbons.vala | 5 ++++- xmpp-vala/src/module/xep/0313_message_archive_management.vala | 8 ++++++-- xmpp-vala/src/module/xep/0333_chat_markers.vala | 5 ++++- 7 files changed, 35 insertions(+), 10 deletions(-) (limited to 'xmpp-vala/src') diff --git a/xmpp-vala/src/module/util.vala b/xmpp-vala/src/module/util.vala index e6626049..812b09ad 100644 --- a/xmpp-vala/src/module/util.vala +++ b/xmpp-vala/src/module/util.vala @@ -30,13 +30,18 @@ public abstract class StanzaListener : Object { } public class StanzaListenerHolder : Object { - private Gee.List> listeners = new ArrayList>(); + private ArrayList> listeners = new ArrayList>(); public new void connect(StanzaListener listener) { listeners.add(listener); resort_list(); } + public new void disconnect(StanzaListener listener) { + listeners.remove(listener); + resort_list(); + } + public async void run(Core.XmppStream stream, T stanza) { foreach (StanzaListener l in listeners) { yield l.run(stream, stanza); @@ -63,7 +68,7 @@ public class StanzaListenerHolder : Object { } private void resort_list() { - Gee.List> new_list = new ArrayList>(); + ArrayList> new_list = new ArrayList>(); while (listeners.size > new_list.size) { bool changed = false; foreach (StanzaListener l in listeners) { diff --git a/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala b/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala index 3ca97282..e92763fb 100644 --- a/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala +++ b/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala @@ -18,6 +18,8 @@ public class Module : XmppStreamModule { public signal void chat_state_received(XmppStream stream, string jid, string state); + private SendPipelineListener send_pipeline_listener = new SendPipelineListener(); + /** * "A message stanza that does not contain standard messaging content [...] SHOULD be a state other than " (0085, 5.6) */ @@ -31,12 +33,13 @@ public class Module : XmppStreamModule { public override void attach(XmppStream stream) { stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); - stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); + stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener); stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message); } public override void detach(XmppStream stream) { stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message); + stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener); } public override string get_ns() { return NS_URI; } diff --git a/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala b/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala index c9cb2d40..826b8726 100644 --- a/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala +++ b/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala @@ -8,6 +8,8 @@ namespace Xmpp.Xep.MessageDeliveryReceipts { public signal void receipt_received(XmppStream stream, string jid, string id); + private SendPipelineListener send_pipeline_listener = new SendPipelineListener(); + public void send_received(XmppStream stream, string from, string message_id) { Message.Stanza received_message = new Message.Stanza(); received_message.to = from; @@ -22,11 +24,12 @@ namespace Xmpp.Xep.MessageDeliveryReceipts { public override void attach(XmppStream stream) { stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); stream.get_module(Message.Module.IDENTITY).received_message.connect(received_message); - stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); + stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener); } public override void detach(XmppStream stream) { stream.get_module(Message.Module.IDENTITY).received_message.disconnect(received_message); + stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener); } public override string get_ns() { return NS_URI; } diff --git a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala index 89c761f2..b36932b0 100644 --- a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala +++ b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala @@ -6,6 +6,8 @@ namespace Xmpp.Xep.DelayedDelivery { public class Module : XmppStreamModule { public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "0203_delayed_delivery"); + private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener(); + public static void set_message_delay(Message.Stanza message, DateTime datetime) { StanzaNode delay_node = (new StanzaNode.build("delay", NS_URI)).add_self_xmlns(); delay_node.put_attribute("stamp", DateTimeProfiles.to_datetime(datetime)); @@ -27,10 +29,12 @@ namespace Xmpp.Xep.DelayedDelivery { } public override void attach(XmppStream stream) { - stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); + stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener); } - public override void detach(XmppStream stream) { } + public override void detach(XmppStream stream) { + stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener); + } public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala index 930c5234..8dc4e00c 100644 --- a/xmpp-vala/src/module/xep/0280_message_carbons.vala +++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala @@ -6,6 +6,8 @@ namespace Xmpp.Xep.MessageCarbons { public class Module : XmppStreamModule { public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "0280_message_carbons_module"); + private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener(); + public void enable(XmppStream stream) { Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns()); stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq); @@ -18,12 +20,13 @@ namespace Xmpp.Xep.MessageCarbons { public override void attach(XmppStream stream) { stream.stream_negotiated.connect(enable); - stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); + stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener); 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).received_pipeline.disconnect(received_pipeline_listener); } public override string get_ns() { return NS_URI; } diff --git a/xmpp-vala/src/module/xep/0313_message_archive_management.vala b/xmpp-vala/src/module/xep/0313_message_archive_management.vala index ac68e190..0e3ac0c7 100644 --- a/xmpp-vala/src/module/xep/0313_message_archive_management.vala +++ b/xmpp-vala/src/module/xep/0313_message_archive_management.vala @@ -14,6 +14,8 @@ public class Module : XmppStreamModule { public signal void feature_available(XmppStream stream); + private ReceivedPipelineListener received_pipeline_listener = new ReceivedPipelineListener(); + public void query_archive(XmppStream stream, string? jid, DateTime? start, DateTime? end) { if (stream.get_flag(Flag.IDENTITY) == null) return; @@ -42,11 +44,13 @@ public class Module : XmppStreamModule { } public override void attach(XmppStream stream) { - stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(new ReceivedPipelineListener()); + stream.get_module(Message.Module.IDENTITY).received_pipeline.connect(received_pipeline_listener); stream.stream_negotiated.connect(query_availability); } - public override void detach(XmppStream stream) { } + public override void detach(XmppStream stream) { + stream.get_module(Message.Module.IDENTITY).received_pipeline.disconnect(received_pipeline_listener); + } public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } diff --git a/xmpp-vala/src/module/xep/0333_chat_markers.vala b/xmpp-vala/src/module/xep/0333_chat_markers.vala index 9c3251dc..27cbd107 100644 --- a/xmpp-vala/src/module/xep/0333_chat_markers.vala +++ b/xmpp-vala/src/module/xep/0333_chat_markers.vala @@ -16,6 +16,8 @@ public class Module : XmppStreamModule { public signal void marker_received(XmppStream stream, string jid, string marker, string id); + private SendPipelineListener send_pipeline_listener = new SendPipelineListener(); + public void send_marker(XmppStream stream, string jid, string message_id, string type_, string marker) { Message.Stanza received_message = new Message.Stanza(); received_message.to = jid; @@ -31,12 +33,13 @@ public class Module : XmppStreamModule { public override void attach(XmppStream stream) { stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI); - stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(new SendPipelineListener()); + stream.get_module(Message.Module.IDENTITY).send_pipeline.connect(send_pipeline_listener); stream.get_module(Message.Module.IDENTITY).received_message.connect(on_received_message); } public override void detach(XmppStream stream) { stream.get_module(Message.Module.IDENTITY).received_message.disconnect(on_received_message); + stream.get_module(Message.Module.IDENTITY).send_pipeline.disconnect(send_pipeline_listener); } public override string get_ns() { return NS_URI; } -- cgit v1.2.3-70-g09d2