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)
"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.
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
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
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),