Don't request the whole MUC room state in get_room_occupants_number command (#3684) (#1964)

This commit is contained in:
Alexey Shchepin 2022-03-07 08:42:42 +03:00
parent f721374321
commit d5841785e1
2 changed files with 18 additions and 2 deletions

View File

@ -1050,8 +1050,8 @@ get_room_occupants(Pid) ->
get_room_occupants_number(Room, Host) ->
case get_room_pid(Room, Host) of
Pid when is_pid(Pid )->
S = get_room_state(Pid),
maps:size(S#state.users);
{ok, #{occupants_number := N}} = mod_muc_room:get_info(Pid),
N;
_ ->
throw({error, room_not_found})
end.

View File

@ -49,6 +49,7 @@
get_config/1,
set_config/2,
get_state/1,
get_info/1,
change_item/5,
change_item_async/5,
config_reloaded/1,
@ -217,6 +218,17 @@ get_state(Pid) ->
{error, notfound}
end.
-spec get_info(pid()) -> {ok, #{occupants_number => integer()}} |
{error, notfound | timeout}.
get_info(Pid) ->
try
{ok, p1_fsm:sync_send_all_state_event(Pid, get_info)}
catch _:{timeout, {p1_fsm, _, _}} ->
{error, timeout};
_:{_, {p1_fsm, _, _}} ->
{error, notfound}
end.
-spec subscribe(pid(), jid(), binary(), [binary()]) -> {ok, [binary()]} | {error, binary()}.
subscribe(Pid, JID, Nick, Nodes) ->
try p1_fsm:sync_send_all_state_event(Pid, {muc_subscribe, JID, Nick, Nodes})
@ -721,6 +733,10 @@ handle_sync_event(get_config, _From, StateName,
handle_sync_event(get_state, _From, StateName,
StateData) ->
{reply, {ok, StateData}, StateName, StateData};
handle_sync_event(get_info, _From, StateName,
StateData) ->
Result = #{occupants_number => maps:size(StateData#state.users)},
{reply, Result, StateName, StateData};
handle_sync_event({change_config, Config}, _From,
StateName, StateData) ->
{result, undefined, NSD} = change_config(Config, StateData),