Once just_created isn't true, use it to keep room process creation (#2787)

This commit is contained in:
Badlop 2019-02-06 16:13:30 +01:00
parent ea32d3f02c
commit e18522f74c
3 changed files with 13 additions and 15 deletions

View File

@ -113,7 +113,7 @@
history :: lqueue(),
subject = [] :: [text()],
subject_author = <<"">> :: binary(),
just_created = false :: boolean(),
just_created = misc:now_to_usec(now()) :: true | integer(),
activity = treap:empty() :: treap:treap(),
room_shaper = none :: shaper:shaper(),
room_queue :: p1_queue:queue() | undefined

View File

@ -787,13 +787,15 @@ decide_room({_Room_name, _Host, Room_pid}, ServerHost, Last_allowed) ->
History = (S#state.history)#lqueue.queue,
Ts_now = calendar:universal_time(),
Ts_uptime = uptime_seconds(),
HistorySize = gen_mod:get_module_opt(ServerHost, mod_muc, history_size),
JustCreated = S#state.just_created,
{Has_hist, Last} = case p1_queue:is_empty(History) of
true when HistorySize == 0 ->
true when (HistorySize == 0) or (JustCreated == true) ->
{false, 0};
true ->
{false, Ts_uptime};
Ts_diff = (misc:now_to_usec(now())
- S#state.just_created) div 1000000,
{false, Ts_diff};
false ->
Last_message = get_queue_last(History),
Ts_last = calendar:now_to_universal_time(
@ -803,10 +805,9 @@ decide_room({_Room_name, _Host, Room_pid}, ServerHost, Last_allowed) ->
- calendar:datetime_to_gregorian_seconds(Ts_last),
{true, Ts_diff}
end,
case {Persistent, Just_created, Num_users, Has_hist, seconds_to_days(Last)} of
{_true, false, 0, _, Last_days}
when Last_days >= Last_allowed ->
{_true, JC, 0, _, Last_days}
when (Last_days >= Last_allowed) and (JC /= true) ->
true;
_ ->
false
@ -1222,9 +1223,6 @@ make_opts(StateData) ->
%% Utils
%%----------------------------
uptime_seconds() ->
trunc(element(1, erlang:statistics(wall_clock))/1000).
find_host(global) ->
global;
find_host("global") ->

View File

@ -340,7 +340,7 @@ normal_state({route, <<"">>, #iq{} = IQ}, StateData) ->
ejabberd_router:route_error(IQ, Err),
case StateData#state.just_created of
true -> {stop, normal, StateData};
false -> {next_state, normal_state, StateData}
_ -> {next_state, normal_state, StateData}
end;
normal_state({route, Nick, #presence{from = From} = Packet}, StateData) ->
Activity = get_user_activity(From, StateData),
@ -1960,8 +1960,8 @@ add_new_user(From, Nick, Packet, StateData) ->
ResultState =
case NewStateData#state.just_created of
true ->
NewStateData#state{just_created = false};
false ->
NewStateData#state{just_created = misc:now_to_usec(now())};
_ ->
Robots = maps:remove(From, StateData#state.robots),
NewStateData#state{robots = Robots}
end,
@ -2475,7 +2475,7 @@ status_codes(IsInitialPresence, _IsSelfPresence = true, StateData) ->
true ->
S1 = case StateData#state.just_created of
true -> [201|S0];
false -> S0
_ -> S0
end,
S2 = case (StateData#state.config)#config.anonymous of
true -> S1;
@ -3983,7 +3983,7 @@ process_iq_vcard(From, #iq{type = set, lang = Lang, sub_els = [Pkt]},
{ignore, state()}.
process_iq_mucsub(_From, #iq{type = set, lang = Lang,
sub_els = [#muc_subscribe{}]},
#state{just_created = false, config = #config{allow_subscription = false}}) ->
#state{just_created = Just, config = #config{allow_subscription = false}}) when Just /= true ->
{error, xmpp:err_not_allowed(<<"Subscriptions are not allowed">>, Lang)};
process_iq_mucsub(From,
#iq{type = set, lang = Lang,