diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | sql/mysql.new.sql | 2 | ||||
-rw-r--r-- | src/ejabberd_logger.erl | 12 | ||||
-rw-r--r-- | src/mod_mam_sql.erl | 20 | ||||
-rw-r--r-- | src/mod_offline.erl | 10 | ||||
-rw-r--r-- | src/mod_pubsub.erl | 3 | ||||
-rw-r--r-- | test/offline_tests.erl | 16 |
7 files changed, 43 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f55ce7127..13385b864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ Compilation - Add rebar3 3.15.2 binary - Add support for mix to: `./configure --enable-rebar=mix` -- Add workaround so rebar2 can use Elixir 1.12.0 - Improved `make rel` to work with rebar3 and mix - Add `make dev` to build a development release with rebar3 or mix - Hex: Add `sql/` and `vars.config` to Hex package files diff --git a/sql/mysql.new.sql b/sql/mysql.new.sql index c6d74bb91..01aeffbc5 100644 --- a/sql/mysql.new.sql +++ b/sql/mysql.new.sql @@ -86,7 +86,7 @@ CREATE TABLE sr_user ( PRIMARY KEY (server_host(191), jid, grp) ) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -CREATE UNIQUE INDEX i_sr_user_sh_jid_group ON sr_group(server_host(191), jid, grp); +CREATE UNIQUE INDEX i_sr_user_sh_jid_group ON sr_user(server_host(191), jid, grp); CREATE INDEX i_sr_user_sh_jid ON sr_user(server_host(191), jid); CREATE INDEX i_sr_user_sh_grp ON sr_user(server_host(191), grp); diff --git a/src/ejabberd_logger.erl b/src/ejabberd_logger.erl index 5ace8115f..05e197b3e 100644 --- a/src/ejabberd_logger.erl +++ b/src/ejabberd_logger.erl @@ -288,10 +288,11 @@ start(Level) -> ConsoleFmtConfig = FmtConfig#{template => console_template()}, try ok = logger:set_primary_config(level, Level), - ok = logger:update_formatter_config(default, ConsoleFmtConfig), + DefaultHandlerId = get_default_handlerid(), + ok = logger:update_formatter_config(DefaultHandlerId, ConsoleFmtConfig), case quiet_mode() of true -> - ok = logger:set_handler_config(default, level, critical); + ok = logger:set_handler_config(DefaultHandlerId, level, critical); _ -> ok end, @@ -319,6 +320,13 @@ start(Level) -> Err end. +get_default_handlerid() -> + Ids = logger:get_handler_ids(), + case lists:member(default, Ids) of + true -> default; + false -> hd(Ids) + end. + -spec restart() -> ok. restart() -> ok. diff --git a/src/mod_mam_sql.erl b/src/mod_mam_sql.erl index e5069b9a2..269b4c963 100644 --- a/src/mod_mam_sql.erl +++ b/src/mod_mam_sql.erl @@ -72,7 +72,7 @@ remove_from_archive(LUser, LServer, WithJid) -> end. delete_old_messages(ServerHost, TimeStamp, Type) -> - TS = now_to_usec(TimeStamp), + TS = misc:now_to_usec(TimeStamp), case Type of all -> ejabberd_sql:sql_query( @@ -315,7 +315,7 @@ export(_Server) -> id = _ID, timestamp = TS, peer = Peer, type = Type, nick = Nick, packet = Pkt}) when LServer == Host -> - TStmp = now_to_usec(TS), + TStmp = misc:now_to_usec(TS), SUser = case Type of chat -> LUser; groupchat -> jid:encode({LUser, LServer, <<>>}) @@ -372,16 +372,6 @@ is_empty_for_room(LServer, LName, LHost) -> %%%=================================================================== %%% Internal functions %%%=================================================================== -now_to_usec({MSec, Sec, USec}) -> - (MSec*1000000 + Sec)*1000000 + USec. - -usec_to_now(Int) -> - Secs = Int div 1000000, - USec = Int rem 1000000, - MSec = Secs div 1000000, - Sec = Secs rem 1000000, - {MSec, Sec, USec}. - make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) -> Start = proplists:get_value(start, MAMQuery), End = proplists:get_value('end', MAMQuery), @@ -432,14 +422,14 @@ make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) -> StartClause = case Start of {_, _, _} -> [<<" and timestamp >= ">>, - integer_to_binary(now_to_usec(Start))]; + integer_to_binary(misc:now_to_usec(Start))]; _ -> [] end, EndClause = case End of {_, _, _} -> [<<" and timestamp <= ">>, - integer_to_binary(now_to_usec(End))]; + integer_to_binary(misc:now_to_usec(End))]; _ -> [] end, @@ -526,7 +516,7 @@ make_archive_el(User, TS, XML, Peer, Kind, Nick, MsgType, JidRequestor, JidArchi TSInt -> try jid:decode(Peer) of PeerJID -> - Now = usec_to_now(TSInt), + Now = misc:usec_to_now(TSInt), PeerLJID = jid:tolower(PeerJID), T = case Kind of <<"">> -> chat; diff --git a/src/mod_offline.erl b/src/mod_offline.erl index c3fda25db..ff95767b6 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -572,6 +572,16 @@ check_event(#message{from = From, to = To, id = ID, type = Type} = Msg) -> sub_els = [#xevent{id = ID, offline = true}]}, ejabberd_router:route(NewMsg), true; + % Don't store composing events + #xevent{id = V, composing = true} when V /= undefined -> + false; + % Nor composing stopped events + #xevent{id = V, composing = false, delivered = false, + displayed = false, offline = false} when V /= undefined -> + false; + % But store other received notifications + #xevent{id = V} when V /= undefined -> + true; _ -> false end. diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index b0dca4b0d..d49a11817 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -3548,7 +3548,8 @@ decode_get_pending(#xdata{fields = Fs}, Lang) -> {error, xmpp:err_resource_constraint(Txt, Lang)} end. --spec check_opt_range(atom(), [proplists:property()], non_neg_integer()) -> boolean(). +-spec check_opt_range(atom(), [proplists:property()], + non_neg_integer() | undefined) -> boolean(). check_opt_range(_Opt, _Opts, undefined) -> true; check_opt_range(Opt, Opts, Max) -> diff --git a/test/offline_tests.erl b/test/offline_tests.erl index 1021c86e8..b5a90e7ee 100644 --- a/test/offline_tests.erl +++ b/test/offline_tests.erl @@ -489,6 +489,14 @@ wait_for_complete(Config, N) -> end end, error, [0, 100, 200, 2000, 5000, 10000]). +xevent_stored(#message{body = [], subject = []}, _) -> false; +xevent_stored(#message{type = T}, _) when T /= chat, T /= normal -> false; +xevent_stored(_, #xevent{id = undefined}) -> true; +xevent_stored(_, #xevent{offline = true}) -> true; +xevent_stored(_, #xevent{delivered = true}) -> true; +xevent_stored(_, #xevent{displayed = true}) -> true; +xevent_stored(_, _) -> false. + message_iterator(Config) -> ServerJID = server_jid(Config), ChatStates = [[#chatstate{type = composing}]], @@ -511,8 +519,14 @@ message_iterator(Config) -> fun(#message{type = error}) -> true; (#message{type = groupchat}) -> false; (#message{sub_els = [#hint{type = store}|_]}) when MamEnabled -> true; + (#message{sub_els = [#hint{type = 'no-store'}|_]}) -> false; (#message{sub_els = [#offline{}|_]}) when not MamEnabled -> false; - (#message{sub_els = [_, #xevent{id = I}]}) when I /= undefined, not MamEnabled -> false; + (#message{sub_els = [#hint{type = store}, #xevent{} = Event | _]} = Msg) when not MamEnabled -> + xevent_stored(Msg#message{body = body, type = chat}, Event); + (#message{sub_els = [#xevent{} = Event]} = Msg) when not MamEnabled -> + xevent_stored(Msg, Event); + (#message{sub_els = [_, #xevent{} = Event | _]} = Msg) when not MamEnabled -> + xevent_stored(Msg, Event); (#message{sub_els = [#xevent{id = I}]}) when I /= undefined, not MamEnabled -> false; (#message{sub_els = [#hint{type = store}|_]}) -> true; (#message{sub_els = [#hint{type = 'no-store'}|_]}) -> false; |