From cd68dfa58339b3107a6ad922866782c994be59ed Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Sat, 20 Feb 2021 20:33:46 +0100 Subject: [PATCH] mod_mix: Various things - Start working on MIX Anon - Fix a TODO --- mod_mix/mod_mix.lua | 66 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/mod_mix/mod_mix.lua b/mod_mix/mod_mix.lua index a36fec4..bdf7e73 100644 --- a/mod_mix/mod_mix.lua +++ b/mod_mix/mod_mix.lua @@ -1,6 +1,5 @@ -- Big TODOlist -- TODO: Channel:is_subscribed could be replaced by get_pep_service(...):get_subscription --- TODO: All channels[i] can probably safely be replaced with channel. local host = module:get_host(); if module:get_host_type() ~= "component" then @@ -24,6 +23,7 @@ Participant = mixlib.Participant; -- XML namespaces local mix_core_xmlns = "urn:xmpp:mix:core:1"; +local mix_anon_xmlns = "urn:xmpp:mix:anon:0"; --local mix_admin_xmlns = "urn:xmpp:mix:admin:0"; local mix_node_messages = "urn:xmpp:mix:nodes:messages"; local mix_node_participants = "urn:xmpp:mix:nodes:participants"; @@ -44,13 +44,23 @@ local default_channel_description = module:get_option("default_description", "A local default_channel_name = module:get_option("default_name", "MIX channel"); local restrict_channel_creation = module:get_option("restrict_local_channels", "local"); --- MAM stuff +-- Dataforms +-- MAM local mam_query_form = dataforms.new({ { name = "FORM_TYPE", type = "hidden", value = mam_xmlns }, { name = "with", type = "jid-single" }, { name = "start", type = "text-single" }, { name = "end", type = "text-single" }, }); +-- MIX Anon +local mix_anon_form = dataforms.new({ + { name = "FORM_TYPE", type = "hidden", value = mix_anon_xmlns }, + { name = "JID Visibility", type = "text-single" }, + { name = "Private Messages", type = "text-single" }, + { name = "Presence", type = "text-single" }, + { name = "vCard", type = "text-single" }, +}); + -- MIX-ADMIN stuff --[[ @@ -358,11 +368,11 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event) srv:remove_subscription(node, true, from); module:log("debug", "Unsubscribed %s from %s on %s", from, node, channel.jid); end - channels[i].subscriptions[from] = nil; + channel.subscriptions[from] = nil; -- Retracting the participation srv:retract("urn:xmpp:mix:nodes:participants", true, channel:get_spid(from), true); -- Removing the user - table.remove(channels[i].participants, j); + table.remove(channel.participants, j); channel:save_state(); origin.send(st.reply(stanza):tag("leave", { xmlns = mix_core_xmlns })); @@ -430,14 +440,50 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event) return true; end - local participant = Participant:new(jid.bare(from), nick); - channels[i].subscriptions[from] = nodes; - table.insert(channels[i].participants, participant) - channels[i]:set_spid(jid.bare(stanza.attr.from), spid); + -- TODO: Make the default configurable + local jid_visibility = "never"; -- default + local allow_pms = "allow"; + local allow_vcards = "block"; + local share_presence = "share"; + local x = join:get_child("x", "jabber:x:data"); + if x ~= nil then + -- TODO: Rethink naming + -- TODO: Error handling? + local form, err = mix_anon_form:data(x); + if form["JID Visibility"] then + jid_visibility = form["JID Visibility"]; + end + if form["Private Messages"] then + allow_pms = form["Private Messages"]; + end + if form["Presence"] then + share_presence = form["Presence"]; + end + if form["vCard"] then + allow_vcards = form["vCard"]; + end + end + + local participant = Participant:new(jid.bare(from), nick, jid_visibility, allow_pms, share_presence, allow_vcards); + channel.subscriptions[from] = nodes; + table.insert(channel.participants, participant) + channel:set_spid(jid.bare(stanza.attr.from), spid); publish_participant(srv, channel, spid, participant); - channels[i]:save_state(); + channel:save_state(); reply:add_child(nick); + reply:tag("x", { xmlns = "jabber:x:data", type = "result" }) + :tag("field", { var = "FORM_TYPE", type = "hidden" }) + :tag("value"):text(mix_anon_xmlns):up():up() + :tag("field", { var = "JID Visibility"}) + :tag("value"):text(jid_visibility):up():up() + :tag("field", { var = "Private Messages"}) + :tag("value"):text(allow_pms):up():up() + :tag("field", { var = "Presence"}) + :tag("value"):text(share_presence):up():up() + :tag("field", { var = "vCard"}) + :tag("value"):text(allow_vcards):up():up(); + origin.send(reply); return true end); @@ -468,7 +514,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event) end -- Change the nick - channels[i].participants[j].nick = nick:get_text(); + channel.participants[j].nick = nick:get_text(); -- Inform all other members local srv = pep.get_pep_service(channel.jid); --local participant = channel.participants[participant_index];