From 417284a9210cb8f6a3bcf9df41232e17c374da03 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 6 Sep 2016 17:55:18 +0300 Subject: [PATCH] Add get_subscribers command to list MUC subscribers --- src/mod_muc_admin.erl | 16 +++++++++++++++- src/mod_muc_room.erl | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 76e90957e..9ceec7d5b 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -20,7 +20,7 @@ change_room_option/4, get_room_options/2, set_room_affiliation/4, get_room_affiliations/2, web_menu_main/2, web_page_main/2, web_menu_host/3, - subscribe_room/4, unsubscribe_room/2, + subscribe_room/4, unsubscribe_room/2, get_subscribers/2, web_page_host/3, mod_opt_type/1, get_commands_spec/0]). -include("ejabberd.hrl"). @@ -163,6 +163,11 @@ get_commands_spec() -> module = ?MODULE, function = unsubscribe_room, args = [{user, binary}, {room, binary}], result = {res, rescode}}, + #ejabberd_commands{name = get_subscribers, tags = [muc_room], + desc = "List subscribers of a MUC conference", + module = ?MODULE, function = get_subscribers, + args = [{name, binary}, {service, binary}], + result = {subscribers, {list, {jid, string}}}}, #ejabberd_commands{name = set_room_affiliation, tags = [muc_room], desc = "Change an affiliation in a MUC room", module = ?MODULE, function = set_room_affiliation, @@ -955,6 +960,15 @@ unsubscribe_room(User, Room) -> throw({error, "Malformed room JID"}) end. +get_subscribers(Name, Host) -> + case get_room_pid(Name, Host) of + Pid when is_pid(Pid) -> + {ok, JIDList} = gen_fsm:sync_send_all_state_event(Pid, get_subscribers), + [jid:to_string(jid:remove_resource(J)) || J <- JIDList]; + _ -> + throw({error, "The room does not exist"}) + end. + make_opts(StateData) -> Config = StateData#state.config, [ diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index e5ed4cc68..bdcb808a1 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -749,6 +749,14 @@ handle_sync_event({change_state, NewStateData}, _From, handle_sync_event({process_item_change, Item, UJID}, _From, StateName, StateData) -> NSD = process_item_change(Item, StateData, UJID), {reply, {ok, NSD}, StateName, NSD}; +handle_sync_event(get_subscribers, _From, StateName, StateData) -> + JIDs = dict:fold( + fun(_, #user{is_subscriber = true, jid = J}, Acc) -> + [J|Acc]; + (_, _, Acc) -> + Acc + end, [], StateData#state.users), + {reply, {ok, JIDs}, StateName, StateData}; handle_sync_event({muc_subscribe, From, Nick, Nodes}, _From, StateName, StateData) -> SubEl = #xmlel{name = <<"subscribe">>,