diff --git a/src/mod_muc.erl b/src/mod_muc.erl index e7f8ca951..e1da09a7e 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -317,6 +317,15 @@ create_room(Host, Name, Opts) -> store_room(ServerHost, Host, Name, Opts) -> store_room(ServerHost, Host, Name, Opts, undefined). +maybe_store_new_room(ServerHost, Host, Name, Opts) -> + case {proplists:get_bool(persistent, Opts), proplists:get_value(subscribers, Opts, [])} of + {false, []} -> + {atomic, ok}; + {_, Subs} -> + Changes = [{add_subscription, JID, Nick, Nodes} || {JID, Nick, Nodes} <- Subs], + store_room(ServerHost, Host, Name, Opts, Changes) + end. + store_room(ServerHost, Host, Name, Opts, ChangesHints) -> LServer = jid:nameprep(ServerHost), Mod = gen_mod:db_mod(LServer, ?MODULE), @@ -417,6 +426,7 @@ handle_call({create, Room, Host, Opts}, _From, RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE), case start_room(RMod, Host, ServerHost, Room, NewOpts) of {ok, _} -> + maybe_store_new_room(ServerHost, Host, Room, NewOpts), ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]), {reply, ok, State}; Err -> @@ -432,6 +442,7 @@ handle_call({create, Room, Host, From, Nick, Opts}, _From, RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE), case start_room(RMod, Host, ServerHost, Room, NewOpts, From, Nick) of {ok, _} -> + maybe_store_new_room(ServerHost, Host, Room, NewOpts), ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]), {reply, ok, State}; Err -> diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 7bdd51f42..c13dd92ca 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -733,7 +733,7 @@ create_room_with_opts(Name1, Host1, ServerHost1, CustomRoomOpts) -> lists:keysort(1, DefRoomOpts)), case mod_muc:create_room(Host, Name, RoomOpts) of ok -> - maybe_store_room(ServerHost, Host, Name, RoomOpts); + ok; {error, _} -> throw({error, "Unable to start room"}) end; @@ -744,15 +744,6 @@ create_room_with_opts(Name1, Host1, ServerHost1, CustomRoomOpts) -> end end. -maybe_store_room(ServerHost, Host, Name, RoomOpts) -> - case proplists:get_bool(persistent, RoomOpts) of - true -> - {atomic, _} = mod_muc:store_room(ServerHost, Host, Name, RoomOpts), - ok; - false -> - ok - end. - %% Create the room only in the database. %% It is required to restart the MUC service for the room to appear. muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) ->