From da9c591eed5e7eee5f98761b58ff23f392d75e7a Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 25 Nov 2024 10:39:46 +0100 Subject: [PATCH] Improve create_rooms_file command to support vhosts with different config Until now it created all the rooms in the storage of the first vhost listed in the ejabberd configuration file. Similarly, it used only the default room options defined for the first vhost. --- src/mod_muc_admin.erl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 313a4721b26..1fc8efb05ff 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -160,6 +160,7 @@ get_commands_spec() -> #ejabberd_commands{name = create_rooms_file, tags = [muc], desc = "Create the rooms indicated in file", longdesc = "Provide one room JID per line. Rooms will be created after restart.", + note = "improved in 24.xx", module = ?MODULE, function = create_rooms_file, args_desc = ["Path to the text file with one room JID per line"], args_example = ["/home/ejabberd/rooms.txt"], @@ -1245,11 +1246,23 @@ create_rooms_file(Filename) -> RJID = read_room(F), Rooms = read_rooms(F, RJID, []), file:close(F), - %% Read the default room options defined for the first virtual host - DefRoomOpts = mod_muc_opt:default_room_options(ejabberd_config:get_myname()), - [muc_create_room(ejabberd_config:get_myname(), A, DefRoomOpts) || A <- Rooms], + HostsDetails = get_hosts_details(Rooms), + [muc_create_room(HostsDetails, A) || A <- Rooms], ok. +muc_create_room(HostsDetails, {_, Host, _} = RoomTuple) -> + {_Host, ServerHost, DefRoomOpts} = get_host_details(Host, HostsDetails), + muc_create_room(ServerHost, RoomTuple, DefRoomOpts). + +get_hosts_details(Rooms) -> + Hosts = lists:uniq([Host || {_, Host, _} <- Rooms]), + lists:map(fun(H) -> + SH = get_room_serverhost(H), + {H, SH, mod_muc_opt:default_room_options(SH)} + end, Hosts). + +get_host_details(Host, ServerHostsDetails) -> + lists:keyfind(Host, 1, ServerHostsDetails). %%--------------------------------- %% List/Delete Unused/Empty Rooms