aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-08-22 16:05:28 +0200
committerfiaxh <git@lightrise.org>2019-08-22 16:05:28 +0200
commit130965f322ea58d3d2bbce5ee6ac31dae2d3a659 (patch)
tree1ece66670d82eac674ee82ebe84a7ca487047d69 /xmpp-vala/src/module/xep
parent0521afa3d828ea0dfc79e6c5c76697e2a3a270c0 (diff)
downloaddino-130965f322ea58d3d2bbce5ee6ac31dae2d3a659.tar.gz
dino-130965f322ea58d3d2bbce5ee6ac31dae2d3a659.zip
Add incoming mediated invitation support (#162)
Co-authored-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Diffstat (limited to 'xmpp-vala/src/module/xep')
-rw-r--r--xmpp-vala/src/module/xep/0045_muc/module.vala48
-rw-r--r--xmpp-vala/src/module/xep/0363_http_file_upload.vala2
2 files changed, 49 insertions, 1 deletions
diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala
index 7b136d8c..db7a299f 100644
--- a/xmpp-vala/src/module/xep/0045_muc/module.vala
+++ b/xmpp-vala/src/module/xep/0045_muc/module.vala
@@ -61,12 +61,19 @@ public class Module : XmppStreamModule {
public signal void received_occupant_role(XmppStream stream, Jid jid, Role? role);
public signal void subject_set(XmppStream stream, string? subject, Jid jid);
public signal void room_name_set(XmppStream stream, Jid jid, string? room_name);
+ public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void room_entered(XmppStream stream, Jid jid, string nick);
public signal void room_enter_error(XmppStream stream, Jid jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday
public signal void self_removed_from_room(XmppStream stream, Jid jid, StatusCode code);
public signal void removed_from_room(XmppStream stream, Jid jid, StatusCode? code);
+ private ReceivedPipelineListener received_pipeline_listener;
+
+ public Module() {
+ received_pipeline_listener = new ReceivedPipelineListener(this);
+ }
+
public void enter(XmppStream stream, Jid bare_jid, string nick, string? password, DateTime? history_since) {
Presence.Stanza presence = new Presence.Stanza();
presence.to = bare_jid.with_resource(nick);
@@ -175,6 +182,7 @@ public class Module : XmppStreamModule {
public override void attach(XmppStream stream) {
stream.add_flag(new Flag());
stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
+ stream.get_module(MessageModule.IDENTITY).received_pipeline.connect(received_pipeline_listener);
stream.get_module(Presence.Module.IDENTITY).received_presence.connect(check_for_enter_error);
stream.get_module(Presence.Module.IDENTITY).received_available.connect(on_received_available);
stream.get_module(Presence.Module.IDENTITY).received_unavailable.connect(on_received_unavailable);
@@ -191,6 +199,7 @@ public class Module : XmppStreamModule {
public override void detach(XmppStream stream) {
stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message);
+ stream.get_module(MessageModule.IDENTITY).received_pipeline.disconnect(received_pipeline_listener);
stream.get_module(Presence.Module.IDENTITY).received_presence.disconnect(check_for_enter_error);
stream.get_module(Presence.Module.IDENTITY).received_available.disconnect(on_received_available);
stream.get_module(Presence.Module.IDENTITY).received_unavailable.disconnect(on_received_unavailable);
@@ -429,4 +438,43 @@ public class Module : XmppStreamModule {
}
}
+public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
+
+ private const string[] after_actions_const = {"EXTRACT_MESSAGE_2"};
+
+ public override string action_group { get { return ""; } }
+ public override string[] after_actions { get { return after_actions_const; } }
+
+ Module outer;
+
+ public ReceivedPipelineListener(Module outer) {
+ this.outer = outer;
+ }
+
+ public override async bool run(XmppStream stream, MessageStanza message) {
+ if (message.type_ == MessageStanza.TYPE_NORMAL) {
+ StanzaNode? x_node = message.stanza.get_subnode("x", NS_URI_USER);
+ if (x_node != null) {
+ StanzaNode? invite_node = x_node.get_subnode("invite", NS_URI_USER);
+ string? password = null;
+ StanzaNode? password_node = x_node.get_subnode("password", NS_URI_USER);
+ if (password_node != null)
+ password = password_node.get_string_content();
+ if (invite_node != null) {
+ string? from_jid = invite_node.get_attribute("from");
+ if (from_jid != null) {
+ StanzaNode? reason_node = invite_node.get_subnode("reason", NS_URI_USER);
+ string? reason = null;
+ if (reason_node != null)
+ reason = reason_node.get_string_content();
+ outer.invite_received(stream, message.from, new Jid(from_jid), password, reason);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
+
}
diff --git a/xmpp-vala/src/module/xep/0363_http_file_upload.vala b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
index 822ddc6b..8829ad15 100644
--- a/xmpp-vala/src/module/xep/0363_http_file_upload.vala
+++ b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
@@ -166,7 +166,7 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
if (oob_url != null && oob_url == message.body) {
stream.get_module(Module.IDENTITY).received_url(stream, message);
}
- return true;
+ return false;
}
}