25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

Add subscribe_room_many command

This commit is contained in:
Alexey Shchepin 2021-12-20 09:37:47 +03:00
parent a26c9d2475
commit fc34661b6f
2 changed files with 54 additions and 3 deletions

View File

@ -40,8 +40,11 @@
change_room_option/4, get_room_options/2,
set_room_affiliation/4, get_room_affiliations/2, get_room_affiliation/3,
web_menu_main/2, web_page_main/2, web_menu_host/3,
subscribe_room/4, unsubscribe_room/2, get_subscribers/2,
web_page_host/3, mod_options/1, get_commands_spec/0, find_hosts/1]).
subscribe_room/4, subscribe_room_many/3,
unsubscribe_room/2, get_subscribers/2,
web_page_host/3,
mod_opt_type/1, mod_options/1,
get_commands_spec/0, find_hosts/1]).
-include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl").
@ -331,6 +334,25 @@ get_commands_spec() ->
args = [{user, binary}, {nick, binary}, {room, binary},
{nodes, binary}],
result = {nodes, {list, {node, string}}}},
#ejabberd_commands{name = subscribe_room_many, tags = [muc_room],
desc = "Subscribe several users to a MUC conference",
module = ?MODULE, function = subscribe_room_many,
args_desc = ["Users JIDs and nicks",
"the room to subscribe",
"nodes separated by commas: ,"],
args_example = [[{"tom@localhost", "Tom"},
{"jerry@localhost", "Jerry"}],
"room1@conference.localhost",
"urn:xmpp:mucsub:nodes:messages,urn:xmpp:mucsub:nodes:affiliations"],
args = [{users, {list,
{user, {tuple,
[{jid, binary},
{nick, binary}
]}}
}},
{room, binary},
{nodes, binary}],
result = {res, rescode}},
#ejabberd_commands{name = unsubscribe_room, tags = [muc_room],
desc = "Unsubscribe from a MUC conference",
module = ?MODULE, function = unsubscribe_room,
@ -1331,6 +1353,18 @@ subscribe_room(User, Nick, Room, Nodes) ->
throw({error, "Malformed room JID"})
end.
subscribe_room_many(Users, Room, Nodes) ->
MaxUsers = mod_muc_admin_opt:subscribe_room_many_max_users(global),
if
length(Users) > MaxUsers ->
throw({error, "Too many users in subscribe_room_many command"});
true ->
lists:foreach(
fun({User, Nick}) ->
subscribe_room(User, Nick, Room, Nodes)
end, Users)
end.
unsubscribe_room(User, Room) ->
try jid:decode(Room) of
#jid{luser = Name, lserver = Host} when Name /= <<"">> ->
@ -1413,7 +1447,11 @@ find_hosts(ServerHost) ->
[]
end.
mod_options(_) -> [].
mod_opt_type(subscribe_room_many_max_users) ->
econf:int().
mod_options(_) ->
[{subscribe_room_many_max_users, 50}].
mod_doc() ->
#{desc =>

13
src/mod_muc_admin_opt.erl Normal file
View File

@ -0,0 +1,13 @@
%% Generated automatically
%% DO NOT EDIT: run `make options` instead
-module(mod_muc_admin_opt).
-export([subscribe_room_many_max_users/1]).
-spec subscribe_room_many_max_users(gen_mod:opts() | global | binary()) -> integer().
subscribe_room_many_max_users(Opts) when is_map(Opts) ->
gen_mod:get_opt(subscribe_room_many_max_users, Opts);
subscribe_room_many_max_users(Host) ->
gen_mod:get_module_opt(Host, mod_muc_admin, subscribe_room_many_max_users).