diff options
author | Alexey Shchepin <alexey@process-one.net> | 2022-03-07 08:42:42 +0300 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2022-03-07 08:42:42 +0300 |
commit | d5841785e1121ccc7cdb6a9e12b9f5f814303000 (patch) | |
tree | 64dbc6a809363553fe4a4f15a09611e082ecd2be /src | |
parent | Determine compile definitions based on Erlang version (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/mod_muc_admin.erl | 4 | ||||
-rw-r--r-- | src/mod_muc_room.erl | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 434559001..0015eb30a 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -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. diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 7984c12c5..fd2c931a3 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -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), |