25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Add hook room_destroyed called when room gets destroyed

This commit is contained in:
Paweł Chmielowski 2019-04-17 17:23:21 +02:00
parent 4e2c95fe58
commit 875b2daff1

View File

@ -322,7 +322,8 @@ normal_state({route, <<"">>,
end, end,
case NewStateData of case NewStateData of
stop -> stop ->
{stop, normal, StateData}; Conf = StateData#state.config,
{stop, normal, StateData#state{config = Conf#config{persistent = false}}};
_ when NewStateData#state.just_created -> _ when NewStateData#state.just_created ->
close_room_if_temporary_and_empty(NewStateData); close_room_if_temporary_and_empty(NewStateData);
_ -> _ ->
@ -498,7 +499,8 @@ handle_event({destroy, Reason}, _StateName,
?INFO_MSG("Destroyed MUC room ~s with reason: ~p", ?INFO_MSG("Destroyed MUC room ~s with reason: ~p",
[jid:encode(StateData#state.jid), Reason]), [jid:encode(StateData#state.jid), Reason]),
add_to_log(room_existence, destroyed, StateData), add_to_log(room_existence, destroyed, StateData),
{stop, shutdown, StateData}; Conf = StateData#state.config,
{stop, shutdown, StateData#state{config = Conf#config{persistent = false}}};
handle_event(destroy, StateName, StateData) -> handle_event(destroy, StateName, StateData) ->
?INFO_MSG("Destroyed MUC room ~s", ?INFO_MSG("Destroyed MUC room ~s",
[jid:encode(StateData#state.jid)]), [jid:encode(StateData#state.jid)]),
@ -698,10 +700,10 @@ handle_info(config_reloaded, StateName, StateData) ->
handle_info(_Info, StateName, StateData) -> handle_info(_Info, StateName, StateData) ->
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
terminate(Reason, _StateName, StateData) -> terminate(Reason, _StateName,
#state{server_host = LServer, host = Host, room = Room} = StateData) ->
try try
?INFO_MSG("Stopping MUC room ~s@~s", ?INFO_MSG("Stopping MUC room ~s@~s", [Room, Host]),
[StateData#state.room, StateData#state.host]),
ReasonT = case Reason of ReasonT = case Reason of
shutdown -> shutdown ->
<<"You are being removed from the room " <<"You are being removed from the room "
@ -728,12 +730,16 @@ terminate(Reason, _StateName, StateData) ->
tab_remove_online_user(LJID, StateData) tab_remove_online_user(LJID, StateData)
end, [], get_users_and_subscribers(StateData)), end, [], get_users_and_subscribers(StateData)),
add_to_log(room_existence, stopped, StateData), add_to_log(room_existence, stopped, StateData),
mod_muc:room_destroyed(StateData#state.host, StateData#state.room, self(), case (StateData#state.config)#config.persistent of
StateData#state.server_host) false ->
ejabberd_hooks:run(room_destroyed, LServer, [LServer, Room, Host]);
_ ->
ok
end,
mod_muc:room_destroyed(Host, Room, self(), LServer)
catch ?EX_RULE(E, R, St) -> catch ?EX_RULE(E, R, St) ->
mod_muc:room_destroyed(StateData#state.host, StateData#state.room, self(), mod_muc:room_destroyed(Host, Room, self(), LServer),
StateData#state.server_host), ?ERROR_MSG("Got exception on room termination: ~p", [{E, {R, ?EX_STACK(St)}}])
?ERROR_MSG("Got exception on room termination: ~p", [{E, {R, ?EX_STACK(St)}}])
end, end,
ok. ok.