Update muc_room just_created timestamp when message is received
This together with last history message is used by room_unused_* command to determine for how long room was not used, this change allow us to skip checking history, and works even when history is disabled.
This commit is contained in:
parent
bf1aacefcb
commit
c2a3f037bb
|
@ -874,41 +874,29 @@ decide_rooms(Method, Rooms, Last_allowed) ->
|
||||||
decide_room(unused, {_Room_name, _Host, _ServerHost, Room_pid}, Last_allowed) ->
|
decide_room(unused, {_Room_name, _Host, _ServerHost, Room_pid}, Last_allowed) ->
|
||||||
NodeStartTime = erlang:system_time(microsecond) -
|
NodeStartTime = erlang:system_time(microsecond) -
|
||||||
1000000*(erlang:monotonic_time(second)-ejabberd_config:get_node_start()),
|
1000000*(erlang:monotonic_time(second)-ejabberd_config:get_node_start()),
|
||||||
{Just_created, Num_users, History} =
|
{Just_created, Num_users} =
|
||||||
case Room_pid of
|
case Room_pid of
|
||||||
Pid when is_pid(Pid) ->
|
Pid when is_pid(Pid) ->
|
||||||
S = get_room_state(Room_pid),
|
S = get_room_state(Room_pid),
|
||||||
{S#state.just_created,
|
{S#state.just_created,
|
||||||
maps:size(S#state.users),
|
maps:size(S#state.users)};
|
||||||
(S#state.history)#lqueue.queue};
|
|
||||||
Opts ->
|
Opts ->
|
||||||
case lists:keyfind(hibernation_time, 1, Opts) of
|
case lists:keyfind(hibernation_time, 1, Opts) of
|
||||||
false ->
|
false ->
|
||||||
{NodeStartTime, 0, p1_queue:new()};
|
{NodeStartTime, 0};
|
||||||
{_, T} ->
|
{_, T} ->
|
||||||
{T, 0, p1_queue:new()}
|
{T, 0}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Ts_now = calendar:universal_time(),
|
Last = case Just_created of
|
||||||
{Has_hist, Last} = case p1_queue:is_empty(History) of
|
|
||||||
true when Just_created == true ->
|
|
||||||
{false, 0};
|
|
||||||
true ->
|
true ->
|
||||||
Ts_diff = (erlang:system_time(microsecond)
|
0;
|
||||||
- Just_created) div 1000000,
|
_ ->
|
||||||
{false, Ts_diff};
|
(erlang:system_time(microsecond)
|
||||||
false ->
|
- Just_created) div 1000000
|
||||||
Last_message = get_queue_last(History),
|
|
||||||
Ts_last = calendar:now_to_universal_time(
|
|
||||||
element(4, Last_message)),
|
|
||||||
Ts_diff =
|
|
||||||
calendar:datetime_to_gregorian_seconds(Ts_now)
|
|
||||||
- calendar:datetime_to_gregorian_seconds(Ts_last),
|
|
||||||
{true, Ts_diff}
|
|
||||||
end,
|
end,
|
||||||
case {Just_created, Num_users, Has_hist, seconds_to_days(Last)} of
|
case {Num_users, seconds_to_days(Last)} of
|
||||||
{JC, 0, _, Last_days}
|
{0, Last_days} when (Last_days >= Last_allowed) ->
|
||||||
when (Last_days >= Last_allowed) and (JC /= true) ->
|
|
||||||
true;
|
true;
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
|
|
|
@ -2720,9 +2720,9 @@ add_message_to_history(FromNick, FromJID, Packet, StateData) ->
|
||||||
Q1 = lqueue_in({FromNick, TSPacket, false,
|
Q1 = lqueue_in({FromNick, TSPacket, false,
|
||||||
TimeStamp, Size},
|
TimeStamp, Size},
|
||||||
StateData#state.history),
|
StateData#state.history),
|
||||||
StateData#state{history = Q1};
|
StateData#state{history = Q1, just_created = erlang:system_time(microsecond)};
|
||||||
_ ->
|
_ ->
|
||||||
StateData
|
StateData#state{just_created = erlang:system_time(microsecond)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec send_history(jid(), [lqueue_elem()], state()) -> ok.
|
-spec send_history(jid(), [lqueue_elem()], state()) -> ok.
|
||||||
|
|
Loading…
Reference in New Issue