]> granicus.if.org Git - ejabberd/commitdiff
Add get_subscribers command to list MUC subscribers
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 6 Sep 2016 14:55:18 +0000 (17:55 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 6 Sep 2016 14:55:18 +0000 (17:55 +0300)
src/mod_muc_admin.erl
src/mod_muc_room.erl

index 76e90957e22caf7b263e749cfd276b6c5ce060d7..9ceec7d5b06c583f257778c7af2c7ff0e8bde76a 100644 (file)
@@ -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,
     [
index e5ed4cc681598c809693d1daf49c3e1def3d5865..bdcb808a17debb35c471caf297c7cc5ac1a02a3b 100644 (file)
@@ -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">>,