mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Store state in db in mod_muc:create_room()
This commit is contained in:
parent
4e7aa41e3f
commit
f10f6d176f
@ -317,6 +317,15 @@ create_room(Host, Name, Opts) ->
|
|||||||
store_room(ServerHost, Host, Name, Opts) ->
|
store_room(ServerHost, Host, Name, Opts) ->
|
||||||
store_room(ServerHost, Host, Name, Opts, undefined).
|
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) ->
|
store_room(ServerHost, Host, Name, Opts, ChangesHints) ->
|
||||||
LServer = jid:nameprep(ServerHost),
|
LServer = jid:nameprep(ServerHost),
|
||||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
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),
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
||||||
case start_room(RMod, Host, ServerHost, Room, NewOpts) of
|
case start_room(RMod, Host, ServerHost, Room, NewOpts) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
maybe_store_new_room(ServerHost, Host, Room, NewOpts),
|
||||||
ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]),
|
ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]),
|
||||||
{reply, ok, State};
|
{reply, ok, State};
|
||||||
Err ->
|
Err ->
|
||||||
@ -432,6 +442,7 @@ handle_call({create, Room, Host, From, Nick, Opts}, _From,
|
|||||||
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
||||||
case start_room(RMod, Host, ServerHost, Room, NewOpts, From, Nick) of
|
case start_room(RMod, Host, ServerHost, Room, NewOpts, From, Nick) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
maybe_store_new_room(ServerHost, Host, Room, NewOpts),
|
||||||
ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]),
|
ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]),
|
||||||
{reply, ok, State};
|
{reply, ok, State};
|
||||||
Err ->
|
Err ->
|
||||||
|
@ -733,7 +733,7 @@ create_room_with_opts(Name1, Host1, ServerHost1, CustomRoomOpts) ->
|
|||||||
lists:keysort(1, DefRoomOpts)),
|
lists:keysort(1, DefRoomOpts)),
|
||||||
case mod_muc:create_room(Host, Name, RoomOpts) of
|
case mod_muc:create_room(Host, Name, RoomOpts) of
|
||||||
ok ->
|
ok ->
|
||||||
maybe_store_room(ServerHost, Host, Name, RoomOpts);
|
ok;
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
throw({error, "Unable to start room"})
|
throw({error, "Unable to start room"})
|
||||||
end;
|
end;
|
||||||
@ -744,15 +744,6 @@ create_room_with_opts(Name1, Host1, ServerHost1, CustomRoomOpts) ->
|
|||||||
end
|
end
|
||||||
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.
|
%% Create the room only in the database.
|
||||||
%% It is required to restart the MUC service for the room to appear.
|
%% It is required to restart the MUC service for the room to appear.
|
||||||
muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) ->
|
muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user