aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-01-12 23:10:45 +0100
committerfiaxh <git@lightrise.org>2021-01-12 23:10:45 +0100
commit59236ec01a55a6316befad5101ec95314fac42fa (patch)
tree2981fb2209707f42b84ffb4e4baf908c7f6fdc00 /xmpp-vala
parentfc18e781a5c8d6fda52ecc5f4b4da96944f969a5 (diff)
downloaddino-59236ec01a55a6316befad5101ec95314fac42fa.tar.gz
dino-59236ec01a55a6316befad5101ec95314fac42fa.zip
Add support for Direct MUC Invitations (XEP-0249)
Diffstat (limited to 'xmpp-vala')
-rw-r--r--xmpp-vala/CMakeLists.txt1
-rw-r--r--xmpp-vala/src/module/xep/0249_direct_muc_invitations.vala55
2 files changed, 56 insertions, 0 deletions
diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt
index 5778c2de..fcc74fdc 100644
--- a/xmpp-vala/CMakeLists.txt
+++ b/xmpp-vala/CMakeLists.txt
@@ -88,6 +88,7 @@ SOURCES
"src/module/xep/0199_ping.vala"
"src/module/xep/0203_delayed_delivery.vala"
"src/module/xep/0234_jingle_file_transfer.vala"
+ "src/module/xep/0249_direct_muc_invitations.vala"
"src/module/xep/0260_jingle_socks5_bytestreams.vala"
"src/module/xep/0261_jingle_in_band_bytestreams.vala"
"src/module/xep/0280_message_carbons.vala"
diff --git a/xmpp-vala/src/module/xep/0249_direct_muc_invitations.vala b/xmpp-vala/src/module/xep/0249_direct_muc_invitations.vala
new file mode 100644
index 00000000..2ccab33d
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0249_direct_muc_invitations.vala
@@ -0,0 +1,55 @@
+namespace Xmpp.Xep.DirectMucInvitations {
+
+ private const string NS_URI = "jabber:x:conference";
+
+ public class Module : XmppStreamModule {
+ public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0249_direct_muc_invitations");
+
+ public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason);
+
+ public void invite(XmppStream stream, Jid to_muc, Jid jid) {
+ MessageStanza message = new MessageStanza() { to=jid };
+ StanzaNode invite_node = new StanzaNode.build("x", NS_URI).add_self_xmlns()
+ .put_attribute("jid", to_muc.to_string());
+ message.stanza.put_node(invite_node);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message);
+ }
+
+ private void received_message(XmppStream stream, MessageStanza message) {
+ StanzaNode? x_node = message.stanza.get_subnode("x", NS_URI);
+ if (x_node == null) return;
+
+ string? room_str = x_node.get_attribute("jid", NS_URI);
+ if (room_str == null) return;
+ Jid? room_jid = null;
+ try {
+ room_jid = new Jid(room_str);
+ } catch (Error e) {
+ return;
+ }
+ if (room_jid == null) return;
+
+ string? password = x_node.get_attribute("password", NS_URI);
+ string? reason = x_node.get_attribute("reason", NS_URI);
+
+ invite_received(stream, room_jid, message.from, password, reason);
+ }
+
+ public override void attach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.connect(received_message);
+ }
+
+ public override void detach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.connect(received_message);
+ }
+
+ public override string get_ns() {
+ return NS_URI;
+ }
+
+ public override string get_id() {
+ return IDENTITY.id;
+ }
+ }
+
+}