diff options
Diffstat (limited to 'src/mod_muc_room.erl')
-rw-r--r-- | src/mod_muc_room.erl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 7984c12c..fd2c931a 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), |