mod_mix: Various things

- Start working on MIX Anon
- Fix a TODO
This commit is contained in:
PapaTutuWawa 2021-02-20 20:33:46 +01:00
parent 8e12c18d4a
commit cd68dfa583

View File

@ -1,6 +1,5 @@
-- Big TODOlist -- Big TODOlist
-- TODO: Channel:is_subscribed could be replaced by get_pep_service(...):get_subscription -- 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(); local host = module:get_host();
if module:get_host_type() ~= "component" then if module:get_host_type() ~= "component" then
@ -24,6 +23,7 @@ Participant = mixlib.Participant;
-- XML namespaces -- XML namespaces
local mix_core_xmlns = "urn:xmpp:mix:core:1"; 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_admin_xmlns = "urn:xmpp:mix:admin:0";
local mix_node_messages = "urn:xmpp:mix:nodes:messages"; local mix_node_messages = "urn:xmpp:mix:nodes:messages";
local mix_node_participants = "urn:xmpp:mix:nodes:participants"; 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 default_channel_name = module:get_option("default_name", "MIX channel");
local restrict_channel_creation = module:get_option("restrict_local_channels", "local"); local restrict_channel_creation = module:get_option("restrict_local_channels", "local");
-- MAM stuff -- Dataforms
-- MAM
local mam_query_form = dataforms.new({ local mam_query_form = dataforms.new({
{ name = "FORM_TYPE", type = "hidden", value = mam_xmlns }, { name = "FORM_TYPE", type = "hidden", value = mam_xmlns },
{ name = "with", type = "jid-single" }, { name = "with", type = "jid-single" },
{ name = "start", type = "text-single" }, { name = "start", type = "text-single" },
{ name = "end", 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 -- MIX-ADMIN stuff
--[[ --[[
@ -358,11 +368,11 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event)
srv:remove_subscription(node, true, from); srv:remove_subscription(node, true, from);
module:log("debug", "Unsubscribed %s from %s on %s", from, node, channel.jid); module:log("debug", "Unsubscribed %s from %s on %s", from, node, channel.jid);
end end
channels[i].subscriptions[from] = nil; channel.subscriptions[from] = nil;
-- Retracting the participation -- Retracting the participation
srv:retract("urn:xmpp:mix:nodes:participants", true, channel:get_spid(from), true); srv:retract("urn:xmpp:mix:nodes:participants", true, channel:get_spid(from), true);
-- Removing the user -- Removing the user
table.remove(channels[i].participants, j); table.remove(channel.participants, j);
channel:save_state(); channel:save_state();
origin.send(st.reply(stanza):tag("leave", { xmlns = mix_core_xmlns })); 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; return true;
end end
local participant = Participant:new(jid.bare(from), nick); -- TODO: Make the default configurable
channels[i].subscriptions[from] = nodes; local jid_visibility = "never"; -- default
table.insert(channels[i].participants, participant) local allow_pms = "allow";
channels[i]:set_spid(jid.bare(stanza.attr.from), spid); 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); publish_participant(srv, channel, spid, participant);
channels[i]:save_state(); channel:save_state();
reply:add_child(nick); 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); origin.send(reply);
return true return true
end); end);
@ -468,7 +514,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event)
end end
-- Change the nick -- Change the nick
channels[i].participants[j].nick = nick:get_text(); channel.participants[j].nick = nick:get_text();
-- Inform all other members -- Inform all other members
local srv = pep.get_pep_service(channel.jid); local srv = pep.get_pep_service(channel.jid);
--local participant = channel.participants[participant_index]; --local participant = channel.participants[participant_index];