aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2022-01-19 16:54:56 +0100
committerfiaxh <git@lightrise.org>2022-02-07 01:21:11 +0100
commit071d925e370b2238a9804733a484fe4ec9432f44 (patch)
treecd1fba934d8a7f88df771c1df6fa1a3b3fdcd26a /xmpp-vala
parent4ef50db3e581016365087759d5af8649e37ab8a7 (diff)
downloaddino-071d925e370b2238a9804733a484fe4ec9432f44.tar.gz
dino-071d925e370b2238a9804733a484fe4ec9432f44.zip
Add support for call invite messages
As of https://github.com/xsf/xeps/pull/1155
Diffstat (limited to 'xmpp-vala')
-rw-r--r--xmpp-vala/CMakeLists.txt2
-rw-r--r--xmpp-vala/src/module/xep/0334_message_processing_hints.vala8
-rw-r--r--xmpp-vala/src/module/xep/0353_call_invite_message.vala93
-rw-r--r--xmpp-vala/src/module/xep/muji_meta.vala117
4 files changed, 98 insertions, 122 deletions
diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt
index 27f0d408..5b767448 100644
--- a/xmpp-vala/CMakeLists.txt
+++ b/xmpp-vala/CMakeLists.txt
@@ -132,12 +132,12 @@ SOURCES
"src/module/xep/0333_chat_markers.vala"
"src/module/xep/0334_message_processing_hints.vala"
"src/module/xep/0353_jingle_message_initiation.vala"
+ "src/module/xep/0353_call_invite_message.vala"
"src/module/xep/0359_unique_stable_stanza_ids.vala"
"src/module/xep/0363_http_file_upload.vala"
"src/module/xep/0380_explicit_encryption.vala"
"src/module/xep/0391_jingle_encrypted_transports.vala"
"src/module/xep/0410_muc_self_ping.vala"
- "src/module/xep/muji_meta.vala"
"src/module/xep/pixbuf_storage.vala"
"src/util.vala"
diff --git a/xmpp-vala/src/module/xep/0334_message_processing_hints.vala b/xmpp-vala/src/module/xep/0334_message_processing_hints.vala
index 352e03ac..09fd7dd4 100644
--- a/xmpp-vala/src/module/xep/0334_message_processing_hints.vala
+++ b/xmpp-vala/src/module/xep/0334_message_processing_hints.vala
@@ -2,10 +2,10 @@ namespace Xmpp.Xep.MessageProcessingHints {
private const string NS_URI = "urn:xmpp:hints";
-private const string HINT_NO_PERMANENT_STORE = "no-permanent-store";
-private const string HINT_NO_STORE = "no-store";
-private const string HINT_NO_COPY = "no-copy";
-private const string HINT_STORE = "store";
+public const string HINT_NO_PERMANENT_STORE = "no-permanent-store";
+public const string HINT_NO_STORE = "no-store";
+public const string HINT_NO_COPY = "no-copy";
+public const string HINT_STORE = "store";
public static void set_message_hint(MessageStanza message, string message_hint) {
StanzaNode hint_node = (new StanzaNode.build(message_hint, NS_URI)).add_self_xmlns();
diff --git a/xmpp-vala/src/module/xep/0353_call_invite_message.vala b/xmpp-vala/src/module/xep/0353_call_invite_message.vala
new file mode 100644
index 00000000..806db5e7
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0353_call_invite_message.vala
@@ -0,0 +1,93 @@
+using Gee;
+namespace Xmpp.Xep.CallInvites {
+
+ public const string NS_URI = "urn:xmpp:call-invites:0";
+
+ public class Module : XmppStreamModule {
+ public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "call_invites");
+
+ public signal void call_proposed(Jid from, Jid to, bool video, Gee.List<StanzaNode> join_methods, MessageStanza message);
+ public signal void call_retracted(Jid from, Jid to, string invite_id, string message_type);
+ public signal void call_accepted(Jid from, string invite_id, string message_type);
+ public signal void call_rejected(Jid from, Jid to, string invite_id, string message_type);
+
+ public void send_invite(XmppStream stream, Jid invitee, Jid muc_jid, bool video, string message_type) {
+ StanzaNode muji_node = new StanzaNode.build("muji", Muji.NS_URI).add_self_xmlns().put_attribute("room", muc_jid.to_string());
+ StanzaNode invite_node = new StanzaNode.build("propose", NS_URI).add_self_xmlns()
+ .put_attribute("video", video.to_string())
+ .put_node(muji_node);
+ MessageStanza invite_message = new MessageStanza() { to=invitee, type_=message_type };
+ MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
+ invite_message.stanza.put_node(invite_node);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
+ }
+
+ public void send_retract(XmppStream stream, Jid to, string invite_id, string message_type) {
+ send_message(stream, "retract", to, invite_id, message_type);
+ }
+
+ public void send_accept(XmppStream stream, Jid to, string invite_id, string message_type) {
+ send_message(stream, "accept", to, invite_id, message_type);
+ }
+
+ public void send_reject(XmppStream stream, Jid to, string invite_id, string message_type) {
+ send_message(stream, "reject", to, invite_id, message_type);
+ }
+
+ private void send_message(XmppStream stream, string action, Jid to, string invite_id, string message_type) {
+ StanzaNode inner_node = new StanzaNode.build(action, NS_URI).add_self_xmlns().put_attribute("id", invite_id);
+ MessageStanza message = new MessageStanza() { to=to, type_=message_type };
+ message.stanza.put_node(inner_node);
+ MessageProcessingHints.set_message_hint(message, MessageProcessingHints.HINT_STORE);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message);
+ }
+
+ private void on_received_message(XmppStream stream, MessageStanza message) {
+ Xep.MessageArchiveManagement.MessageFlag? mam_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message);
+ if (mam_flag != null) return;
+
+ StanzaNode? relevant_node = null;
+
+ foreach (StanzaNode node in message.stanza.sub_nodes) {
+ if (node.ns_uri == NS_URI) {
+ relevant_node = node;
+ break;
+ }
+ }
+ if (relevant_node == null) return;
+
+ if (relevant_node.name == "propose") {
+ if (relevant_node.sub_nodes.is_empty) return;
+ bool video = relevant_node.get_attribute_bool("video", false);
+ call_proposed(message.from, message.to, video, relevant_node.sub_nodes, message);
+ return;
+ }
+
+ string? invite_id = relevant_node.get_attribute("id");
+ if (invite_id == null) return;
+
+ switch (relevant_node.name) {
+ case "accept":
+ call_accepted(message.from, invite_id, message.type_);
+ break;
+ case "retract":
+ call_retracted(message.from, message.to, invite_id, message.type_);
+ break;
+ case "reject":
+ call_rejected(message.from, message.to, invite_id, message.type_);
+ break;
+ }
+ }
+
+ public override void attach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
+ }
+
+ public override void detach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message);
+ }
+
+ public override string get_ns() { return NS_URI; }
+ public override string get_id() { return IDENTITY.id; }
+ }
+} \ No newline at end of file
diff --git a/xmpp-vala/src/module/xep/muji_meta.vala b/xmpp-vala/src/module/xep/muji_meta.vala
deleted file mode 100644
index fa161f28..00000000
--- a/xmpp-vala/src/module/xep/muji_meta.vala
+++ /dev/null
@@ -1,117 +0,0 @@
-using Gee;
-namespace Xmpp.Xep.MujiMeta {
-
- public const string NS_URI = "http://telepathy.freedesktop.org/muji";
-
- public class Module : XmppStreamModule {
- public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "muji_meta");
-
- public signal void call_proposed(Jid from, Jid to, Jid muc_jid, Gee.List<StanzaNode> descriptions, string message_type);
- public signal void call_retracted(Jid from, Jid to, Jid muc_jid, string message_type);
- public signal void call_accepted(Jid from, Jid muc_jid, string message_type);
- public signal void call_rejected(Jid from, Jid to, Jid muc_jid, string message_type);
-
- public void send_invite(XmppStream stream, Jid invitee, Jid muc_jid, bool video, string message_type) {
- var invite_node = new StanzaNode.build("propose", NS_URI).put_attribute("muc", muc_jid.to_string());
- invite_node.put_node(new StanzaNode.build("description", Xep.JingleRtp.NS_URI).add_self_xmlns().put_attribute("media", "audio"));
- if (video) {
- invite_node.put_node(new StanzaNode.build("description", Xep.JingleRtp.NS_URI).add_self_xmlns().put_attribute("media", "video"));
- }
- var muji_node = new StanzaNode.build("muji", NS_URI).add_self_xmlns().put_node(invite_node);
- MessageStanza invite_message = new MessageStanza() { to=invitee, type_=message_type };
- invite_message.stanza.put_node(muji_node);
- stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
- }
-
- public void send_invite_retract_to_peer(XmppStream stream, Jid invitee, Jid muc_jid, string message_type) {
- send_jmi_message(stream, "retract", invitee, muc_jid, message_type);
- }
-
- public void send_invite_accept_to_peer(XmppStream stream, Jid invitor, Jid muc_jid, string message_type) {
- send_jmi_message(stream, "accept", invitor, muc_jid, message_type);
- }
-
- public void send_invite_accept_to_self(XmppStream stream, Jid muc_jid) {
- send_jmi_message(stream, "accept", Bind.Flag.get_my_jid(stream).bare_jid, muc_jid, MessageStanza.TYPE_CHAT);
- }
-
- public void send_invite_reject_to_peer(XmppStream stream, Jid invitor, Jid muc_jid, string message_type) {
- send_jmi_message(stream, "reject", invitor, muc_jid, message_type);
- }
-
- public void send_invite_reject_to_self(XmppStream stream, Jid muc_jid) {
- send_jmi_message(stream, "reject", Bind.Flag.get_my_jid(stream).bare_jid, muc_jid, MessageStanza.TYPE_CHAT);
- }
-
- private void send_jmi_message(XmppStream stream, string name, Jid to, Jid muc, string message_type) {
- var jmi_node = new StanzaNode.build(name, NS_URI).add_self_xmlns().put_attribute("muc", muc.to_string());
- var muji_node = new StanzaNode.build("muji", NS_URI).add_self_xmlns().put_node(jmi_node);
-
- MessageStanza accepted_message = new MessageStanza() { to=to, type_= message_type ?? MessageStanza.TYPE_CHAT };
- accepted_message.stanza.put_node(muji_node);
- stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, accepted_message);
- }
-
- private void on_received_message(XmppStream stream, MessageStanza message) {
- Xep.MessageArchiveManagement.MessageFlag? mam_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message);
- if (mam_flag != null) return;
-
- var muji_node = message.stanza.get_subnode("muji", NS_URI);
- if (muji_node == null) return;
-
- StanzaNode? mi_node = null;
- foreach (StanzaNode node in muji_node.sub_nodes) {
- if (node.ns_uri == NS_URI) {
- mi_node = node;
- }
- }
- if (mi_node == null) return;
-
- string? jid_str = mi_node.get_attribute("muc");
- if (jid_str == null) return;
-
- Jid muc_jid = null;
- try {
- muc_jid = new Jid(jid_str);
- } catch (Error e) {
- return;
- }
-
- switch (mi_node.name) {
- case "accept":
- case "proceed":
- call_accepted(message.from, muc_jid, message.type_);
- break;
- case "propose":
- ArrayList<StanzaNode> descriptions = new ArrayList<StanzaNode>();
-
- foreach (StanzaNode node in mi_node.sub_nodes) {
- if (node.name != "description") continue;
- descriptions.add(node);
- }
-
- if (descriptions.size > 0) {
- call_proposed(message.from, message.to, muc_jid, descriptions, message.type_);
- }
- break;
- case "retract":
- call_retracted(message.from, message.to, muc_jid, message.type_);
- break;
- case "reject":
- call_rejected(message.from, message.to, muc_jid, message.type_);
- break;
- }
- }
-
- public override void attach(XmppStream stream) {
- stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
- }
-
- public override void detach(XmppStream stream) {
- stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message);
- }
-
- public override string get_ns() { return NS_URI; }
- public override string get_id() { return IDENTITY.id; }
- }
-} \ No newline at end of file