mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
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:
parent
b071c4906f
commit
b83d30fd07
@ -654,31 +654,46 @@ load_permanent_rooms(Host, ServerHost, Access,
|
|||||||
HistorySize, RoomShaper, QueueType) ->
|
HistorySize, RoomShaper, QueueType) ->
|
||||||
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(R) ->
|
fun(R) ->
|
||||||
{Room, Host} = R#muc_room.name_host,
|
{Room, Host} = R#muc_room.name_host,
|
||||||
case RMod:find_online_room(ServerHost, Room, Host) of
|
case proplists:get_bool(persistent, R#muc_room.opts) of
|
||||||
error ->
|
true ->
|
||||||
{ok, Pid} = mod_muc_room:start(Host,
|
case RMod:find_online_room(ServerHost, Room, Host) of
|
||||||
ServerHost, Access, Room,
|
error ->
|
||||||
HistorySize, RoomShaper,
|
{ok, Pid} = mod_muc_room:start(Host,
|
||||||
R#muc_room.opts, QueueType),
|
ServerHost, Access, Room,
|
||||||
RMod:register_online_room(ServerHost, Room, Host, Pid);
|
HistorySize, RoomShaper,
|
||||||
{ok, _} ->
|
R#muc_room.opts, QueueType),
|
||||||
ok
|
RMod:register_online_room(ServerHost, Room, Host, Pid);
|
||||||
end
|
{ok, _} ->
|
||||||
end,
|
ok
|
||||||
get_rooms(ServerHost, Host)).
|
end;
|
||||||
|
_ ->
|
||||||
|
forget_room(ServerHost, Host, Room)
|
||||||
|
end
|
||||||
|
end, get_rooms(ServerHost, Host)).
|
||||||
|
|
||||||
start_new_room(Host, ServerHost, Access, Room,
|
start_new_room(Host, ServerHost, Access, Room,
|
||||||
HistorySize, RoomShaper, From,
|
HistorySize, RoomShaper, From,
|
||||||
Nick, DefRoomOpts, QueueType) ->
|
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 ->
|
error ->
|
||||||
?DEBUG("MUC: open new room '~s'~n", [Room]),
|
?DEBUG("MUC: open new room '~s'~n", [Room]),
|
||||||
mod_muc_room:start(Host, ServerHost, Access, Room,
|
mod_muc_room:start(Host, ServerHost, Access, Room,
|
||||||
HistorySize, RoomShaper,
|
HistorySize, RoomShaper,
|
||||||
From, Nick, DefRoomOpts, QueueType);
|
From, Nick, DefRoomOpts, QueueType);
|
||||||
Opts ->
|
_ ->
|
||||||
?DEBUG("MUC: restore room '~s'~n", [Room]),
|
?DEBUG("MUC: restore room '~s'~n", [Room]),
|
||||||
mod_muc_room:start(Host, ServerHost, Access, Room,
|
mod_muc_room:start(Host, ServerHost, Access, Room,
|
||||||
HistorySize, RoomShaper, Opts, QueueType)
|
HistorySize, RoomShaper, Opts, QueueType)
|
||||||
|
@ -1140,6 +1140,7 @@ close_room_if_temporary_and_empty(StateData1) ->
|
|||||||
"and empty",
|
"and empty",
|
||||||
[jid:encode(StateData1#state.jid)]),
|
[jid:encode(StateData1#state.jid)]),
|
||||||
add_to_log(room_existence, destroyed, StateData1),
|
add_to_log(room_existence, destroyed, StateData1),
|
||||||
|
maybe_forget_room(StateData1),
|
||||||
{stop, normal, StateData1};
|
{stop, normal, StateData1};
|
||||||
_ -> {next_state, normal_state, StateData1}
|
_ -> {next_state, normal_state, StateData1}
|
||||||
end.
|
end.
|
||||||
@ -3485,14 +3486,15 @@ change_config(Config, StateData) ->
|
|||||||
end,
|
end,
|
||||||
store_room(StateData1),
|
store_room(StateData1),
|
||||||
StateData1;
|
StateData1;
|
||||||
{true, false} ->
|
{WasPersistent, false} ->
|
||||||
Affiliations = get_affiliations(StateData),
|
maybe_forget_room(StateData1),
|
||||||
mod_muc:forget_room(StateData1#state.server_host,
|
case WasPersistent of
|
||||||
StateData1#state.host,
|
true ->
|
||||||
StateData1#state.room),
|
Affiliations = get_affiliations(StateData),
|
||||||
StateData1#state{affiliations = Affiliations};
|
StateData1#state{affiliations = Affiliations};
|
||||||
{false, false} ->
|
_ ->
|
||||||
StateData1
|
StateData1
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
case {(StateData#state.config)#config.members_only,
|
case {(StateData#state.config)#config.members_only,
|
||||||
Config#config.members_only} of
|
Config#config.members_only} of
|
||||||
@ -3822,14 +3824,27 @@ destroy_room(DEl, StateData) ->
|
|||||||
Info#user.jid, Packet,
|
Info#user.jid, Packet,
|
||||||
?NS_MUCSUB_NODES_CONFIG, StateData)
|
?NS_MUCSUB_NODES_CONFIG, StateData)
|
||||||
end, ok, get_users_and_subscribers(StateData)),
|
end, ok, get_users_and_subscribers(StateData)),
|
||||||
case (StateData#state.config)#config.persistent of
|
maybe_forget_room(StateData),
|
||||||
true ->
|
|
||||||
mod_muc:forget_room(StateData#state.server_host,
|
|
||||||
StateData#state.host, StateData#state.room);
|
|
||||||
false -> ok
|
|
||||||
end,
|
|
||||||
{result, undefined, stop}.
|
{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
|
% Disco
|
||||||
|
|
||||||
@ -4359,7 +4374,20 @@ element_size(El) ->
|
|||||||
store_room(StateData) ->
|
store_room(StateData) ->
|
||||||
store_room(StateData, []).
|
store_room(StateData, []).
|
||||||
store_room(StateData, ChangesHints) ->
|
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,
|
mod_muc:store_room(StateData#state.server_host,
|
||||||
StateData#state.host, StateData#state.room,
|
StateData#state.host, StateData#state.room,
|
||||||
make_opts(StateData),
|
make_opts(StateData),
|
||||||
|
Loading…
Reference in New Issue
Block a user