aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2018-01-19 22:37:02 +0100
committerfiaxh <git@mx.ax.lt>2018-01-28 13:37:53 +0100
commit57c72d2818dec6c713834cfbb8c4c566a1602907 (patch)
tree0f7102171049cce6f6732b658d005b3c57140271 /xmpp-vala/src/module
parentca331e85efe2a74a6b9b5a5ff0fbcd10a36758ce (diff)
downloaddino-57c72d2818dec6c713834cfbb8c4c566a1602907.tar.gz
dino-57c72d2818dec6c713834cfbb8c4c566a1602907.zip
Pipeline for incoming messages in libdino
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r--xmpp-vala/src/module/message/module.vala1
-rw-r--r--xmpp-vala/src/module/util.vala47
-rw-r--r--xmpp-vala/src/module/xep/0085_chat_state_notifications.vala9
-rw-r--r--xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala9
-rw-r--r--xmpp-vala/src/module/xep/0203_delayed_delivery.vala3
-rw-r--r--xmpp-vala/src/module/xep/0280_message_carbons.vala16
-rw-r--r--xmpp-vala/src/module/xep/0313_message_archive_management.vala5
-rw-r--r--xmpp-vala/src/module/xep/0333_chat_markers.vala9
8 files changed, 56 insertions, 43 deletions
diff --git a/xmpp-vala/src/module/message/module.vala b/xmpp-vala/src/module/message/module.vala
index cfb1d750..864b4f71 100644
--- a/xmpp-vala/src/module/message/module.vala
+++ b/xmpp-vala/src/module/message/module.vala
@@ -11,7 +11,6 @@ namespace Xmpp {
public StanzaListenerHolder<MessageStanza> received_pipeline = new StanzaListenerHolder<MessageStanza>();
public StanzaListenerHolder<MessageStanza> send_pipeline = new StanzaListenerHolder<MessageStanza>();
- public signal void pre_received_message(XmppStream stream, MessageStanza message);
public signal void received_message(XmppStream stream, MessageStanza message);
public void send_message(XmppStream stream, MessageStanza message) {
diff --git a/xmpp-vala/src/module/util.vala b/xmpp-vala/src/module/util.vala
index 1043dee1..02f391ae 100644
--- a/xmpp-vala/src/module/util.vala
+++ b/xmpp-vala/src/module/util.vala
@@ -12,34 +12,42 @@ public string random_uuid() {
return "%08x-%04x-%04x-%04x-%04x%08x".printf(b1, b2, b3, b4, b5_1, b5_2);
}
-public abstract class StanzaListener<T> : Object {
+public abstract class StanzaListener<T> : OrderedListener {
+
+ public abstract async bool run(XmppStream stream, T stanza);
+}
+
+public class StanzaListenerHolder<T> : ListenerHolder {
+
+ public async void run(XmppStream stream, T stanza) {
+ foreach (OrderedListener ol in listeners) {
+ StanzaListener<T> l = ol as StanzaListener<T>;
+ bool stop = yield l.run(stream, stanza);
+ if (stop) break;
+ }
+ }
+}
+
+public abstract class OrderedListener : Object {
public abstract string action_group { get; }
public abstract string[] after_actions { get; }
-
- public abstract async void run(XmppStream stream, T stanza);
}
-public class StanzaListenerHolder<T> : Object {
- private ArrayList<StanzaListener<T>> listeners = new ArrayList<StanzaListener<T>>();
+public abstract class ListenerHolder : Object {
+ protected ArrayList<OrderedListener> listeners = new ArrayList<OrderedListener>();
- public new void connect(StanzaListener<T> listener) {
+ public new void connect(OrderedListener listener) {
listeners.add(listener);
resort_list();
}
- public new void disconnect(StanzaListener<T> listener) {
+ public new void disconnect(OrderedListener listener) {
listeners.remove(listener);
resort_list();
}
- public async void run(XmppStream stream, T stanza) {
- foreach (StanzaListener<T> l in listeners) {
- yield l.run(stream, stanza);
- }
- }
-
- private bool set_contains_action(Gee.List<StanzaListener<T>> s, string[] actions) {
- foreach (StanzaListener<T> l in s) {
+ private bool set_contains_action(Gee.List<OrderedListener> s, string[] actions) {
+ foreach(OrderedListener l in s) {
if (l.action_group in actions) {
return true;
}
@@ -48,22 +56,23 @@ public class StanzaListenerHolder<T> : Object {
}
private void resort_list() {
- ArrayList<StanzaListener<T>> new_list = new ArrayList<StanzaListener<T>>();
- ArrayList<StanzaListener<T>> remaining = new ArrayList<StanzaListener<T>>();
+ ArrayList<OrderedListener> new_list = new ArrayList<OrderedListener>();
+ ArrayList<OrderedListener> remaining = new ArrayList<OrderedListener>();
remaining.add_all(listeners);
while (remaining.size > 0) {
bool changed = false;
- Gee.Iterator<StanzaListener<T>> iter = remaining.iterator();
+ Gee.Iterator<OrderedListener> iter = remaining.iterator();
while (iter.has_next()) {
if (!iter.valid) {
iter.next();
}
- StanzaListener<T> l = iter.get();
+ OrderedListener l = iter.get();
if (!set_contains_action(remaining, l.after_actions)) {
new_list.add(l);
iter.remove();
changed = true;
}
+ iter.next();
}
if (!changed) error("Can't sort 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 cc18c52f..9d23c716 100644
--- a/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala
+++ b/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala
@@ -9,7 +9,7 @@ public const string STATE_GONE = "gone";
public const string STATE_COMPOSING = "composing";
public const string STATE_PAUSED = "paused";
-private const string[] STATES = {STATE_ACTIVE, STATE_INACTIVE, STATE_GONE, STATE_COMPOSING, STATE_PAUSED};
+private const string[] STATES = { STATE_ACTIVE, STATE_INACTIVE, STATE_GONE, STATE_COMPOSING, STATE_PAUSED };
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0085_chat_state_notifications");
@@ -63,10 +63,11 @@ public class SendPipelineListener : StanzaListener<MessageStanza> {
public override string action_group { get { return "ADD_NODES"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(XmppStream stream, MessageStanza message) {
- if (message.body == null) return;
- if (message.type_ != MessageStanza.TYPE_CHAT) return;
+ public override async bool run(XmppStream stream, MessageStanza message) {
+ if (message.body == null) return false;
+ if (message.type_ != MessageStanza.TYPE_CHAT) return false;
message.stanza.put_node(new StanzaNode.build(STATE_ACTIVE, NS_URI).add_self_xmlns());
+ return false;
}
}
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 5e3cb320..b51178c7 100644
--- a/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala
+++ b/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala
@@ -48,12 +48,13 @@ public class SendPipelineListener : StanzaListener<MessageStanza> {
public override string action_group { get { return "ADD_NODES"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(XmppStream stream, MessageStanza message) {
+ public override async bool run(XmppStream stream, MessageStanza message) {
StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI);
- if (received_node != null) return;
- if (message.body == null) return;
- if (message.type_ == MessageStanza.TYPE_GROUPCHAT) return;
+ if (received_node != null) return false;
+ if (message.body == null) return false;
+ if (message.type_ == MessageStanza.TYPE_GROUPCHAT) return false;
message.stanza.put_node(new StanzaNode.build("request", NS_URI).add_self_xmlns());
+ return false;
}
}
diff --git a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala
index 8581ed93..39666fa8 100644
--- a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala
+++ b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala
@@ -51,9 +51,10 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
public override string action_group { get { return "ADD_NODE"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(XmppStream stream, MessageStanza message) {
+ public override async bool run(XmppStream stream, MessageStanza message) {
DateTime? datetime = Module.get_time_for_message(message);
if (datetime != null) message.add_flag(new MessageFlag(datetime));
+ return false;
}
}
diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala
index 9e85a607..fca35606 100644
--- a/xmpp-vala/src/module/xep/0280_message_carbons.vala
+++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala
@@ -44,7 +44,7 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
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(XmppStream stream, MessageStanza message) {
+ public override async bool run(XmppStream stream, MessageStanza 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;
@@ -55,18 +55,18 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
string? from_attribute = message_node.get_attribute("from", Xmpp.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 == stream.get_flag(Bind.Flag.IDENTITY).my_jid.bare_jid.to_string()) {
- 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;
+ return true;
+ }
+ 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;
}
}
+ return false;
}
}
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 1c1b51e3..343a5fbd 100644
--- a/xmpp-vala/src/module/xep/0313_message_archive_management.vala
+++ b/xmpp-vala/src/module/xep/0313_message_archive_management.vala
@@ -91,9 +91,9 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
public override string action_group { get { return "EXTRACT_MESSAGE_1"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(XmppStream stream, MessageStanza message) {
+ public override async bool run(XmppStream stream, MessageStanza message) {
// if (message.from != stream.remote_name) return;
- if (stream.get_flag(Flag.IDENTITY) == null) return;
+ if (stream.get_flag(Flag.IDENTITY) == null) return false;
StanzaNode? message_node = message.stanza.get_deep_subnode(NS_VER(stream) + ":result", "urn:xmpp:forward:0:forwarded", Xmpp.NS_URI + ":message");
if (message_node != null) {
@@ -104,6 +104,7 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
message.stanza = message_node;
message.rerun_parsing = true;
}
+ return false;
}
}
diff --git a/xmpp-vala/src/module/xep/0333_chat_markers.vala b/xmpp-vala/src/module/xep/0333_chat_markers.vala
index 2cba957a..d5f46c43 100644
--- a/xmpp-vala/src/module/xep/0333_chat_markers.vala
+++ b/xmpp-vala/src/module/xep/0333_chat_markers.vala
@@ -61,12 +61,13 @@ public class SendPipelineListener : StanzaListener<MessageStanza> {
public override string action_group { get { return "ADD_NODES"; } }
public override string[] after_actions { get { return after_actions_const; } }
- public override async void run(XmppStream stream, MessageStanza message) {
+ public override async bool run(XmppStream stream, MessageStanza message) {
StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI);
- if (received_node != null) return;
- if (message.body == null) return;
- if (message.type_ != MessageStanza.TYPE_CHAT) return;
+ if (received_node != null) return false;
+ if (message.body == null) return false;
+ if (message.type_ != MessageStanza.TYPE_CHAT) return false;
message.stanza.put_node(new StanzaNode.build("markable", NS_URI).add_self_xmlns());
+ return false;
}
}