aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2019-02-06 16:13:30 +0100
committerBadlop <badlop@process-one.net>2019-02-11 16:56:33 +0100
commite18522f74ceaae87885d2265a6fea6e063e23aa3 (patch)
tree9de01c007f6019705fcd3324872a5fc463d652c5
parentSend mucsub subscriber notification events with from set to room jid (diff)
Once just_created isn't true, use it to keep room process creation (#2787)
-rw-r--r--include/mod_muc_room.hrl2
-rw-r--r--src/mod_muc_admin.erl16
-rw-r--r--src/mod_muc_room.erl10
3 files changed, 13 insertions, 15 deletions
diff --git a/include/mod_muc_room.hrl b/include/mod_muc_room.hrl
index 7ae68cd4f..40b1b9c04 100644
--- a/include/mod_muc_room.hrl
+++ b/include/mod_muc_room.hrl
@@ -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
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl
index ec0cf65ec..0dac45e8b 100644
--- a/src/mod_muc_admin.erl
+++ b/src/mod_muc_admin.erl
@@ -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") ->
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index 135e89d77..a8818aca4 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -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,