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
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(
- 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
%% Utils
%%----------------------------
-uptime_seconds() ->
- trunc(element(1, erlang:statistics(wall_clock))/1000).
-
find_host(global) ->
global;
find_host("global") ->
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),
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,
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;
{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,