Make get_subscribed_rooms work even for non-persistant rooms

This will store info about non-persistant rooms in db, but rooms with that
that option enabled will not be restored on server restart.

This will save info about room only on subscribers change.
This commit is contained in:
Paweł Chmielowski 2019-04-30 13:41:03 +02:00
parent b071c4906f
commit b83d30fd07
2 changed files with 74 additions and 31 deletions

View File

@ -654,31 +654,46 @@ load_permanent_rooms(Host, ServerHost, Access,
HistorySize, RoomShaper, QueueType) ->
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
lists:foreach(
fun(R) ->
{Room, Host} = R#muc_room.name_host,
case RMod:find_online_room(ServerHost, Room, Host) of
error ->
{ok, Pid} = mod_muc_room:start(Host,
ServerHost, Access, Room,
HistorySize, RoomShaper,
R#muc_room.opts, QueueType),
RMod:register_online_room(ServerHost, Room, Host, Pid);
{ok, _} ->
ok
end
end,
get_rooms(ServerHost, Host)).
fun(R) ->
{Room, Host} = R#muc_room.name_host,
case proplists:get_bool(persistent, R#muc_room.opts) of
true ->
case RMod:find_online_room(ServerHost, Room, Host) of
error ->
{ok, Pid} = mod_muc_room:start(Host,
ServerHost, Access, Room,
HistorySize, RoomShaper,
R#muc_room.opts, QueueType),
RMod:register_online_room(ServerHost, Room, Host, Pid);
{ok, _} ->
ok
end;
_ ->
forget_room(ServerHost, Host, Room)
end
end, get_rooms(ServerHost, Host)).
start_new_room(Host, ServerHost, Access, Room,
HistorySize, RoomShaper, From,
Nick, DefRoomOpts, QueueType) ->
case restore_room(ServerHost, Host, Room) of
Opts = case restore_room(ServerHost, Host, Room) of
error ->
error;
Opts0 ->
case proplists:get_bool(persistent, Opts0) of
true ->
Opts0;
_ ->
error
end
end,
case Opts of
error ->
?DEBUG("MUC: open new room '~s'~n", [Room]),
mod_muc_room:start(Host, ServerHost, Access, Room,
HistorySize, RoomShaper,
From, Nick, DefRoomOpts, QueueType);
Opts ->
_ ->
?DEBUG("MUC: restore room '~s'~n", [Room]),
mod_muc_room:start(Host, ServerHost, Access, Room,
HistorySize, RoomShaper, Opts, QueueType)

View File

@ -1140,6 +1140,7 @@ close_room_if_temporary_and_empty(StateData1) ->
"and empty",
[jid:encode(StateData1#state.jid)]),
add_to_log(room_existence, destroyed, StateData1),
maybe_forget_room(StateData1),
{stop, normal, StateData1};
_ -> {next_state, normal_state, StateData1}
end.
@ -3485,14 +3486,15 @@ change_config(Config, StateData) ->
end,
store_room(StateData1),
StateData1;
{true, false} ->
Affiliations = get_affiliations(StateData),
mod_muc:forget_room(StateData1#state.server_host,
StateData1#state.host,
StateData1#state.room),
StateData1#state{affiliations = Affiliations};
{false, false} ->
StateData1
{WasPersistent, false} ->
maybe_forget_room(StateData1),
case WasPersistent of
true ->
Affiliations = get_affiliations(StateData),
StateData1#state{affiliations = Affiliations};
_ ->
StateData1
end
end,
case {(StateData#state.config)#config.members_only,
Config#config.members_only} of
@ -3822,14 +3824,27 @@ destroy_room(DEl, StateData) ->
Info#user.jid, Packet,
?NS_MUCSUB_NODES_CONFIG, StateData)
end, ok, get_users_and_subscribers(StateData)),
case (StateData#state.config)#config.persistent of
true ->
mod_muc:forget_room(StateData#state.server_host,
StateData#state.host, StateData#state.room);
false -> ok
end,
maybe_forget_room(StateData),
{result, undefined, stop}.
maybe_forget_room(StateData) ->
Forget = case (StateData#state.config)#config.persistent of
true ->
true;
_ ->
Mod = gen_mod:db_mod(StateData#state.server_host, mod_muc),
erlang:function_exported(Mod, get_subscribed_rooms, 3)
end,
case Forget of
true ->
mod_muc:forget_room(StateData#state.server_host,
StateData#state.host,
StateData#state.room),
StateData;
_ ->
StateData
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Disco
@ -4359,7 +4374,20 @@ element_size(El) ->
store_room(StateData) ->
store_room(StateData, []).
store_room(StateData, ChangesHints) ->
if (StateData#state.config)#config.persistent ->
% Let store persistent rooms or on those backends that have get_subscribed_rooms
ShouldStore = case (StateData#state.config)#config.persistent of
true ->
true;
_ ->
case ChangesHints of
[] ->
false;
_ ->
Mod = gen_mod:db_mod(StateData#state.server_host, mod_muc),
erlang:function_exported(Mod, get_subscribed_rooms, 3)
end
end,
if ShouldStore ->
mod_muc:store_room(StateData#state.server_host,
StateData#state.host, StateData#state.room,
make_opts(StateData),