]> granicus.if.org Git - ejabberd/commitdiff
Once just_created isn't true, use it to keep room process creation (#2787)
authorBadlop <badlop@process-one.net>
Wed, 6 Feb 2019 15:13:30 +0000 (16:13 +0100)
committerBadlop <badlop@process-one.net>
Mon, 11 Feb 2019 15:56:33 +0000 (16:56 +0100)
include/mod_muc_room.hrl
src/mod_muc_admin.erl
src/mod_muc_room.erl

index 7ae68cd4fcb3ffd8e94707ac2f129df0a33dbaa8..40b1b9c046fe6ee3cf47f165d07eb89ac3c76cf8 100644 (file)
     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
index ec0cf65ec7735c949e574c388bebdacdb0cfcf03..0dac45e8b6174957a48bd91a8f34b133452a1deb 100644 (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") ->
index 135e89d773c2e8435d22847420d77b83586f4d9d..a8818aca405be22b3bda2f2fd2394fcc9b7df40b 100644 (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,