Once just_created isn't true, use it to keep room process creation (#2787)
This commit is contained in:
parent
ea32d3f02c
commit
e18522f74c
|
@ -113,7 +113,7 @@
|
||||||
history :: lqueue(),
|
history :: lqueue(),
|
||||||
subject = [] :: [text()],
|
subject = [] :: [text()],
|
||||||
subject_author = <<"">> :: binary(),
|
subject_author = <<"">> :: binary(),
|
||||||
just_created = false :: boolean(),
|
just_created = misc:now_to_usec(now()) :: true | integer(),
|
||||||
activity = treap:empty() :: treap:treap(),
|
activity = treap:empty() :: treap:treap(),
|
||||||
room_shaper = none :: shaper:shaper(),
|
room_shaper = none :: shaper:shaper(),
|
||||||
room_queue :: p1_queue:queue() | undefined
|
room_queue :: p1_queue:queue() | undefined
|
||||||
|
|
|
@ -787,13 +787,15 @@ decide_room({_Room_name, _Host, Room_pid}, ServerHost, Last_allowed) ->
|
||||||
|
|
||||||
History = (S#state.history)#lqueue.queue,
|
History = (S#state.history)#lqueue.queue,
|
||||||
Ts_now = calendar:universal_time(),
|
Ts_now = calendar:universal_time(),
|
||||||
Ts_uptime = uptime_seconds(),
|
|
||||||
HistorySize = gen_mod:get_module_opt(ServerHost, mod_muc, history_size),
|
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
|
{Has_hist, Last} = case p1_queue:is_empty(History) of
|
||||||
true when HistorySize == 0 ->
|
true when (HistorySize == 0) or (JustCreated == true) ->
|
||||||
{false, 0};
|
{false, 0};
|
||||||
true ->
|
true ->
|
||||||
{false, Ts_uptime};
|
Ts_diff = (misc:now_to_usec(now())
|
||||||
|
- S#state.just_created) div 1000000,
|
||||||
|
{false, Ts_diff};
|
||||||
false ->
|
false ->
|
||||||
Last_message = get_queue_last(History),
|
Last_message = get_queue_last(History),
|
||||||
Ts_last = calendar:now_to_universal_time(
|
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),
|
- calendar:datetime_to_gregorian_seconds(Ts_last),
|
||||||
{true, Ts_diff}
|
{true, Ts_diff}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
case {Persistent, Just_created, Num_users, Has_hist, seconds_to_days(Last)} of
|
case {Persistent, Just_created, Num_users, Has_hist, seconds_to_days(Last)} of
|
||||||
{_true, false, 0, _, Last_days}
|
{_true, JC, 0, _, Last_days}
|
||||||
when Last_days >= Last_allowed ->
|
when (Last_days >= Last_allowed) and (JC /= true) ->
|
||||||
true;
|
true;
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
|
@ -1222,9 +1223,6 @@ make_opts(StateData) ->
|
||||||
%% Utils
|
%% Utils
|
||||||
%%----------------------------
|
%%----------------------------
|
||||||
|
|
||||||
uptime_seconds() ->
|
|
||||||
trunc(element(1, erlang:statistics(wall_clock))/1000).
|
|
||||||
|
|
||||||
find_host(global) ->
|
find_host(global) ->
|
||||||
global;
|
global;
|
||||||
find_host("global") ->
|
find_host("global") ->
|
||||||
|
|
|
@ -340,7 +340,7 @@ normal_state({route, <<"">>, #iq{} = IQ}, StateData) ->
|
||||||
ejabberd_router:route_error(IQ, Err),
|
ejabberd_router:route_error(IQ, Err),
|
||||||
case StateData#state.just_created of
|
case StateData#state.just_created of
|
||||||
true -> {stop, normal, StateData};
|
true -> {stop, normal, StateData};
|
||||||
false -> {next_state, normal_state, StateData}
|
_ -> {next_state, normal_state, StateData}
|
||||||
end;
|
end;
|
||||||
normal_state({route, Nick, #presence{from = From} = Packet}, StateData) ->
|
normal_state({route, Nick, #presence{from = From} = Packet}, StateData) ->
|
||||||
Activity = get_user_activity(From, StateData),
|
Activity = get_user_activity(From, StateData),
|
||||||
|
@ -1960,8 +1960,8 @@ add_new_user(From, Nick, Packet, StateData) ->
|
||||||
ResultState =
|
ResultState =
|
||||||
case NewStateData#state.just_created of
|
case NewStateData#state.just_created of
|
||||||
true ->
|
true ->
|
||||||
NewStateData#state{just_created = false};
|
NewStateData#state{just_created = misc:now_to_usec(now())};
|
||||||
false ->
|
_ ->
|
||||||
Robots = maps:remove(From, StateData#state.robots),
|
Robots = maps:remove(From, StateData#state.robots),
|
||||||
NewStateData#state{robots = Robots}
|
NewStateData#state{robots = Robots}
|
||||||
end,
|
end,
|
||||||
|
@ -2475,7 +2475,7 @@ status_codes(IsInitialPresence, _IsSelfPresence = true, StateData) ->
|
||||||
true ->
|
true ->
|
||||||
S1 = case StateData#state.just_created of
|
S1 = case StateData#state.just_created of
|
||||||
true -> [201|S0];
|
true -> [201|S0];
|
||||||
false -> S0
|
_ -> S0
|
||||||
end,
|
end,
|
||||||
S2 = case (StateData#state.config)#config.anonymous of
|
S2 = case (StateData#state.config)#config.anonymous of
|
||||||
true -> S1;
|
true -> S1;
|
||||||
|
@ -3983,7 +3983,7 @@ process_iq_vcard(From, #iq{type = set, lang = Lang, sub_els = [Pkt]},
|
||||||
{ignore, state()}.
|
{ignore, state()}.
|
||||||
process_iq_mucsub(_From, #iq{type = set, lang = Lang,
|
process_iq_mucsub(_From, #iq{type = set, lang = Lang,
|
||||||
sub_els = [#muc_subscribe{}]},
|
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)};
|
{error, xmpp:err_not_allowed(<<"Subscriptions are not allowed">>, Lang)};
|
||||||
process_iq_mucsub(From,
|
process_iq_mucsub(From,
|
||||||
#iq{type = set, lang = Lang,
|
#iq{type = set, lang = Lang,
|
||||||
|
|
Loading…
Reference in New Issue