aboutsummaryrefslogtreecommitdiff
path: root/src/mod_muc_room.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_muc_room.erl')
-rw-r--r--src/mod_muc_room.erl38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index aaf3e8895..fd2c931a3 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -5,7 +5,7 @@
%%% Created : 19 Mar 2003 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%
-%%% ejabberd, Copyright (C) 2002-2021 ProcessOne
+%%% ejabberd, Copyright (C) 2002-2022 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
@@ -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})
@@ -644,7 +656,7 @@ normal_state({route, ToNick,
normal_state(hibernate, StateData) ->
case maps:size(StateData#state.users) of
0 ->
- store_room_no_checks(StateData, []),
+ store_room_no_checks(StateData, [], true),
?INFO_MSG("Hibernating room ~ts@~ts", [StateData#state.room, StateData#state.host]),
{stop, normal, StateData#state{hibernate_timer = hibernating}};
_ ->
@@ -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),
@@ -3997,8 +4013,8 @@ set_vcard_xupdate(State) ->
-define(MAKE_CONFIG_OPT(Opt),
{get_config_opt_name(Opt), element(Opt, Config)}).
--spec make_opts(state()) -> [{atom(), any()}].
-make_opts(StateData) ->
+-spec make_opts(state(), boolean()) -> [{atom(), any()}].
+make_opts(StateData, Hibernation) ->
Config = StateData#state.config,
Subscribers = muc_subscribers_fold(
fun(_LJID, Sub, Acc) ->
@@ -4042,7 +4058,7 @@ make_opts(StateData) ->
{hats_users,
lists:map(fun({U, H}) -> {U, maps:to_list(H)} end,
maps:to_list(StateData#state.hats_users))},
- {hibernation_time, erlang:system_time(microsecond)},
+ {hibernation_time, if Hibernation -> erlang:system_time(microsecond); true -> undefined end},
{subscribers, Subscribers}].
expand_opts(CompactOpts) ->
@@ -5004,13 +5020,13 @@ add_to_log(Type, Data, StateData)
when Type == roomconfig_change_disabledlogging ->
mod_muc_log:add_to_log(StateData#state.server_host,
roomconfig_change, Data, StateData#state.jid,
- make_opts(StateData));
+ make_opts(StateData, false));
add_to_log(Type, Data, StateData) ->
case (StateData#state.config)#config.logging of
true ->
mod_muc_log:add_to_log(StateData#state.server_host,
Type, Data, StateData#state.jid,
- make_opts(StateData));
+ make_opts(StateData, false));
false -> ok
end.
@@ -5075,16 +5091,18 @@ store_room(StateData, ChangesHints) ->
StateData#state.host, StateData#state.room,
ChangesHints);
_ ->
- store_room_no_checks(StateData, ChangesHints)
+ store_room_no_checks(StateData, ChangesHints, false),
+ ok
end;
true ->
ok
end.
-store_room_no_checks(StateData, ChangesHints) ->
+-spec store_room_no_checks(state(), list(), boolean()) -> {atomic, any()}.
+store_room_no_checks(StateData, ChangesHints, Hibernation) ->
mod_muc:store_room(StateData#state.server_host,
StateData#state.host, StateData#state.room,
- make_opts(StateData),
+ make_opts(StateData, Hibernation),
ChangesHints).
-spec send_subscriptions_change_notifications(jid(), binary(), subscribe|unsubscribe, state()) -> ok.