New option to only allow registered users to speak WIP (#233):

* Prosody mod_muc_peertubelivechat_roles module
* Fix ConverseJS to disable the message field when room is unmoderated
  and user is visitor
* Mute/voice anonymous users when changing room configuration.
* Display a specific message to muted anonymous users.
* Default value for mute_anonymous in channel options.
* Feature documentation
This commit is contained in:
John Livingston
2024-06-20 16:46:14 +02:00
parent 1f1543bc97
commit 5a455fff93
57 changed files with 2959 additions and 944 deletions

View File

@ -4,9 +4,13 @@
-- SPDX-License-Identifier: MIT
-- SPDX-License-Identifier: AGPL-3.0-only
--
-- This version contains a modification to take into account new config option "slow_mode_duration".
-- This option is introduced in the Peertube livechat plugin, by mod_muc_slow_mode.
-- There will be a XEP proposal. When done, these modifications will be submitted to the mod_muc_http_defaults maintainer.
-- This version contains a modification to take into account new config options:
-- * "slow_mode_duration"
-- * "mute_anonymous"
-- These options are introduced in the Peertube livechat plugin.
--
-- The "slow_mode_duration" comes with mod_muc_slow_mode.
-- There will be a XEP proposal for this one. When done, these modifications will be submitted to the mod_muc_http_defaults maintainer.
--
local http = require "net.http";
@ -114,6 +118,9 @@ local function apply_config(room, settings)
if (type(config.slow_mode_duration) == "number") and config.slow_mode_duration >= 0 then
room._data.slow_mode_duration = config.slow_mode_duration;
end
if (type(config.mute_anonymous) == "boolean") then
room._data.x_peertubelivechat_mute_anonymous = config.mute_anonymous;
end
elseif config ~= nil then
module:log("error", "Invalid config returned from API for %s: %q", room.jid, config);
return nil, "format", { field = "config" };

View File

@ -0,0 +1,30 @@
<!--
SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
SPDX-License-Identifier: AGPL-3.0-only
-->
# mod_muc_peertubelivechat_roles
This module is a custom module that handles default roles for users.
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
## Features
### Only registered users can talk
This feature will set default user roles to 'visitor' for anonymous users.
The feature is associated to a room configuration field (muc#roomconfig_x_peertubelivechat_mute_anonymous).
The default value for this field will be set by mod_muc_http_defaults (which is a custom version of the original module).
Note: currently, all anonymous users are joining the original Peertube instance.
This means we only have to handle anonymous users on the local "anon" virtualhost.
If anonymous users are muted, the room disco features will include "x_peertubelivechat_mute_anonymous".
This is used by the ConverseJs frontend to display a message explaining why the user is muted.
### Only Peertube channel followers can talk
This feature will come later.

View File

@ -0,0 +1,84 @@
-- mod_muc_peertubelivechat_roles
--
-- SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
-- SPDX-License-Identifier: AGPL-3.0-only
--
-- This file is AGPL-v3 licensed.
-- Please see the Peertube livechat plugin copyright information.
-- https://livingston.frama.io/peertube-plugin-livechat/credits/
--
-- To compute the anonymous host, we will simply replace "room." by "anon." in the current module host.
-- This part is very peertube-plugin-livechat specific, but that's okay :)
local anonymous_host = "@anon." .. module.host:sub(#"^room.");
local function get_peertubelivechat_mute_anonymous(room)
return room._data.x_peertubelivechat_mute_anonymous;
end
local function set_peertubelivechat_mute_anonymous(room, mute_anonymous)
mute_anonymous = mute_anonymous and true or nil;
if get_peertubelivechat_mute_anonymous(room) == mute_anonymous then return false; end
room._data.x_peertubelivechat_mute_anonymous = mute_anonymous;
local role_to_test;
local role_to_set;
if (mute_anonymous) then
-- mute all anonymous users (with "participant" role)
role_to_test = "participant";
role_to_set = "visitor";
else
-- voice all anonymous users (with "visitor" role).
role_to_test = "visitor";
role_to_set = "participant";
end
for occupant_jid, occupant in room:each_occupant() do
if (occupant.bare_jid:sub(-#anonymous_host) == anonymous_host) and occupant.role == role_to_test then
room:set_role(true, occupant_jid, role_to_set);
end
end
return true;
end
module:hook("muc-disco#info", function(event)
if get_peertubelivechat_mute_anonymous(event.room) then
event.reply:tag("feature", {var = "x_peertubelivechat_mute_anonymous"}):up();
end
end);
module:hook("muc-config-form", function(event)
table.insert(event.form, {
name = "muc#roomconfig_x_peertubelivechat_mute_anonymous";
type = "boolean";
label = "Mute anonymous users";
desc = "Anonymous users will be muted by default.";
value = get_peertubelivechat_mute_anonymous(event.room);
});
end, 121);
module:hook("muc-config-submitted/muc#roomconfig_x_peertubelivechat_mute_anonymous", function(event)
if set_peertubelivechat_mute_anonymous(event.room, event.value) then
event.status_codes["104"] = true;
end
end);
-- Note: muc-get-default-role does not get any occupant info.
-- So we want use this hook to set default roles.
-- We will do something a little hacky...: change the role in a high priority muc-occupant-pre-join hook!
module:hook("muc-occupant-pre-join", function(event)
local occupant = event.occupant;
if occupant.role == "participant" then
if get_peertubelivechat_mute_anonymous(event.room) and occupant.bare_jid ~= nil then
if (occupant.bare_jid:sub(-#anonymous_host) == anonymous_host) then
occupant.role = "visitor";
end
end
end
end, 1000);
return {
get = get_peertubelivechat_mute_anonymous;
set = set_peertubelivechat_mute_anonymous;
};