From c511cc1d5f1ef1f1f1d92eb1b74205ff402a752b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Tue, 14 Jun 2022 15:49:58 +0200 Subject: [PATCH 1/5] Rename mod_mam to mod_mam_pm --- big_tests/tests/amp_big_SUITE.erl | 10 +-- big_tests/tests/gdpr_SUITE.erl | 4 +- big_tests/tests/mam_SUITE.erl | 2 +- big_tests/tests/mam_helper.erl | 10 +-- big_tests/tests/mam_proper_SUITE.erl | 2 +- big_tests/tests/rest_helper.erl | 2 +- src/mam/ejabberd_gen_mam_archive.erl | 6 +- src/mam/ejabberd_gen_mam_prefs.erl | 14 ++--- src/mam/mam_decoder.erl | 6 +- src/mam/mam_encoder.erl | 2 +- src/mam/mam_iq.erl | 10 +-- src/mam/mam_lookup.erl | 8 +-- src/mam/mam_send_message.erl | 4 +- src/mam/mod_mam_cache_user.erl | 8 +-- src/mam/mod_mam_cassandra_arch.erl | 4 +- src/mam/mod_mam_cassandra_prefs.erl | 18 +++--- src/mam/mod_mam_elasticsearch_arch.erl | 14 ++--- src/mam/mod_mam_meta.erl | 4 +- src/mam/mod_mam_mnesia_prefs.erl | 12 ++-- src/mam/mod_mam_muc.erl | 28 ++++----- src/mam/mod_mam_muc_cassandra_arch.erl | 2 +- src/mam/mod_mam_muc_elasticsearch_arch.erl | 14 ++--- src/mam/mod_mam_muc_rdbms_arch.erl | 20 +++--- src/mam/mod_mam_muc_rdbms_arch_async.erl | 2 +- src/mam/mod_mam_params.erl | 4 +- src/mam/{mod_mam.erl => mod_mam_pm.erl} | 12 ++-- src/mam/mod_mam_rdbms_arch.erl | 24 +++---- src/mam/mod_mam_rdbms_arch_async.erl | 2 +- src/mam/mod_mam_rdbms_prefs.erl | 20 +++--- src/mam/mod_mam_rdbms_user.erl | 6 +- src/mam/mod_mam_riak_timed_arch_yz.erl | 2 +- src/mam/mod_mam_utils.erl | 48 +++++++------- src/metrics/mongoose_metrics_mam_hooks.erl | 12 ++-- src/mod_commands.erl | 6 +- .../mongoose_client_api_messages.erl | 4 +- .../mongoose_client_api_rooms_messages.erl | 2 +- src/mongoose_deprecations.erl | 2 +- src/mongoose_hooks.erl | 62 +++++++++---------- test/common/config_parser_helper.erl | 6 +- test/mam_misc_SUITE.erl | 2 +- test/mod_mam_meta_SUITE.erl | 10 +-- 41 files changed, 215 insertions(+), 215 deletions(-) rename src/mam/{mod_mam.erl => mod_mam_pm.erl} (98%) diff --git a/big_tests/tests/amp_big_SUITE.erl b/big_tests/tests/amp_big_SUITE.erl index 452fced4c40..5842d3cba73 100644 --- a/big_tests/tests/amp_big_SUITE.erl +++ b/big_tests/tests/amp_big_SUITE.erl @@ -302,7 +302,7 @@ notify_deliver_to_online_user_bare_jid_test(Config) -> end). notify_deliver_to_online_user_recipient_privacy_test(Config) -> - case is_module_loaded(mod_mam) of + case is_module_loaded(mod_mam_pm) of true -> {skip, "MAM does not support privacy lists"}; false -> do_notify_deliver_to_online_user_recipient_privacy_test(Config) end. @@ -398,7 +398,7 @@ is_offline_storage_working(Config) -> Status == mam orelse Status == offline. notify_deliver_to_offline_user_recipient_privacy_test(Config) -> - case is_module_loaded(mod_mam) of + case is_module_loaded(mod_mam_pm) of true -> {skip, "MAM does not support privacy lists"}; false -> do_notify_deliver_to_offline_user_recipient_privacy_test(Config) end. @@ -735,14 +735,14 @@ user_has_no_incoming_offline_messages(FreshConfig, UserName) -> FreshConfig, [{UserName, 1}], fun(User) -> client_receives_nothing(User), - case is_module_loaded(mod_mam) of + case is_module_loaded(mod_mam_pm) of true -> client_has_no_mam_messages(User); false -> ok end end). user_has_incoming_offline_message(FreshConfig, UserName, MsgText) -> - true = is_module_loaded(mod_mam) orelse is_module_loaded(mod_offline), + true = is_module_loaded(mod_mam_pm) orelse is_module_loaded(mod_offline), {ok, Client} = escalus_client:start(FreshConfig, UserName, <<"new-session">>), escalus:send(Client, escalus_stanza:presence(<<"available">>)), case is_module_loaded(mod_offline) of @@ -751,7 +751,7 @@ user_has_incoming_offline_message(FreshConfig, UserName, MsgText) -> end, Presence = escalus:wait_for_stanza(Client), escalus:assert(is_presence, Presence), - case is_module_loaded(mod_mam) of + case is_module_loaded(mod_mam_pm) of true -> client_has_mam_message(Client); false -> ok end, diff --git a/big_tests/tests/gdpr_SUITE.erl b/big_tests/tests/gdpr_SUITE.erl index 92b52bf05a9..2f8e7353149 100644 --- a/big_tests/tests/gdpr_SUITE.erl +++ b/big_tests/tests/gdpr_SUITE.erl @@ -866,7 +866,7 @@ retrieve_mam_pm_and_muc_light_dont_interfere(Config) -> [mam_helper:wait_for_archive_size(User, 2) || User <- [Alice, Bob]], false = mongoose_helper:successful_rpc(gen_mod, get_module_opt, - [host_type(), mod_mam, archive_groupchats, undefined]), + [host_type(), mod_mam_pm, archive_groupchats, undefined]), AliceDir = retrieve_all_personal_data(Alice, Config), BobDir = retrieve_all_personal_data(Bob, Config), @@ -914,7 +914,7 @@ retrieve_mam_pm_and_muc_light_interfere(Config) -> mam_helper:wait_for_archive_size(Kate, 3), true = mongoose_helper:successful_rpc(gen_mod, get_module_opt, - [host_type(), mod_mam, archive_groupchats, undefined]), + [host_type(), mod_mam_pm, archive_groupchats, undefined]), AliceDir = retrieve_all_personal_data(Alice, Config), BobDir = retrieve_all_personal_data(Bob, Config), diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index f4735f588e8..1367e42fcfd 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -2850,7 +2850,7 @@ metric_incremented_on_archive_request(ConfigIn) -> end, HostType = domain_helper:host_type(mim), HostTypePrefix = domain_helper:make_metrics_prefix(HostType), - MongooseMetrics = [{[HostTypePrefix, backends, mod_mam, lookup], changed}], + MongooseMetrics = [{[HostTypePrefix, backends, mod_mam_pm, lookup], changed}], Config = [{mongoose_metrics, MongooseMetrics} | ConfigIn], escalus_fresh:story(Config, [{alice, 1}], F). diff --git a/big_tests/tests/mam_helper.erl b/big_tests/tests/mam_helper.erl index 26cdd3f6d5a..76b0dce2b3e 100644 --- a/big_tests/tests/mam_helper.erl +++ b/big_tests/tests/mam_helper.erl @@ -801,16 +801,16 @@ wait_for_room_archive_size(Server, Username, ExpectedSize) -> archive_size(Server, Username) -> - rpc_apply(mod_mam, archive_size, [Server, Username]). + rpc_apply(mod_mam_pm, archive_size, [Server, Username]). archive_size_with_host_type(HostType, Server, Username) -> - rpc_apply(mod_mam, archive_size_with_host_type, [HostType, Server, Username]). + rpc_apply(mod_mam_pm, archive_size_with_host_type, [HostType, Server, Username]). room_archive_size(Server, Username) -> rpc_apply(mod_mam_muc, archive_size, [Server, Username]). delete_archive(Server, Username) -> - rpc_apply(mod_mam, delete_archive, [Server, Username]). + rpc_apply(mod_mam_pm, delete_archive, [Server, Username]). delete_room_archive(Server, Username) -> rpc_apply(mod_mam_muc, delete_archive, [Server, Username]). @@ -967,7 +967,7 @@ put_msg({{MsgIdOwner, MsgIdRemote}, archive_message(Map2). archive_message(#{} = Map) -> - ok = rpc_apply(mod_mam, archive_message_from_ct, [Map]). + ok = rpc_apply(mod_mam_pm, archive_message_from_ct, [Map]). muc_bootstrap_archive(Config) -> Room = ?config(room, Config), @@ -1017,7 +1017,7 @@ archive_muc_msg({{MsgID, _}, packet => Packet}]). get_archive_id(Server, User) -> - rpc_apply(mod_mam, archive_id, [Server, User]). + rpc_apply(mod_mam_pm, archive_id, [Server, User]). get_muc_archive_id(MucHost, Room) -> rpc_apply(mod_mam_muc, archive_id, [MucHost, Room]). diff --git a/big_tests/tests/mam_proper_SUITE.erl b/big_tests/tests/mam_proper_SUITE.erl index b751a2f6cc2..a250052ecce 100644 --- a/big_tests/tests/mam_proper_SUITE.erl +++ b/big_tests/tests/mam_proper_SUITE.erl @@ -117,7 +117,7 @@ body() -> packet(To, Body) -> escalus_stanza:chat_to(jid:to_binary(To), Body). -%% Generates mod_mam:archive_message_params() +%% Generates mod_mam_pm:archive_message_params() params() -> ?LET({MessId, ArcId, LocalJid, RemoteJid, OriginId, Dir, Body, SenderId}, diff --git a/big_tests/tests/rest_helper.erl b/big_tests/tests/rest_helper.erl index 37fbf3b7229..eeddcff0e7c 100644 --- a/big_tests/tests/rest_helper.erl +++ b/big_tests/tests/rest_helper.erl @@ -377,7 +377,7 @@ make_arc_id(Client) -> Server = escalus_client:server(Client), Bin = escalus_client:short_jid(Client), Jid = mongoose_helper:make_jid(User, Server, <<>>), - {Bin, Jid, mam_helper:rpc_apply(mod_mam, archive_id, [Server, User])}. + {Bin, Jid, mam_helper:rpc_apply(mod_mam_pm, archive_id, [Server, User])}. fill_room_archive(RoomID, Users, AlreadyArchivedCount) -> {TodayDate, _} = calendar:local_time(), diff --git a/src/mam/ejabberd_gen_mam_archive.erl b/src/mam/ejabberd_gen_mam_archive.erl index a02dbcc873a..f4753b61bb9 100644 --- a/src/mam/ejabberd_gen_mam_archive.erl +++ b/src/mam/ejabberd_gen_mam_archive.erl @@ -3,15 +3,15 @@ -ignore_xref([behaviour_info/1]). -callback archive_size(Size :: integer(), Host :: jid:server(), - ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) -> integer(). -callback archive_message(Result :: any(), Host :: jid:server(), - Params :: mod_mam:archive_message_params()) -> ok | {error, timeout}. + Params :: mod_mam_pm:archive_message_params()) -> ok | {error, timeout}. -callback lookup_messages(Result :: any(), Host :: jid:server(), Params :: map()) -> Result when - Result :: {ok, mod_mam:lookup_result()} | {error, 'policy-violation'}. + Result :: {ok, mod_mam_pm:lookup_result()} | {error, 'policy-violation'}. -callback get_mam_pm_gdpr_data(mam_pm_gdpr_data(), mongooseim:host_type(), jid:jid()) -> mam_pm_gdpr_data(). diff --git a/src/mam/ejabberd_gen_mam_prefs.erl b/src/mam/ejabberd_gen_mam_prefs.erl index d0fafb2a5f0..91da0a69484 100644 --- a/src/mam/ejabberd_gen_mam_prefs.erl +++ b/src/mam/ejabberd_gen_mam_prefs.erl @@ -2,17 +2,17 @@ -ignore_xref([behaviour_info/1]). --callback get_behaviour(Default :: mod_mam:archive_behaviour(), - Host :: jid:server(), ArcID :: mod_mam:archive_id(), +-callback get_behaviour(Default :: mod_mam_pm:archive_behaviour(), + Host :: jid:server(), ArcID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). -callback set_prefs(Result :: any(), Host :: jid:server(), - ArcID :: mod_mam:archive_id(), ArcJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + ArcID :: mod_mam_pm:archive_id(), ArcJID :: jid:jid(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). --callback get_prefs(mod_mam:preference(), _Host :: jid:server(), - ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) - -> mod_mam:preference(). +-callback get_prefs(mod_mam_pm:preference(), _Host :: jid:server(), + ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) + -> mod_mam_pm:preference(). diff --git a/src/mam/mam_decoder.erl b/src/mam/mam_decoder.erl index 147a46ec935..3cd35ce0c7c 100644 --- a/src/mam/mam_decoder.erl +++ b/src/mam/mam_decoder.erl @@ -11,14 +11,14 @@ -type db_muc_gdpr_row() :: {ext_mess_id(), ExtData :: binary()}. -type decoded_muc_gdpr_row() :: {ext_mess_id(), exml:element()}. --spec decode_row(db_row(), env_vars()) -> mod_mam:message_row(). +-spec decode_row(db_row(), env_vars()) -> mod_mam_pm:message_row(). decode_row({ExtMessID, ExtSrcJID, ExtData}, Env) -> MessID = mongoose_rdbms:result_to_integer(ExtMessID), SrcJID = decode_jid(ExtSrcJID, Env), Packet = decode_packet(ExtData, Env), #{id => MessID, jid => SrcJID, packet => Packet}. --spec decode_muc_row(db_muc_row(), env_vars()) -> mod_mam:message_row(). +-spec decode_muc_row(db_muc_row(), env_vars()) -> mod_mam_pm:message_row(). decode_muc_row({ExtMessID, Nick, ExtData}, Env = #{archive_jid := RoomJID}) -> MessID = mongoose_rdbms:result_to_integer(ExtMessID), SrcJID = jid:replace_resource(RoomJID, Nick), @@ -31,7 +31,7 @@ decode_muc_gdpr_row({ExtMessID, ExtData}, Env) -> {ExtMessID, Packet}. -spec decode_retraction_info(env_vars(), - [{binary(), mod_mam:message_id(), binary()}], + [{binary(), mod_mam_pm:message_id(), binary()}], mod_mam_utils:retraction_id()) -> skip | mod_mam_utils:retraction_info(). decode_retraction_info(_Env, [], _) -> skip; diff --git a/src/mam/mam_encoder.erl b/src/mam/mam_encoder.erl index 76904a0b0f6..1a408c134a8 100644 --- a/src/mam/mam_encoder.erl +++ b/src/mam/mam_encoder.erl @@ -22,7 +22,7 @@ extend_lookup_params(#{start_ts := Start, end_ts := End, with_jid := WithJID, remote_bare_jid => maybe_encode_bare_jid(WithJID, Env), remote_resource => jid_to_non_empty_resource(WithJID)}. --spec encode_message(mod_mam:archive_message_params(), env_vars(), list(db_mapping())) -> +-spec encode_message(mod_mam_pm:archive_message_params(), env_vars(), list(db_mapping())) -> [encoded_field_value()]. encode_message(Params, Env, Mappings) -> [encode_value_using_mapping(Params, Env, Mapping) || Mapping <- Mappings]. diff --git a/src/mam/mam_iq.erl b/src/mam/mam_iq.erl index 41c698bf079..197c3cb2d6e 100644 --- a/src/mam/mam_iq.erl +++ b/src/mam/mam_iq.erl @@ -37,7 +37,7 @@ | 'mam_get_message_form'. -type lookup_params() :: #{ - archive_id => mod_mam:archive_id(), + archive_id => mod_mam_pm:archive_id(), owner_jid => jid:jid(), caller_jid => jid:jid(), rsm => jlib:rsm_in() | undefined, @@ -47,16 +47,16 @@ page_size => non_neg_integer(), ordering_direction => backward | forward, %% unix_timestamp() is in microseconds - now => mod_mam:unix_timestamp(), + now => mod_mam_pm:unix_timestamp(), %% Filtering by date - start_ts => mod_mam:unix_timestamp() | undefined, - end_ts => mod_mam:unix_timestamp() | undefined, + start_ts => mod_mam_pm:unix_timestamp() | undefined, + end_ts => mod_mam_pm:unix_timestamp() | undefined, %% Filtering by contact with_jid => jid:jid() | undefined, %% Filtering by body text search_text => binary() | undefined, %% Filtering Result Set based on message ids - borders => mod_mam:borders() | undefined, + borders => mod_mam_pm:borders() | undefined, %% Affects 'policy-violation' for a case when: %% - user does not use forms to query archive %% - user does not provide "set" element diff --git a/src/mam/mam_lookup.erl b/src/mam/mam_lookup.erl index c55d8b33166..7c80564f1ea 100644 --- a/src/mam/mam_lookup.erl +++ b/src/mam/mam_lookup.erl @@ -9,7 +9,7 @@ -type filter() :: mam_filter:filter(). -type env_vars() :: mod_mam_rdbms_arch:env_vars(). -type params() :: map(). --type message_id() :: mod_mam:message_id(). +-type message_id() :: mod_mam_pm:message_id(). -type maybe_rsm() :: #rsm_in{} | undefined. -type opt_count_type() :: last_page | by_offset | none. @@ -18,7 +18,7 @@ %% - lookup_fn %% - decode_row_fn -spec lookup(env_vars(), filter(), params()) -> - {ok, mod_mam:lookup_result()} | {error, item_not_found}. + {ok, mod_mam_pm:lookup_result()} | {error, item_not_found}. lookup(Env = #{}, Filter, Params = #{rsm := RSM}) when is_list(Filter) -> OptParams = Params#{opt_count_type => opt_count_type(RSM)}, choose_lookup_messages_strategy(Env, Filter, OptParams). @@ -155,12 +155,12 @@ rsm_to_regular_lookup_vars(RSM, Filter, Offset, PageSize) -> decode_rows(MessageRows, Env) -> [decode_row(Row, Env) || Row <- MessageRows]. --spec decoded_row_to_message_id(mod_mam:message_row()) -> mod_mam:message_id(). +-spec decoded_row_to_message_id(mod_mam_pm:message_row()) -> mod_mam_pm:message_id(). decoded_row_to_message_id(#{id := MessId}) -> MessId. -spec extract_messages(Env :: env_vars(), Filter :: filter(), Offset :: non_neg_integer(), Max :: pos_integer(), - Order :: asc | desc) -> [mod_mam:message_row()]. + Order :: asc | desc) -> [mod_mam_pm:message_row()]. extract_messages(_Env, _Filter, _Offset, 0 = _Max, _Order) -> []; extract_messages(Env, Filter, Offset, Max, Order) -> diff --git a/src/mam/mam_send_message.erl b/src/mam/mam_send_message.erl index 6db54ee32a1..0fd3aaf20cb 100644 --- a/src/mam/mam_send_message.erl +++ b/src/mam/mam_send_message.erl @@ -6,14 +6,14 @@ -ignore_xref([behaviour_info/1]). -callback send_message( - Row :: mod_mam:message_row(), + Row :: mod_mam_pm:message_row(), ArcJID :: jid:jid(), From :: jid:jid(), Packet :: exml:element()) -> Acc :: mongoose_acc:t(). -spec call_send_message( SendModule :: module(), - Row :: mod_mam:message_row(), + Row :: mod_mam_pm:message_row(), ArcJID :: jid:jid(), From :: jid:jid(), Packet :: exml:element()) -> Acc :: mongoose_acc:t(). diff --git a/src/mam/mod_mam_cache_user.erl b/src/mam/mod_mam_cache_user.erl index c0b7b28ef93..5ffbe763d5d 100644 --- a/src/mam/mod_mam_cache_user.erl +++ b/src/mam/mod_mam_cache_user.erl @@ -75,7 +75,7 @@ muc_hooks(HostType) -> %% API %%==================================================================== -spec cached_archive_id(undefined, mongooseim:host_type(), jid:jid()) -> - mod_mam:archive_id(). + mod_mam_pm:archive_id(). cached_archive_id(undefined, HostType, ArcJid) -> case mongoose_user_cache:get_entry(HostType, ?MODULE, ArcJid) of #{id := ArchId} -> ArchId; @@ -84,8 +84,8 @@ cached_archive_id(undefined, HostType, ArcJid) -> undefined end. --spec store_archive_id(mod_mam:archive_id(), mongooseim:host_type(), jid:jid()) - -> mod_mam:archive_id(). +-spec store_archive_id(mod_mam_pm:archive_id(), mongooseim:host_type(), jid:jid()) + -> mod_mam_pm:archive_id(). store_archive_id(ArchId, HostType, ArcJid) -> case erase(mam_not_cached_flag) of undefined -> @@ -96,7 +96,7 @@ store_archive_id(ArchId, HostType, ArcJid) -> end. -spec remove_archive(Acc :: map(), HostType :: mongooseim:host_type(), - ArchId :: mod_mam:archive_id(), ArcJid :: jid:jid()) -> map(). + ArchId :: mod_mam_pm:archive_id(), ArcJid :: jid:jid()) -> map(). remove_archive(Acc, HostType, _UserID, ArcJid) -> mongoose_user_cache:delete_user(HostType, ?MODULE, ArcJid), Acc. diff --git a/src/mam/mod_mam_cassandra_arch.erl b/src/mam/mod_mam_cassandra_arch.erl index 69eb26c2991..1f9f6f7c2fc 100644 --- a/src/mam/mod_mam_cassandra_arch.erl +++ b/src/mam/mod_mam_cassandra_arch.erl @@ -86,7 +86,7 @@ stop(HostType) -> ejabberd_hooks:delete(hooks(HostType)). %% ---------------------------------------------------------------------- -%% Add hooks for mod_mam +%% Add hooks for mod_mam_pm -spec hooks(host_type()) -> [ejabberd_hooks:hook()]. hooks(HostType) -> @@ -210,7 +210,7 @@ remove_archive(HostType, UserJID) -> %% SELECT MESSAGES -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()}. + {ok, mod_mam_pm:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, _HostType, #{search_text := <<_/binary>>}) -> diff --git a/src/mam/mod_mam_cassandra_prefs.erl b/src/mam/mod_mam_cassandra_prefs.erl index a3ec8e119a9..4bb64c5780b 100644 --- a/src/mam/mod_mam_cassandra_prefs.erl +++ b/src/mam/mod_mam_cassandra_prefs.erl @@ -82,8 +82,8 @@ prepared_queries() -> %% ---------------------------------------------------------------------- %% Internal functions and callbacks --spec get_behaviour(Default :: mod_mam:archive_behaviour(), - HostType :: host_type(), ArchiveID :: mod_mam:archive_id(), +-spec get_behaviour(Default :: mod_mam_pm:archive_behaviour(), + HostType :: host_type(), ArchiveID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, HostType, _UserID, LocJID, RemJID) -> BUserJID = mod_mam_utils:bare_jid(LocJID), @@ -105,8 +105,8 @@ get_behaviour(DefaultBehaviour, HostType, _UserID, LocJID, RemJID) -> -spec set_prefs(Result :: any(), HostType :: host_type(), - ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, HostType, _UserID, UserJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -144,9 +144,9 @@ encode_row(BUserJID, BRemoteJID, Behaviour, Timestamp) -> behaviour => Behaviour, '[timestamp]' => Timestamp}. --spec get_prefs(mod_mam:preference(), _HostType :: host_type(), - ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) - -> mod_mam:preference(). +-spec get_prefs(mod_mam_pm:preference(), _HostType :: host_type(), + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) + -> mod_mam_pm:preference(). get_prefs({GlobalDefaultMode, _, _}, HostType, _UserID, UserJID) -> BUserJID = mod_mam_utils:bare_jid(UserJID), Params = #{user_jid => BUserJID}, @@ -155,7 +155,7 @@ get_prefs({GlobalDefaultMode, _, _}, HostType, _UserID, UserJID) -> decode_prefs_rows(Rows, GlobalDefaultMode, [], []). --spec remove_archive(mongoose_acc:t(), host_type(), mod_mam:archive_id(), jid:jid()) -> +-spec remove_archive(mongoose_acc:t(), host_type(), mod_mam_pm:archive_id(), jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, _UserID, UserJID) -> remove_archive(HostType, UserJID), @@ -197,7 +197,7 @@ decode_behaviour(<<"N">>) -> never. -spec decode_prefs_rows([[term()]], DefaultMode, AlwaysJIDs, NeverJIDs) -> {DefaultMode, AlwaysJIDs, NeverJIDs} when - DefaultMode :: mod_mam:archive_behaviour(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]. decode_prefs_rows([], DefaultMode, AlwaysJIDs, NeverJIDs) -> diff --git a/src/mam/mod_mam_elasticsearch_arch.erl b/src/mam/mod_mam_elasticsearch_arch.erl index 85a83b3a80f..b21192f4f04 100644 --- a/src/mam/mod_mam_elasticsearch_arch.erl +++ b/src/mam/mod_mam_elasticsearch_arch.erl @@ -140,7 +140,7 @@ archive_size(_Size, _Host, _ArchiveId, OwnerJid) -> -spec remove_archive(Acc :: mongoose_acc:t(), Host :: jid:server(), - ArchiveId :: mod_mam:archive_id(), + ArchiveId :: mod_mam_pm:archive_id(), OwnerJid :: jid:jid()) -> Acc when Acc :: map(). remove_archive(Acc, Host, _ArchiveId, OwnerJid) -> remove_archive(Host, OwnerJid), @@ -169,11 +169,11 @@ hooks(Host) -> {mam_remove_archive, Host, ?MODULE, remove_archive, 50}, {get_mam_pm_gdpr_data, Host, ?MODULE, get_mam_pm_gdpr_data, 50}]. --spec make_document_id(binary(), mod_mam:message_id()) -> binary(). +-spec make_document_id(binary(), mod_mam_pm:message_id()) -> binary(). make_document_id(Owner, MessageId) -> <>. --spec make_document(mod_mam:message_id(), binary(), binary(), binary(), exml:element()) -> +-spec make_document(mod_mam_pm:message_id(), binary(), binary(), binary(), exml:element()) -> map(). make_document(MessageId, Owner, Remote, SourceBinJid, Packet) -> #{mam_id => MessageId, @@ -225,13 +225,13 @@ range_filter(#{end_ts := End, start_ts := Start, borders := Borders, rsm := RSM} range_filter(_) -> []. --spec maybe_add_end_filter(undefined | mod_mam:message_id(), map()) -> map(). +-spec maybe_add_end_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). maybe_add_end_filter(undefined, RangeMap) -> RangeMap; maybe_add_end_filter(Value, RangeMap) -> RangeMap#{le => Value}. --spec maybe_add_start_filter(undefined | mod_mam:message_id(), map()) -> map(). +-spec maybe_add_start_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). maybe_add_start_filter(undefined, RangeMap) -> RangeMap; maybe_add_start_filter(Value, RangeMap) -> @@ -258,7 +258,7 @@ maybe_add_from_constraint(Query, #{rsm := #rsm_in{index = Offset}}) when is_inte maybe_add_from_constraint(Query, _) -> Query. --spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam:lookup_result(). +-spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam_pm:lookup_result(). search_result_to_mam_lookup_result(Result, Params) -> #{<<"hits">> := #{<<"hits">> := Hits, @@ -277,7 +277,7 @@ search_result_to_mam_lookup_result(Result, Params) -> {CorrectedTotalCount, Offset, Messages} end. --spec hit_to_mam_message(map()) -> mod_mam:message_row(). +-spec hit_to_mam_message(map()) -> mod_mam_pm:message_row(). hit_to_mam_message(#{<<"_source">> := JSON}) -> MessageId = maps:get(<<"mam_id">>, JSON), Packet = maps:get(<<"message">>, JSON), diff --git a/src/mam/mod_mam_meta.erl b/src/mam/mod_mam_meta.erl index aafa7178bf5..588eb119820 100644 --- a/src/mam/mod_mam_meta.erl +++ b/src/mam/mod_mam_meta.erl @@ -184,13 +184,13 @@ parse_opts(Type, Opts, Deps) -> parse_backend_opts(Backend, Type, BackendOpts, WithPrefs). -spec mam_type_to_core_mod(mam_type()) -> module(). -mam_type_to_core_mod(pm) -> mod_mam; +mam_type_to_core_mod(pm) -> mod_mam_pm; mam_type_to_core_mod(muc) -> mod_mam_muc. %% Get a list of options to pass into the two modules. %% They don't have to be defined in pm or muc sections, the root section is enough. -spec valid_core_mod_opts(module()) -> [atom()]. -valid_core_mod_opts(mod_mam) -> +valid_core_mod_opts(mod_mam_pm) -> [archive_groupchats, same_mam_id_for_peers] ++ common_opts(); valid_core_mod_opts(mod_mam_muc) -> [host] ++ common_opts(). diff --git a/src/mam/mod_mam_mnesia_prefs.erl b/src/mam/mod_mam_mnesia_prefs.erl index 76161df3ee0..b1d2fce84c3 100644 --- a/src/mam/mod_mam_mnesia_prefs.erl +++ b/src/mam/mod_mam_mnesia_prefs.erl @@ -80,7 +80,7 @@ hooks(_HostType, _Opt, _Opts) -> %% Internal functions and callbacks -spec get_behaviour(Default :: behaviour(), Host :: jid:server(), - ArcID :: mod_mam:archive_id(), LocJID :: jid:jid(), + ArcID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, _Host, _ArcID, @@ -122,8 +122,8 @@ get_behaviour(#mam_prefs{default_mode = roster, -spec set_prefs(Result :: any(), Host :: jid:server(), - ArcID :: mod_mam:archive_id(), ArcJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + ArcID :: mod_mam_pm:archive_id(), ArcJID :: jid:jid(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, _Host, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -149,9 +149,9 @@ set_prefs1(_ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> ok. --spec get_prefs(mod_mam:preference(), _Host :: jid:server(), - _ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid() - ) -> mod_mam:preference(). +-spec get_prefs(mod_mam_pm:preference(), _Host :: jid:server(), + _ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid() + ) -> mod_mam_pm:preference(). get_prefs({GlobalDefaultMode, _, _}, _Host, _ArcID, ArcJID) -> SU = su_key(ArcJID), case mnesia:dirty_read(mam_prefs, SU) of diff --git a/src/mam/mod_mam_muc.erl b/src/mam/mod_mam_muc.erl index 5059ce3a461..1e85ec60830 100644 --- a/src/mam/mod_mam_muc.erl +++ b/src/mam/mod_mam_muc.erl @@ -105,7 +105,7 @@ -type row_batch() :: {TotalCount :: non_neg_integer(), Offset :: non_neg_integer(), MessageRows :: [row()]}. --type row() :: mod_mam:message_row(). +-type row() :: mod_mam_pm:message_row(). -type host_type() :: mongooseim:host_type(). -type muc_action() :: atom(). @@ -398,7 +398,7 @@ handle_set_message_form(HostType, #jid{} = From, #jid{} = ArcJID, IQ) -> -spec do_handle_set_message_form(HostType :: mongooseim:host_type(), From :: jid:jid(), - ArcId :: mod_mam:archive_id(), + ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid(), IQ :: jlib:iq(), Params :: mam_iq:lookup_params()) -> @@ -408,7 +408,7 @@ do_handle_set_message_form(HostType, From, ArcID, ArcJID, IQ, Params0) -> Result = lookup_messages(HostType, Params), handle_lookup_result(Result, HostType, From, IQ, Params). --spec handle_lookup_result({ok, mod_mam:lookup_result()} | {error, term()}, +-spec handle_lookup_result({ok, mod_mam_pm:lookup_result()} | {error, term()}, host_type(), jid:jid(), jlib:iq(), map()) -> jlib:iq() | ignore | {error, term(), jlib:iq()}. handle_lookup_result(Result, HostType, From, IQ, #{owner_jid := ArcJID} = Params) -> @@ -469,18 +469,18 @@ handle_get_message_form(HostType, archive_id_int(HostType, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_archive_id(HostType, ArcJID). --spec archive_size(HostType :: host_type(), ArcID :: mod_mam:archive_id(), +-spec archive_size(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), ArcJID ::jid:jid()) -> non_neg_integer(). archive_size(HostType, ArcID, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_archive_size(HostType, ArcID, ArcJID). --spec get_behaviour(HostType :: host_type(), ArcID :: mod_mam:archive_id(), +-spec get_behaviour(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(HostType, ArcID, LocJID = #jid{}, RemJID = #jid{}) -> mongoose_hooks:mam_muc_get_behaviour(HostType, ArcID, LocJID, RemJID). --spec set_prefs(HostType :: host_type(), ArcID :: mod_mam:archive_id(), - ArcJID :: jid:jid(), DefaultMode :: mod_mam:archive_behaviour(), +-spec set_prefs(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), + ArcJID :: jid:jid(), DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -488,21 +488,21 @@ set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> AlwaysJIDs, NeverJIDs). %% @doc Load settings from the database. --spec get_prefs(HostType :: host_type(), ArcID :: mod_mam:archive_id(), - ArcJID :: jid:jid(), GlobalDefaultMode :: mod_mam:archive_behaviour()) - -> mod_mam:preference() | {error, Reason :: term()}. +-spec get_prefs(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), + ArcJID :: jid:jid(), GlobalDefaultMode :: mod_mam_pm:archive_behaviour()) + -> mod_mam_pm:preference() | {error, Reason :: term()}. get_prefs(HostType, ArcID, ArcJID, GlobalDefaultMode) -> mongoose_hooks:mam_muc_get_prefs(HostType, GlobalDefaultMode, ArcID, ArcJID). --spec remove_archive(host_type(), mod_mam:archive_id() | undefined, +-spec remove_archive(host_type(), mod_mam_pm:archive_id() | undefined, jid:jid()) -> ok. remove_archive(HostType, ArcID, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_remove_archive(HostType, ArcID, ArcJID), ok. -%% See description in mod_mam. +%% See description in mod_mam_pm. -spec lookup_messages(HostType :: host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()} + {ok, mod_mam_pm:lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. lookup_messages(HostType, Params) -> @@ -530,7 +530,7 @@ archive_message_for_ct(Params = #{local_jid := RoomJid}) -> HostType = mod_muc_light_utils:room_jid_to_host_type(RoomJid), archive_message(HostType, Params). --spec archive_message(host_type(), mod_mam:archive_message_params()) -> ok | {error, timeout}. +-spec archive_message(host_type(), mod_mam_pm:archive_message_params()) -> ok | {error, timeout}. archive_message(HostType, Params) -> mongoose_hooks:mam_muc_archive_message(HostType, Params). diff --git a/src/mam/mod_mam_muc_cassandra_arch.erl b/src/mam/mod_mam_muc_cassandra_arch.erl index 4d60a2542d2..2abcc2991af 100644 --- a/src/mam/mod_mam_muc_cassandra_arch.erl +++ b/src/mam/mod_mam_muc_cassandra_arch.erl @@ -206,7 +206,7 @@ remove_archive(Acc, HostType, _RoomID, RoomJID) -> %% SELECT MESSAGES -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()}. + {ok, mod_mam_pm:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, _HostType, #{search_text := <<_/binary>>}) -> diff --git a/src/mam/mod_mam_muc_elasticsearch_arch.erl b/src/mam/mod_mam_muc_elasticsearch_arch.erl index af41199f603..32feaa042d9 100644 --- a/src/mam/mod_mam_muc_elasticsearch_arch.erl +++ b/src/mam/mod_mam_muc_elasticsearch_arch.erl @@ -144,7 +144,7 @@ archive_size(_Size, _Host, _ArchiveId, RoomJid) -> -spec remove_archive(Acc :: mongoose_acc:t(), Host :: jid:server(), - ArchiveId :: mod_mam:archive_id(), + ArchiveId :: mod_mam_pm:archive_id(), RoomJid :: jid:jid()) -> Acc when Acc :: map(). remove_archive(Acc, Host, _ArchiveId, RoomJid) -> SearchQuery = build_search_query(#{owner_jid => RoomJid}), @@ -170,11 +170,11 @@ hooks(Host) -> {mam_muc_remove_archive, Host, ?MODULE, remove_archive, 50}, {get_mam_muc_gdpr_data, Host, ?MODULE, get_mam_muc_gdpr_data, 50}]. --spec make_document_id(binary(), mod_mam:message_id()) -> binary(). +-spec make_document_id(binary(), mod_mam_pm:message_id()) -> binary(). make_document_id(Room, MessageId) -> <>. --spec make_document(mod_mam:message_id(), binary(), binary(), exml:element(), +-spec make_document(mod_mam_pm:message_id(), binary(), binary(), exml:element(), binary()) -> map(). make_document(MessageId, Room, SourceBinJid, Packet, FromJID) -> #{mam_id => MessageId, @@ -227,13 +227,13 @@ range_filter(#{end_ts := End, start_ts := Start, borders := Borders, rsm := RSM} range_filter(_) -> []. --spec maybe_add_end_filter(undefined | mod_mam:message_id(), map()) -> map(). +-spec maybe_add_end_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). maybe_add_end_filter(undefined, RangeMap) -> RangeMap; maybe_add_end_filter(Value, RangeMap) -> RangeMap#{le => Value}. --spec maybe_add_start_filter(undefined | mod_mam:message_id(), map()) -> map(). +-spec maybe_add_start_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). maybe_add_start_filter(undefined, RangeMap) -> RangeMap; maybe_add_start_filter(Value, RangeMap) -> @@ -260,7 +260,7 @@ maybe_add_from_constraint(Query, #{rsm := #rsm_in{index = Offset}}) when is_inte maybe_add_from_constraint(Query, _) -> Query. --spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam:lookup_result(). +-spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam_pm:lookup_result(). search_result_to_mam_lookup_result(Result, Params) -> #{<<"hits">> := #{<<"hits">> := Hits, @@ -279,7 +279,7 @@ search_result_to_mam_lookup_result(Result, Params) -> {CorrectedTotalCount, Offset, Messages} end. --spec hit_to_mam_message(map()) -> mod_mam:message_row(). +-spec hit_to_mam_message(map()) -> mod_mam_pm:message_row(). hit_to_mam_message(#{<<"_source">> := JSON}) -> MessageId = maps:get(<<"mam_id">>, JSON), Packet = maps:get(<<"message">>, JSON), diff --git a/src/mam/mod_mam_muc_rdbms_arch.erl b/src/mam/mod_mam_muc_rdbms_arch.erl index 9114fc63d32..646b4bce960 100644 --- a/src/mam/mod_mam_muc_rdbms_arch.erl +++ b/src/mam/mod_mam_muc_rdbms_arch.erl @@ -71,7 +71,7 @@ supported_features() -> host_type(), jid:jid()) -> ejabberd_gen_mam_archive:mam_muc_gdpr_data(). get_mam_muc_gdpr_data(Acc, HostType, #jid{luser = LUser, lserver = LServer} = _UserJID) -> - case mod_mam:archive_id(LServer, LUser) of + case mod_mam_pm:archive_id(LServer, LUser) of undefined -> Acc; SenderID -> @@ -82,7 +82,7 @@ get_mam_muc_gdpr_data(Acc, HostType, #jid{luser = LUser, lserver = LServer} = _U end. %% ---------------------------------------------------------------------- -%% Add hooks for mod_mam +%% Add hooks for mod_mam_pm -spec start_hooks(host_type()) -> ok. start_hooks(HostType) -> @@ -212,7 +212,7 @@ get_retract_id(Packet, #{has_message_retraction := Enabled}) -> %% Internal functions and callbacks -spec archive_size(Size :: integer(), HostType :: mongooseim:host_type(), - ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) -> integer(). + ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) -> integer(). archive_size(Size, HostType, ArcID, ArcJID) when is_integer(Size) -> Filter = [{equal, room_id, ArcID}], Env = env_vars(HostType, ArcJID), @@ -221,11 +221,11 @@ archive_size(Size, HostType, ArcID, ArcJID) when is_integer(Size) -> extend_params_with_sender_id(HostType, Params = #{remote_jid := SenderJID}) -> BareSenderJID = jid:to_bare(SenderJID), - SenderID = mod_mam:archive_id_int(HostType, BareSenderJID), + SenderID = mod_mam_pm:archive_id_int(HostType, BareSenderJID), Params#{sender_id => SenderID}. -spec archive_message(_Result, HostType :: mongooseim:host_type(), - mod_mam:archive_message_params()) -> ok. + mod_mam_pm:archive_message_params()) -> ok. archive_message(_Result, HostType, Params0 = #{local_jid := ArcJID}) -> try Params = extend_params_with_sender_id(HostType, Params0), @@ -246,12 +246,12 @@ do_archive_message(HostType, Params, Env) -> %% Retraction logic %% Called after inserting a new message --spec retract_message(mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. +-spec retract_message(mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. retract_message(HostType, #{local_jid := ArcJID} = Params) -> Env = env_vars(HostType, ArcJID), retract_message(HostType, Params, Env). --spec retract_message(mongooseim:host_type(), mod_mam:archive_message_params(), env_vars()) -> ok. +-spec retract_message(mongooseim:host_type(), mod_mam_pm:archive_message_params(), env_vars()) -> ok. retract_message(HostType, #{archive_id := ArcID, sender_id := SenderID, packet := Packet} = Params, Env) -> case get_retract_id(Packet, Env) of @@ -291,7 +291,7 @@ execute_make_tombstone(HostType, TombstoneData, ArcID, MessID) -> [TombstoneData, ArcID, MessID]). %% Insert logic --spec prepare_message(mongooseim:host_type(), mod_mam:archive_message_params()) -> list(). +-spec prepare_message(mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> list(). prepare_message(HostType, Params = #{local_jid := ArcJID}) -> Env = env_vars(HostType, ArcJID), mam_encoder:encode_message(Params, Env, db_mappings()). @@ -306,7 +306,7 @@ prepare_insert(Name, NumRows) -> %% Removal logic -spec remove_archive(Acc :: mongoose_acc:t(), HostType :: mongooseim:host_type(), - ArcID :: mod_mam:archive_id(), + ArcID :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, ArcID, _ArcJID) -> mongoose_rdbms:execute_successfully(HostType, mam_muc_archive_remove, [ArcID]), @@ -345,7 +345,7 @@ extract_gdpr_messages(HostType, SenderID) -> %% Lookup logic -spec lookup_messages(Result :: any(), HostType :: mongooseim:host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()}. + {ok, mod_mam_pm:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, HostType, Params = #{owner_jid := ArcJID}) -> diff --git a/src/mam/mod_mam_muc_rdbms_arch_async.erl b/src/mam/mod_mam_muc_rdbms_arch_async.erl index 6199a9e8d4c..5d8a6d92e4d 100644 --- a/src/mam/mod_mam_muc_rdbms_arch_async.erl +++ b/src/mam/mod_mam_muc_rdbms_arch_async.erl @@ -12,7 +12,7 @@ -export([archive_muc_message/3, mam_muc_archive_sync/2, flush/2]). -ignore_xref([archive_muc_message/3, mam_muc_archive_sync/2, flush/2]). --spec archive_muc_message(_Result, mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. +-spec archive_muc_message(_Result, mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. archive_muc_message(_Result, HostType, Params0 = #{archive_id := RoomID}) -> Params = mod_mam_muc_rdbms_arch:extend_params_with_sender_id(HostType, Params0), mongoose_async_pools:put_task(HostType, muc_mam, RoomID, Params). diff --git a/src/mam/mod_mam_params.erl b/src/mam/mod_mam_params.erl index 4924aaba303..70c740baf16 100644 --- a/src/mam/mod_mam_params.erl +++ b/src/mam/mod_mam_params.erl @@ -16,7 +16,7 @@ -module(mod_mam_params). --type mam_module() :: mod_mam | mod_mam_muc. +-type mam_module() :: mod_mam_pm | mod_mam_muc. -export([extra_params_module/2, max_result_limit/2, default_result_limit/2, has_full_text_search/2, is_archivable_message_module/2, send_message_mod/2, @@ -39,7 +39,7 @@ default_result_limit(Module, HostType) -> gen_mod:get_module_opt(HostType, Module, default_result_limit). --spec has_full_text_search(Module :: mod_mam | mod_mam_muc, mongooseim:host_type()) -> boolean(). +-spec has_full_text_search(Module :: mod_mam_pm | mod_mam_muc, mongooseim:host_type()) -> boolean(). has_full_text_search(Module, HostType) -> gen_mod:get_module_opt(HostType, Module, full_text_search). diff --git a/src/mam/mod_mam.erl b/src/mam/mod_mam_pm.erl similarity index 98% rename from src/mam/mod_mam.erl rename to src/mam/mod_mam_pm.erl index a553cdb2dfa..0c835e100b2 100644 --- a/src/mam/mod_mam.erl +++ b/src/mam/mod_mam_pm.erl @@ -27,7 +27,7 @@ %%% %%% @end %%%------------------------------------------------------------------- --module(mod_mam). +-module(mod_mam_pm). -behavior(gen_mod). -behaviour(mongoose_module_metrics). -xep([{xep, 313}, {version, "0.4.1"}]). @@ -137,8 +137,8 @@ AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]}. --type archive_message_params() :: #{message_id := mod_mam:message_id(), - archive_id := mod_mam:archive_id(), +-type archive_message_params() :: #{message_id := message_id(), + archive_id := archive_id(), local_jid := jid:jid(), remote_jid := jid:jid(), source_jid := jid:jid(), @@ -146,7 +146,7 @@ direction := atom(), packet := exml:element(), %% Only in mod_mam_muc_rdbms_arch:retract_message/2 - sender_id => mod_mam:archive_id()}. + sender_id => archive_id()}. -export_type([rewriter_fun/0, borders/0, @@ -616,7 +616,7 @@ remove_archive_hook(HostType, ArcID, ArcJID=#jid{}) -> ok. -spec lookup_messages(HostType :: host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()} + {ok, lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. lookup_messages(HostType, Params) -> @@ -644,7 +644,7 @@ archive_message_from_ct(Params = #{local_jid := JID}) -> HostType = jid_to_host_type(JID), archive_message(HostType, Params). --spec archive_message(host_type(), mod_mam:archive_message_params()) -> +-spec archive_message(host_type(), archive_message_params()) -> ok | {error, timeout}. archive_message(HostType, Params) -> StartT = erlang:monotonic_time(microsecond), diff --git a/src/mam/mod_mam_rdbms_arch.erl b/src/mam/mod_mam_rdbms_arch.erl index 310431a7486..f8a0809b90e 100644 --- a/src/mam/mod_mam_rdbms_arch.erl +++ b/src/mam/mod_mam_rdbms_arch.erl @@ -85,7 +85,7 @@ supported_features() -> ejabberd_gen_mam_archive:mam_pm_gdpr_data(). get_mam_pm_gdpr_data(Acc, HostType, #jid{luser = LUser, lserver = LServer} = ArcJID) -> - case mod_mam:archive_id(LServer, LUser) of + case mod_mam_pm:archive_id(LServer, LUser) of undefined -> Acc; ArcID -> @@ -94,12 +94,12 @@ get_mam_pm_gdpr_data(Acc, HostType, [uniform_to_gdpr(row_to_uniform_format(Row, Env)) || Row <- Rows] ++ Acc end. --spec uniform_to_gdpr(mod_mam:message_row()) -> tuple(). +-spec uniform_to_gdpr(mod_mam_pm:message_row()) -> tuple(). uniform_to_gdpr(#{id := MessID, jid := RemoteJID, packet := Packet}) -> {integer_to_binary(MessID), jid:to_binary(RemoteJID), exml:to_binary(Packet)}. %% ---------------------------------------------------------------------- -%% Add hooks for mod_mam +%% Add hooks for mod_mam_pm -spec start_hooks(host_type()) -> ok. start_hooks(HostType) -> @@ -195,8 +195,8 @@ env_vars(HostType, ArcJID) -> column_to_id_fn => fun column_to_id/1, lookup_fn => fun lookup_query/5, decode_row_fn => fun row_to_uniform_format/2, - has_message_retraction => mod_mam_utils:has_message_retraction(mod_mam, HostType), - has_full_text_search => mod_mam_utils:has_full_text_search(mod_mam, HostType), + has_message_retraction => mod_mam_utils:has_message_retraction(mod_mam_pm, HostType), + has_full_text_search => mod_mam_utils:has_full_text_search(mod_mam_pm, HostType), db_jid_codec => db_jid_codec(HostType, ?MODULE), db_message_codec => db_message_codec(HostType, ?MODULE)}. @@ -242,14 +242,14 @@ get_retract_id(Packet, #{has_message_retraction := Enabled}) -> %% Internal functions and callbacks -spec archive_size(Size :: integer(), HostType :: host_type(), - ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) -> integer(). + ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) -> integer(). archive_size(Size, HostType, ArcID, ArcJID) when is_integer(Size) -> Filter = [{equal, user_id, ArcID}], Env = env_vars(HostType, ArcJID), Result = lookup_query(count, Env, Filter, unordered, all), mongoose_rdbms:selected_to_integer(Result). --spec archive_message(_Result, host_type(), mod_mam:archive_message_params()) -> ok. +-spec archive_message(_Result, host_type(), mod_mam_pm:archive_message_params()) -> ok. archive_message(_Result, HostType, Params = #{local_jid := ArcJID}) -> try assert_archive_id_provided(Params), @@ -270,12 +270,12 @@ do_archive_message(HostType, Params, Env) -> %% Retraction logic %% Called after inserting a new message --spec retract_message(host_type(), mod_mam:archive_message_params()) -> ok. +-spec retract_message(host_type(), mod_mam_pm:archive_message_params()) -> ok. retract_message(HostType, #{local_jid := ArcJID} = Params) -> Env = env_vars(HostType, ArcJID), retract_message(HostType, Params, Env). --spec retract_message(host_type(), mod_mam:archive_message_params(), env_vars()) -> ok. +-spec retract_message(host_type(), mod_mam_pm:archive_message_params(), env_vars()) -> ok. retract_message(HostType, #{archive_id := ArcID, remote_jid := RemJID, direction := Dir, packet := Packet} = Params, Env) -> case get_retract_id(Packet, Env) of @@ -320,7 +320,7 @@ execute_make_tombstone(HostType, TombstoneData, ArcID, MessID) -> [TombstoneData, ArcID, MessID]). %% Insert logic --spec prepare_message(host_type(), mod_mam:archive_message_params()) -> list(). +-spec prepare_message(host_type(), mod_mam_pm:archive_message_params()) -> list(). prepare_message(HostType, Params = #{local_jid := ArcJID}) -> Env = env_vars(HostType, ArcJID), mam_encoder:encode_message(Params, Env, db_mappings()). @@ -335,7 +335,7 @@ prepare_insert(Name, NumRows) -> %% Removal logic -spec remove_archive(Acc :: mongoose_acc:t(), HostType :: host_type(), - ArcID :: mod_mam:archive_id(), + ArcID :: mod_mam_pm:archive_id(), RoomJID :: jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, ArcID, _ArcJID) -> mongoose_rdbms:execute_successfully(HostType, mam_archive_remove, [ArcID]), @@ -358,7 +358,7 @@ extract_gdpr_messages(Env, ArcID) -> %% Lookup logic -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam:lookup_result()}. + {ok, mod_mam_pm:lookup_result()}. lookup_messages({error, _Reason}=Result, _HostType, _Params) -> Result; lookup_messages(_Result, HostType, Params = #{owner_jid := ArcJID}) -> diff --git a/src/mam/mod_mam_rdbms_arch_async.erl b/src/mam/mod_mam_rdbms_arch_async.erl index d164b6d3980..a46832b9bc6 100644 --- a/src/mam/mod_mam_rdbms_arch_async.erl +++ b/src/mam/mod_mam_rdbms_arch_async.erl @@ -14,7 +14,7 @@ -export([make_pool_opts/2, prepare_insert_queries/2]). --spec archive_pm_message(_Result, mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. +-spec archive_pm_message(_Result, mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. archive_pm_message(_Result, HostType, Params = #{archive_id := ArcID}) -> mongoose_async_pools:put_task(HostType, pm_mam, ArcID, Params). diff --git a/src/mam/mod_mam_rdbms_prefs.erl b/src/mam/mod_mam_rdbms_prefs.erl index b4cfa01b012..02261c0b146 100644 --- a/src/mam/mod_mam_rdbms_prefs.erl +++ b/src/mam/mod_mam_rdbms_prefs.erl @@ -103,8 +103,8 @@ order_by_remote_jid_in_delete(HostType) -> %% ---------------------------------------------------------------------- %% Internal functions and callbacks --spec get_behaviour(Default :: mod_mam:archive_behaviour(), - HostType :: mongooseim:host_type(), ArchiveID :: mod_mam:archive_id(), +-spec get_behaviour(Default :: mod_mam_pm:archive_behaviour(), + HostType :: mongooseim:host_type(), ArchiveID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, HostType, UserID, _LocJID, RemJID) when is_integer(UserID) -> @@ -136,8 +136,8 @@ choose_behaviour(BRemLJID, BRemLBareJID, RemoteJid2Behaviour) -> end. -spec set_prefs(Result :: any(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, HostType, UserID, _ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -159,15 +159,15 @@ set_prefs1(HostType, UserID, DefaultMode, AlwaysJIDs, NeverJIDs) -> end, #{user_id => UserID, retries => 5, delay => 100}), ok. --spec get_prefs(mod_mam:preference(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) - -> mod_mam:preference(). +-spec get_prefs(mod_mam_pm:preference(), HostType :: mongooseim:host_type(), + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) + -> mod_mam_pm:preference(). get_prefs({GlobalDefaultMode, _, _}, HostType, UserID, _ArcJID) -> {selected, Rows} = mongoose_rdbms:execute(HostType, mam_prefs_select, [UserID]), decode_prefs_rows(Rows, GlobalDefaultMode, [], []). -spec remove_archive(mongoose_acc:t(), mongooseim:host_type(), - mod_mam:archive_id(), jid:jid()) -> + mod_mam_pm:archive_id(), jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, UserID, _ArcJID) -> remove_archive(HostType, UserID), @@ -210,10 +210,10 @@ prefs_to_rows(UserID, DefaultMode, AlwaysJIDs, NeverJIDs) -> [DefaultRow|lists:sort(AlwaysRows ++ NeverRows)]. -spec decode_prefs_rows([{binary() | jid:jid(), binary()}], - DefaultMode :: mod_mam:archive_behaviour(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> - {mod_mam:archive_behaviour(), [jid:literal_jid()], [jid:literal_jid()]}. + {mod_mam_pm:archive_behaviour(), [jid:literal_jid()], [jid:literal_jid()]}. decode_prefs_rows([{<<>>, Behaviour}|Rows], _DefaultMode, AlwaysJIDs, NeverJIDs) -> decode_prefs_rows(Rows, decode_behaviour(Behaviour), AlwaysJIDs, NeverJIDs); decode_prefs_rows([{JID, <<"A">>}|Rows], DefaultMode, AlwaysJIDs, NeverJIDs) -> diff --git a/src/mam/mod_mam_rdbms_user.erl b/src/mam/mod_mam_rdbms_user.erl index ba2a6e477f1..12399bc19a2 100644 --- a/src/mam/mod_mam_rdbms_user.erl +++ b/src/mam/mod_mam_rdbms_user.erl @@ -69,16 +69,16 @@ prepare_queries() -> %%==================================================================== %% API %%==================================================================== --spec archive_id(ArcID :: undefined | mod_mam:archive_id(), +-spec archive_id(ArcID :: undefined | mod_mam_pm:archive_id(), HostType :: mongooseim:host_type(), - ArchiveJID :: jid:jid()) -> mod_mam:archive_id(). + ArchiveJID :: jid:jid()) -> mod_mam_pm:archive_id(). archive_id(undefined, HostType, _ArcJID=#jid{lserver = LServer, luser = LUser}) -> query_archive_id(HostType, LServer, LUser); archive_id(ArcID, _Host, _ArcJID) -> ArcID. -spec remove_archive(Acc :: map(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam:archive_id(), + ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) -> map(). remove_archive(Acc, HostType, _ArcID, _ArcJID = #jid{lserver = LServer, luser = LUser}) -> execute_user_remove(HostType, LServer, LUser), diff --git a/src/mam/mod_mam_riak_timed_arch_yz.erl b/src/mam/mod_mam_riak_timed_arch_yz.erl index 0838c683457..d4dae30b25e 100644 --- a/src/mam/mod_mam_riak_timed_arch_yz.erl +++ b/src/mam/mod_mam_riak_timed_arch_yz.erl @@ -221,7 +221,7 @@ archive_message(Host, MessID, LocJID, RemJID, SrcJID, OwnerJID, Packet, Type) -> create_obj(Host, MsgId, SourceJID, BareOwnerJID, Packet, Type) -> ModMAM = case Type of - pm -> mod_mam; + pm -> mod_mam_pm; muc -> mod_mam_muc end, BodyChars = mod_mam_utils:packet_to_search_body(ModMAM, Host, Packet), diff --git a/src/mam/mod_mam_utils.erl b/src/mam/mod_mam_utils.erl index d73f4287771..6c091b4aad4 100644 --- a/src/mam/mod_mam_utils.erl +++ b/src/mam/mod_mam_utils.erl @@ -136,16 +136,16 @@ -type ne_binary() :: <<_:8, _:_*8>>. -type iso8601_datetime_binary() :: ne_binary(). %% Microseconds from 01.01.1970 --type unix_timestamp() :: mod_mam:unix_timestamp(). +-type unix_timestamp() :: mod_mam_pm:unix_timestamp(). --type archive_behaviour() :: mod_mam:archive_behaviour(). +-type archive_behaviour() :: mod_mam_pm:archive_behaviour(). -type archive_behaviour_bin() :: binary(). % `<<"roster">> | <<"always">> | <<"never">>'. -type direction() :: incoming | outgoing. -type retraction_id() :: {origin_id | stanza_id, binary()}. -type retraction_info() :: #{retract_on := origin_id | stanza_id, packet := exml:element(), - message_id := mod_mam:message_id(), + message_id := mod_mam_pm:message_id(), origin_id := null | binary()}. %% ----------------------------------------------------------------------- @@ -577,7 +577,7 @@ maybe_transform_fin_elem(undefined, _HostType, _Params, FinEl) -> maybe_transform_fin_elem(Module, HostType, Params, FinEl) -> Module:extra_fin_element(HostType, Params, FinEl). --spec parse_prefs(PrefsEl :: exml:element()) -> mod_mam:preference(). +-spec parse_prefs(PrefsEl :: exml:element()) -> mod_mam_pm:preference(). parse_prefs(El = #xmlel{ name = <<"prefs">> }) -> Default = exml_query:attr(El, <<"default">>), AlwaysJIDs = parse_jid_list(El, <<"always">>), @@ -620,7 +620,7 @@ binary_jid_to_lower(BinJid) when is_binary(BinJid) -> skip_bad_jids(MaybeJids) -> [Jid || Jid <- MaybeJids, is_binary(Jid)]. --spec borders_decode(exml:element()) -> 'undefined' | mod_mam:borders(). +-spec borders_decode(exml:element()) -> 'undefined' | mod_mam_pm:borders(). borders_decode(QueryEl) -> AfterID = tag_id(QueryEl, <<"after_id">>), BeforeID = tag_id(QueryEl, <<"before_id">>), @@ -628,7 +628,7 @@ borders_decode(QueryEl) -> ToID = tag_id(QueryEl, <<"to_id">>), borders(AfterID, BeforeID, FromID, ToID). --spec form_borders_decode(exml:element()) -> 'undefined' | mod_mam:borders(). +-spec form_borders_decode(exml:element()) -> 'undefined' | mod_mam_pm:borders(). form_borders_decode(QueryEl) -> AfterID = form_field_mess_id(QueryEl, <<"after_id">>), BeforeID = form_field_mess_id(QueryEl, <<"before_id">>), @@ -641,7 +641,7 @@ form_borders_decode(QueryEl) -> BeforeID :: 'undefined' | non_neg_integer(), FromID :: 'undefined' | non_neg_integer(), ToID :: 'undefined' | non_neg_integer() - ) -> 'undefined' | mod_mam:borders(). + ) -> 'undefined' | mod_mam_pm:borders(). borders(undefined, undefined, undefined, undefined) -> undefined; borders(AfterID, BeforeID, FromID, ToID) -> @@ -734,7 +734,7 @@ find_field([], _Name) -> field_to_value(FieldEl) -> exml_query:path(FieldEl, [{element, <<"value">>}, cdata], <<>>). --spec message_form(Mod :: mod_mam | mod_mam_muc, +-spec message_form(Mod :: mod_mam_pm | mod_mam_muc, HostType :: mongooseim:host_type(), binary()) -> exml:element(). message_form(Module, HostType, MamNs) -> @@ -801,7 +801,7 @@ normalize_search_text(Text, WordSeparator) -> Re2 = re:replace(Re1, "\s+", unicode:characters_to_list(WordSeparator), ReOpts), unicode:characters_to_binary(Re2). --spec packet_to_search_body(Module :: mod_mam | mod_mam_muc, +-spec packet_to_search_body(Module :: mod_mam_pm | mod_mam_muc, HostType :: mongooseim:host_type(), Packet :: exml:element()) -> binary(). packet_to_search_body(Module, HostType, Packet) -> @@ -816,14 +816,14 @@ packet_to_search_body(true, Packet) -> packet_to_search_body(false, _Packet) -> <<>>. --spec has_full_text_search(Module :: mod_mam | mod_mam_muc, +-spec has_full_text_search(Module :: mod_mam_pm | mod_mam_muc, HostType :: mongooseim:host_type()) -> boolean(). has_full_text_search(Module, HostType) -> gen_mod:get_module_opt(HostType, Module, full_text_search). %% Message retraction --spec has_message_retraction(Module :: mod_mam | mod_mam_muc, +-spec has_message_retraction(Module :: mod_mam_pm | mod_mam_muc, HostType :: mongooseim:host_type()) -> boolean(). has_message_retraction(Module, HostType) -> gen_mod:get_module_opt(HostType, Module, message_retraction). @@ -945,7 +945,7 @@ maybe_integer(<<>>, Def) -> Def; maybe_integer(Bin, _Def) when is_binary(Bin) -> binary_to_integer(Bin). --spec apply_start_border('undefined' | mod_mam:borders(), undefined | integer()) -> +-spec apply_start_border('undefined' | mod_mam_pm:borders(), undefined | integer()) -> undefined | integer(). apply_start_border(undefined, StartID) -> StartID; @@ -953,16 +953,16 @@ apply_start_border(#mam_borders{after_id=AfterID, from_id=FromID}, StartID) -> maybe_max(maybe_next_id(AfterID), maybe_max(FromID, StartID)). --spec apply_end_border('undefined' | mod_mam:borders(), undefined | integer()) -> +-spec apply_end_border('undefined' | mod_mam_pm:borders(), undefined | integer()) -> undefined | integer(). apply_end_border(undefined, EndID) -> EndID; apply_end_border(#mam_borders{before_id=BeforeID, to_id=ToID}, EndID) -> maybe_min(maybe_previous_id(BeforeID), maybe_min(ToID, EndID)). --spec calculate_msg_id_borders(mod_mam:borders() | undefined, - mod_mam:unix_timestamp() | undefined, - mod_mam:unix_timestamp() | undefined) -> R when +-spec calculate_msg_id_borders(mod_mam_pm:borders() | undefined, + mod_mam_pm:unix_timestamp() | undefined, + mod_mam_pm:unix_timestamp() | undefined) -> R when R :: {integer() | undefined, integer() | undefined}. calculate_msg_id_borders(Borders, Start, End) -> StartID = maybe_encode_compact_uuid(Start, 0), @@ -972,9 +972,9 @@ calculate_msg_id_borders(Borders, Start, End) -> -spec calculate_msg_id_borders(RSM, Borders, Start, End) -> R when RSM :: jlib:rsm_in() | undefined, - Borders :: mod_mam:borders() | undefined, - Start :: mod_mam:unix_timestamp() | undefined, - End :: mod_mam:unix_timestamp() | undefined, + Borders :: mod_mam_pm:borders() | undefined, + Start :: mod_mam_pm:unix_timestamp() | undefined, + End :: mod_mam_pm:unix_timestamp() | undefined, R :: {integer() | undefined, integer() | undefined}. calculate_msg_id_borders(undefined, Borders, Start, End) -> calculate_msg_id_borders(Borders, Start, End); @@ -989,7 +989,7 @@ calculate_msg_id_borders(#rsm_in{direction = before, id = Id}, Borders, Start, E {StartId, EndId} = mod_mam_utils:calculate_msg_id_borders(Borders, Start, End), {StartId, mod_mam_utils:maybe_min(EndId, Id)}. --spec maybe_encode_compact_uuid(mod_mam:unix_timestamp() | undefined, integer()) -> +-spec maybe_encode_compact_uuid(mod_mam_pm:unix_timestamp() | undefined, integer()) -> undefined | integer(). maybe_encode_compact_uuid(undefined, _) -> undefined; @@ -1113,7 +1113,7 @@ wait_shaper(HostType, Host, Action, From) -> %% ----------------------------------------------------------------------- %% Ejabberd --spec send_message(mod_mam:message_row(), jid:jid(), jid:jid(), exml:element()) -> mongoose_acc:t(). +-spec send_message(mod_mam_pm:message_row(), jid:jid(), jid:jid(), exml:element()) -> mongoose_acc:t(). send_message(_Row, From, To, Mess) -> ejabberd_sm:route(From, To, Mess). @@ -1131,7 +1131,7 @@ wrapper_id() -> -spec check_result_for_policy_violation(Params, Result) -> Result when Params :: mam_iq:lookup_params(), - Result :: {ok, mod_mam:lookup_result()} + Result :: {ok, mod_mam_pm:lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. check_result_for_policy_violation( @@ -1162,8 +1162,8 @@ is_policy_violation(TotalCount, Offset, MaxResultLimit, LimitPassed) -> -spec check_for_item_not_found(RSM, PageSize, LookupResult) -> R when RSM :: jlib:rsm_in() | undefined, PageSize :: non_neg_integer(), - LookupResult :: mod_mam:lookup_result(), - R :: {ok, mod_mam:lookup_result()} | {error, item_not_found}. + LookupResult :: mod_mam_pm:lookup_result(), + R :: {ok, mod_mam_pm:lookup_result()} | {error, item_not_found}. check_for_item_not_found(#rsm_in{direction = before, id = ID}, PageSize, {TotalCount, Offset, MessageRows}) -> case maybe_last(MessageRows) of diff --git a/src/metrics/mongoose_metrics_mam_hooks.erl b/src/metrics/mongoose_metrics_mam_hooks.erl index 0a389f4da6d..c2738de5718 100644 --- a/src/metrics/mongoose_metrics_mam_hooks.erl +++ b/src/metrics/mongoose_metrics_mam_hooks.erl @@ -40,7 +40,7 @@ %% Implementation %%------------------- -%% @doc Here will be declared which hooks should be registered when mod_mam is enabled. +%% @doc Here will be declared which hooks should be registered when mod_mam_pm is enabled. -spec get_mam_hooks(_) -> [ejabberd_hooks:hook(), ...]. get_mam_hooks(Host) -> [ @@ -66,14 +66,14 @@ get_mam_muc_hooks(Host) -> -spec mam_get_prefs(Result :: any(), Host :: jid:server(), - _ArcID :: mod_mam:archive_id(), + _ArcID :: mod_mam_pm:archive_id(), _ArcJID :: jid:jid()) -> any(). mam_get_prefs(Result, Host, _ArcID, _ArcJID) -> mongoose_metrics:update(Host, modMamPrefsGets, 1), Result. -spec mam_set_prefs(Result :: any(), Host :: jid:server(), - _ArcID :: mod_mam:archive_id(), _ArcJID :: jid:jid(), + _ArcID :: mod_mam_pm:archive_id(), _ArcJID :: jid:jid(), _DefaultMode :: any(), _AlwaysJIDs :: [jid:literal_jid()], _NeverJIDs :: [jid:literal_jid()]) -> any(). mam_set_prefs(Result, Host, _ArcID, _ArcJID, _DefaultMode, _AlwaysJIDs, _NeverJIDs) -> @@ -82,7 +82,7 @@ mam_set_prefs(Result, Host, _ArcID, _ArcJID, _DefaultMode, _AlwaysJIDs, _NeverJI -spec mam_remove_archive(Acc :: map(), Host :: jid:server(), - _ArcID :: mod_mam:archive_id(), + _ArcID :: mod_mam_pm:archive_id(), _ArcJID :: jid:jid()) -> metrics_notify_return(). mam_remove_archive(Acc, Host, _ArcID, _ArcJID) -> mongoose_metrics:update(Host, modMamArchiveRemoved, 1), @@ -103,7 +103,7 @@ mam_lookup_messages(Result = {error, _}, _Host, _Params) -> Result. -spec mam_archive_message(Result :: any(), Host :: jid:server(), - _Params :: mod_mam:archive_message_params()) -> any(). + _Params :: mod_mam_pm:archive_message_params()) -> any(). mam_archive_message(Result, Host, _Params) -> mongoose_metrics:update(Host, modMamArchived, 1), Result. @@ -137,7 +137,7 @@ mam_muc_lookup_messages(Result = {error, _}, Result. -spec mam_muc_archive_message(Result :: any(), Host :: jid:server(), - _Params :: mod_mam:archive_message_params()) -> any(). + _Params :: mod_mam_pm:archive_message_params()) -> any(). mam_muc_archive_message(Result, Host, _Params) -> mongoose_metrics:update(Host, modMucMamArchived, 1), Result. diff --git a/src/mod_commands.erl b/src/mod_commands.erl index 856ab44b25c..bf8a489ca65 100644 --- a/src/mod_commands.erl +++ b/src/mod_commands.erl @@ -463,7 +463,7 @@ change_user_password(Host, User, Password) -> {error, bad_request, "invalid jid"} end. --spec row_to_map(mod_mam:message_row()) -> map(). +-spec row_to_map(mod_mam_pm:message_row()) -> map(). row_to_map(#{id := Id, jid := From, packet := Msg}) -> Jbin = jid:to_binary(From), {Msec, _} = mod_mam_utils:decode_compact_uuid(Id), @@ -495,7 +495,7 @@ lookup_recent_messages(ArcJID, With, Before, Limit) when is_binary(With) -> lookup_recent_messages(ArcJID, WithJID, Before, Limit) -> #jid{luser = LUser, lserver = LServer} = ArcJID, {ok, HostType} = mongoose_domain_api:get_domain_host_type(LServer), - Params = #{archive_id => mod_mam:archive_id(LServer, LUser), + Params = #{archive_id => mod_mam_pm:archive_id(LServer, LUser), owner_jid => ArcJID, borders => undefined, rsm => #rsm_in{direction = before, id = undefined}, % last msgs @@ -508,7 +508,7 @@ lookup_recent_messages(ArcJID, WithJID, Before, Limit) -> limit_passed => false, max_result_limit => 1, is_simple => true}, - R = mod_mam:lookup_messages(HostType, Params), + R = mod_mam_pm:lookup_messages(HostType, Params), {ok, {_, _, L}} = R, L. diff --git a/src/mongoose_client_api/mongoose_client_api_messages.erl b/src/mongoose_client_api/mongoose_client_api_messages.erl index c8d351d2987..d7ae1bdb306 100644 --- a/src/mongoose_client_api/mongoose_client_api_messages.erl +++ b/src/mongoose_client_api/mongoose_client_api_messages.erl @@ -57,13 +57,13 @@ maybe_to_json_with_jid(error, _, Req, State) -> maybe_to_json_with_jid(WithJID, #jid{} = JID, Req, State = #{creds := Creds}) -> HostType = mongoose_credentials:host_type(Creds), Now = os:system_time(microsecond), - ArchiveID = mod_mam:archive_id_int(HostType, JID), + ArchiveID = mod_mam_pm:archive_id_int(HostType, JID), QS = cowboy_req:parse_qs(Req), PageSize = maybe_integer(proplists:get_value(<<"limit">>, QS, <<"50">>)), Before = maybe_integer(proplists:get_value(<<"before">>, QS)), End = maybe_before_to_us(Before, Now), RSM = #rsm_in{direction = before, id = undefined}, - R = mod_mam:lookup_messages(HostType, + R = mod_mam_pm:lookup_messages(HostType, #{archive_id => ArchiveID, owner_jid => JID, rsm => RSM, diff --git a/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl b/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl index 2dc779543b5..f687ca511d3 100644 --- a/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl +++ b/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl @@ -164,7 +164,7 @@ encode(Packet, Timestamp) -> Msg = make_json_item(Packet, FromJID, Timestamp), Msg#{room => FromJID#jid.luser}. --spec make_json_item(mod_mam:message_row()) -> term(). +-spec make_json_item(mod_mam_pm:message_row()) -> term(). make_json_item(#{id := MAMID, jid := JID, packet := Msg}) -> {Microsec, _} = mod_mam_utils:decode_compact_uuid(MAMID), make_json_item(Msg, JID, Microsec div 1000). diff --git a/src/mongoose_deprecations.erl b/src/mongoose_deprecations.erl index bc1659ae503..4891c371f36 100644 --- a/src/mongoose_deprecations.erl +++ b/src/mongoose_deprecations.erl @@ -29,7 +29,7 @@ -type deprecation_tag() :: any(). % Specifies the deprecation -type log_level() :: warning | error. --type unix_timestamp() :: mod_mam:unix_timestamp(). +-type unix_timestamp() :: mod_mam_pm:unix_timestamp(). -type log_map() :: map(). diff --git a/src/mongoose_hooks.erl b/src/mongoose_hooks.erl index c60646178f9..ebe9f054519 100644 --- a/src/mongoose_hooks.erl +++ b/src/mongoose_hooks.erl @@ -961,7 +961,7 @@ room_new_affiliations(Acc, Room, NewAffs, Version) -> -spec mam_archive_id(HostType, OwnerJID) -> Result when HostType :: mongooseim:host_type(), OwnerJID :: jid:jid(), - Result :: undefined | mod_mam:archive_id(). + Result :: undefined | mod_mam_pm:archive_id(). mam_archive_id(HostType, OwnerJID) -> run_hook_for_host_type(mam_archive_id, HostType, undefined, [HostType, OwnerJID]). @@ -969,7 +969,7 @@ mam_archive_id(HostType, OwnerJID) -> %%% of the archive for a given JID -spec mam_archive_size(HostType, ArchiveID, OwnerJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), OwnerJID :: jid:jid(), Result :: integer(). mam_archive_size(HostType, ArchiveID, OwnerJID) -> @@ -981,10 +981,10 @@ mam_archive_size(HostType, ArchiveID, OwnerJID) -> -spec mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> Result when HookServer :: jid:lserver(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), OwnerJID :: jid:jid(), RemoteJID :: jid:jid(), - Result :: mod_mam:archive_behaviour(). + Result :: mod_mam_pm:archive_behaviour(). mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> run_hook_for_host_type(mam_get_behaviour, HookServer, always, [HookServer, ArchiveID, OwnerJID, RemoteJID]). @@ -995,9 +995,9 @@ mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> -spec mam_set_prefs(HookServer, ArchiveId, OwnerJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when HookServer :: jid:lserver(), - ArchiveId :: undefined | mod_mam:archive_id(), + ArchiveId :: undefined | mod_mam_pm:archive_id(), OwnerJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literel_jid()], Result :: any(). @@ -1010,12 +1010,12 @@ mam_set_prefs(HookServer, ArchiveID, OwnerJID, DefaultMode, AlwaysJIDs, NeverJI %%% the archive settings for a given user. -spec mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> Result when HookServer :: jid:lserver(), - DefaultMode :: mod_mam:archive_behaviour(), - ArchiveID :: undefined | mod_mam:archive_id(), + DefaultMode :: mod_mam_pm:archive_behaviour(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), OwnerJID :: jid:jid(), - Result :: mod_mam:preference() | {error, Reason :: term()}. + Result :: mod_mam_pm:preference() | {error, Reason :: term()}. mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> - InitialAccValue = {DefaultMode, [], []}, %% mod_mam:preference() type + InitialAccValue = {DefaultMode, [], []}, %% mod_mam_pm:preference() type run_hook_for_host_type(mam_get_prefs, HookServer, InitialAccValue, [HookServer, ArchiveID, OwnerJID]). @@ -1023,7 +1023,7 @@ mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> %%% remove the entire archive for a particular user. -spec mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> any() when HookServer :: jid:lserver(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), OwnerJID :: jid:jid(). mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> run_hook_for_host_type(mam_remove_archive, HookServer, ok, @@ -1034,9 +1034,9 @@ mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> -spec mam_lookup_messages(HookServer, Params) -> Result when HookServer :: jid:lserver(), Params :: map(), - Result :: {ok, mod_mam:lookup_result()}. + Result :: {ok, mod_mam_pm:lookup_result()}. mam_lookup_messages(HookServer, Params) -> - InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type + InitialLookupValue = {0, 0, []}, %% mod_mam_pm:lookup_result() type run_hook_for_host_type(mam_lookup_messages, HookServer, {ok, InitialLookupValue}, [HookServer, Params]). @@ -1045,7 +1045,7 @@ mam_lookup_messages(HookServer, Params) -> -spec mam_archive_message(HookServer, Params) -> Result when HookServer :: jid:lserver(), - Params :: mod_mam:archive_message_params(), + Params :: mod_mam_pm:archive_message_params(), Result :: ok | {error, timeout}. mam_archive_message(HookServer, Params) -> run_hook_for_host_type(mam_archive_message, HookServer, ok, [HookServer, Params]). @@ -1066,7 +1066,7 @@ mam_archive_sync(HostType) -> %% @doc Notifies of a message retraction -spec mam_retraction(mongooseim:host_type(), mod_mam_utils:retraction_info(), - mod_mam:archive_message_params()) -> + mod_mam_pm:archive_message_params()) -> mod_mam_utils:retraction_info(). mam_retraction(HostType, RetractionInfo, Env) -> run_fold(mam_retraction, HostType, RetractionInfo, Env). @@ -1087,7 +1087,7 @@ mam_retraction(HostType, RetractionInfo, Env) -> -spec mam_muc_archive_id(HookServer, OwnerJID) -> Result when HookServer :: jid:lserver(), OwnerJID :: jid:jid(), - Result :: undefined | mod_mam:archive_id(). + Result :: undefined | mod_mam_pm:archive_id(). mam_muc_archive_id(HookServer, OwnerJID) -> run_hook_for_host_type(mam_muc_archive_id, HookServer, undefined, [HookServer, OwnerJID]). @@ -1096,7 +1096,7 @@ mam_muc_archive_id(HookServer, OwnerJID) -> %%% the archive size for a given room. -spec mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), RoomJID :: jid:jid(), Result :: integer(). mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> @@ -1108,12 +1108,12 @@ mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> -spec mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), RoomJID :: jid:jid(), RemoteJID :: jid:jid(), - Result :: mod_mam:archive_behaviour(). + Result :: mod_mam_pm:archive_behaviour(). mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> - DefaultBehaviour = always, %% mod_mam:archive_behaviour() type + DefaultBehaviour = always, %% mod_mam_pm:archive_behaviour() type run_hook_for_host_type(mam_muc_get_behaviour, HostType, DefaultBehaviour, [HostType, ArchiveID, RoomJID, RemoteJID]). @@ -1123,9 +1123,9 @@ mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> -spec mam_muc_set_prefs(HostType, ArchiveId, RoomJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when HostType :: mongooseim:host_type(), - ArchiveId :: undefined | mod_mam:archive_id(), + ArchiveId :: undefined | mod_mam_pm:archive_id(), RoomJID :: jid:jid(), - DefaultMode :: mod_mam:archive_behaviour(), + DefaultMode :: mod_mam_pm:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literel_jid()], Result :: any(). @@ -1139,12 +1139,12 @@ mam_muc_set_prefs(HostType, ArchiveID, RoomJID, DefaultMode, AlwaysJIDs, NeverJI %%% the archive settings for a given room. -spec mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> Result when HostType :: mongooseim:host_type(), - DefaultMode :: mod_mam:archive_behaviour(), - ArchiveID :: undefined | mod_mam:archive_id(), + DefaultMode :: mod_mam_pm:archive_behaviour(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), RoomJID :: jid:jid(), - Result :: mod_mam:preference() | {error, Reason :: term()}. + Result :: mod_mam_pm:preference() | {error, Reason :: term()}. mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> - InitialAcc = {DefaultMode, [], []}, %% mod_mam:preference() type + InitialAcc = {DefaultMode, [], []}, %% mod_mam_pm:preference() type run_hook_for_host_type(mam_muc_get_prefs, HostType, InitialAcc, [HostType, ArchiveID, RoomJID]). @@ -1152,7 +1152,7 @@ mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> %%% archive for a particular user. -spec mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> any() when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam:archive_id(), + ArchiveID :: undefined | mod_mam_pm:archive_id(), RoomJID :: jid:jid(). mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> run_hook_for_host_type(mam_muc_remove_archive, HostType, ok, @@ -1163,9 +1163,9 @@ mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> -spec mam_muc_lookup_messages(HostType, Params) -> Result when HostType :: mongooseim:host_type(), Params :: map(), - Result :: {ok, mod_mam:lookup_result()}. + Result :: {ok, mod_mam_pm:lookup_result()}. mam_muc_lookup_messages(HostType, Params) -> - InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type + InitialLookupValue = {0, 0, []}, %% mod_mam_pm:lookup_result() type run_hook_for_host_type(mam_muc_lookup_messages, HostType, {ok, InitialLookupValue}, [HostType, Params]). @@ -1173,7 +1173,7 @@ mam_muc_lookup_messages(HostType, Params) -> %%% to store the MUC message in the archive. -spec mam_muc_archive_message(HostType, Params) -> Result when HostType :: mongooseim:host_type(), - Params :: mod_mam:archive_message_params(), + Params :: mod_mam_pm:archive_message_params(), Result :: ok | {error, timeout}. mam_muc_archive_message(HostType, Params) -> run_hook_for_host_type(mam_muc_archive_message, HostType, ok, [HostType, Params]). @@ -1194,7 +1194,7 @@ mam_muc_archive_sync(HostType) -> %% @doc Notifies of a muc message retraction -spec mam_muc_retraction(mongooseim:host_type(), mod_mam_utils:retraction_info(), - mod_mam:archive_message_params()) -> + mod_mam_pm:archive_message_params()) -> mod_mam_utils:retraction_info(). mam_muc_retraction(HostType, RetractionInfo, Env) -> run_fold(mam_muc_retraction, HostType, RetractionInfo, Env). diff --git a/test/common/config_parser_helper.erl b/test/common/config_parser_helper.erl index 7b8bdb8dc12..484a4efe6ba 100644 --- a/test/common/config_parser_helper.erl +++ b/test/common/config_parser_helper.erl @@ -476,8 +476,8 @@ all_modules() -> refresh => #{unit => days, value => 13}}, iqdisc => one_queue}, mod_carboncopy => #{iqdisc => no_queue}, - mod_mam => - mod_config(mod_mam, + mod_mam_pm => + mod_config(mod_mam_pm, #{archive_chat_markers => true, archive_groupchats => false, async_writer => default_config([modules, mod_mam_meta, async_writer]), @@ -901,7 +901,7 @@ default_mod_config(mod_keystore) -> #{ram_key_size => 2048, keys => #{}}; default_mod_config(mod_last) -> #{iqdisc => one_queue, backend => mnesia}; -default_mod_config(mod_mam) -> +default_mod_config(mod_mam_pm) -> maps:merge(common_mam_config(), default_config([modules, mod_mam_meta, pm])); default_mod_config(mod_mam_meta) -> (common_mam_config())#{backend => rdbms, cache_users => true, diff --git a/test/mam_misc_SUITE.erl b/test/mam_misc_SUITE.erl index b0b02612dde..0cecfafc8e0 100644 --- a/test/mam_misc_SUITE.erl +++ b/test/mam_misc_SUITE.erl @@ -112,7 +112,7 @@ must_be_accepted(_) -> %% Generators gen_modules() -> - oneof([mod_mam, mod_inbox]). + oneof([mod_mam_pm, mod_inbox]). gen_directions() -> oneof([outgoing, incoming]). diff --git a/test/mod_mam_meta_SUITE.erl b/test/mod_mam_meta_SUITE.erl index eead670d3b6..6b4f6765ab1 100644 --- a/test/mod_mam_meta_SUITE.erl +++ b/test/mod_mam_meta_SUITE.erl @@ -40,12 +40,12 @@ sets_rdbms_as_default_backend(_Config) -> handles_only_pm(_Config) -> Deps = deps(#{pm => default_config([modules, mod_mam_meta, pm])}), - ?assert(lists:keymember(mod_mam, 1, Deps)), + ?assert(lists:keymember(mod_mam_pm, 1, Deps)), ?assertNot(lists:keymember(mod_mam_muc, 1, Deps)). handles_only_muc(_Config) -> Deps = deps(#{muc => default_config([modules, mod_mam_meta, muc])}), - ?assertNot(lists:keymember(mod_mam, 1, Deps)), + ?assertNot(lists:keymember(mod_mam_pm, 1, Deps)), ?assert(lists:keymember(mod_mam_muc, 1, Deps)). disables_sync_writer_on_async_writer(_Config) -> @@ -70,7 +70,7 @@ produces_valid_configurations(_Config) -> Deps = deps(#{pm => PM, muc => MUC}), Cache = default_config([modules, mod_mam_meta, cache]), - check_equal_opts(mod_mam, mod_config(mod_mam, PMCoreOpts), Deps), + check_equal_opts(mod_mam_pm, mod_config(mod_mam_pm, PMCoreOpts), Deps), check_equal_opts(mod_mam_muc, mod_config(mod_mam_muc, MUCCoreOpts), Deps), check_equal_opts(mod_mam_rdbms_arch, default_mod_config(mod_mam_rdbms_arch), Deps), check_equal_opts(mod_mam_muc_rdbms_arch, mod_config(mod_mam_muc_rdbms_arch, @@ -88,7 +88,7 @@ handles_riak_config(_Config) -> db_message_format => some_format, pm => config([modules, mod_mam_meta, pm], PM), muc => config([modules, mod_mam_meta, muc], MUC)}), - ?assert(lists:keymember(mod_mam, 1, Deps)), + ?assert(lists:keymember(mod_mam_pm, 1, Deps)), ?assert(lists:keymember(mod_mam_muc, 1, Deps)), check_equal_opts(mod_mam_riak_timed_arch_yz, #{pm => true, muc => true, db_message_format => some_format}, Deps), @@ -134,7 +134,7 @@ example_pm_only_good_performance(_Config) -> {mod_mam_mnesia_prefs, #{pm => true}}, {mod_mam_rdbms_arch, mod_config(mod_mam_rdbms_arch, #{no_writer => true})}, {mod_mam_rdbms_arch_async, AsyncOpts}, - {mod_mam, default_mod_config(mod_mam)} + {mod_mam_pm, default_mod_config(mod_mam_pm)} ], Deps). %% Helpers From 9b4ef367ef8d1b69c66e2f497d5f179e2fd5857b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Jun 2022 09:44:02 +0200 Subject: [PATCH 2/5] Rename mod_mam_meta to mod_mam --- big_tests/tests/amp_big_SUITE.erl | 5 +- big_tests/tests/domain_removal_SUITE.erl | 4 +- big_tests/tests/gdpr_SUITE.erl | 28 +++++----- big_tests/tests/mam_SUITE.erl | 20 +++---- big_tests/tests/mam_helper.erl | 10 ++-- big_tests/tests/mam_proper_SUITE.erl | 4 +- big_tests/tests/mam_send_message_SUITE.erl | 6 +-- big_tests/tests/muc_SUITE.erl | 2 +- big_tests/tests/muc_light_SUITE.erl | 6 +-- big_tests/tests/muc_light_legacy_SUITE.erl | 6 +-- big_tests/tests/rest_helper.erl | 10 ++-- big_tests/tests/service_domain_db_SUITE.erl | 2 +- .../service_mongoose_system_metrics_SUITE.erl | 4 +- src/config/mongoose_config_spec.erl | 2 +- src/mam/{mod_mam_meta.erl => mod_mam.erl} | 2 +- src/mam/mod_mam_rdbms_arch_async.erl | 2 +- test/common/config_parser_helper.erl | 34 ++++++------ test/config_parser_SUITE.erl | 44 +++++++-------- test/config_parser_SUITE_data/modules.toml | 2 +- ...d_mam_meta_SUITE.erl => mod_mam_SUITE.erl} | 54 +++++++++---------- 20 files changed, 123 insertions(+), 124 deletions(-) rename src/mam/{mod_mam_meta.erl => mod_mam.erl} (99%) rename test/{mod_mam_meta_SUITE.erl => mod_mam_SUITE.erl} (74%) diff --git a/big_tests/tests/amp_big_SUITE.erl b/big_tests/tests/amp_big_SUITE.erl index 5842d3cba73..59b35b18654 100644 --- a/big_tests/tests/amp_big_SUITE.erl +++ b/big_tests/tests/amp_big_SUITE.erl @@ -988,10 +988,9 @@ required_modules(_) -> []. mam_modules(on) -> - [{mod_mam_meta, mam_helper:config_opts(#{pm => #{}, - async_writer => #{enabled => false}})}]; + [{mod_mam, mam_helper:config_opts(#{pm => #{}, async_writer => #{enabled => false}})}]; mam_modules(off) -> - [{mod_mam_meta, stopped}]. + [{mod_mam, stopped}]. offline_modules(on) -> [{mod_offline, config_parser_helper:mod_config(mod_offline, diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index 2406c27013c..dc1a6163f12 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -84,10 +84,10 @@ group_to_modules(auth_removal) -> []; group_to_modules(cache_removal) -> [{mod_cache_users, config_parser_helper:default_mod_config(mod_cache_users)}, - {mod_mam_meta, mam_helper:config_opts(#{pm => #{}})}]; + {mod_mam, mam_helper:config_opts(#{pm => #{}})}]; group_to_modules(mam_removal) -> MucHost = subhost_pattern(muc_light_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{pm => #{}, muc => #{host => MucHost}})}, + [{mod_mam, mam_helper:config_opts(#{pm => #{}, muc => #{host => MucHost}})}, {mod_muc_light, mod_config(mod_muc_light, #{backend => rdbms})}]; group_to_modules(muc_light_removal) -> [{mod_muc_light, mod_config(mod_muc_light, #{backend => rdbms})}]; diff --git a/big_tests/tests/gdpr_SUITE.erl b/big_tests/tests/gdpr_SUITE.erl index 2f8e7353149..7d494e5b4dd 100644 --- a/big_tests/tests/gdpr_SUITE.erl +++ b/big_tests/tests/gdpr_SUITE.erl @@ -354,33 +354,33 @@ groupchat_module(muclight) -> mam_required_modules(CN, Backend) when CN =:= remove_mam_pm; CN =:= retrieve_mam_pm -> - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, pm => #{}})}]; + [{mod_mam, mam_helper:config_opts(#{backend => Backend, pm => #{}})}]; mam_required_modules(CN, Backend) when CN =:= retrieve_mam_pm_and_muc_light_dont_interfere; CN =:= retrieve_mam_muc_light -> HostPattern = subhost_pattern(muc_light_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, - pm => #{}, - muc => #{host => HostPattern}})}, + [{mod_mam, mam_helper:config_opts(#{backend => Backend, + pm => #{}, + muc => #{host => HostPattern}})}, {mod_muc_light, default_mod_config(mod_muc_light)}]; mam_required_modules(retrieve_mam_pm_and_muc_light_interfere, Backend) -> HostPattern = subhost_pattern(muc_light_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, - db_message_format => mam_message_xml, - pm => #{archive_groupchats => true}, - muc => #{host => HostPattern}})}, + [{mod_mam, mam_helper:config_opts(#{backend => Backend, + db_message_format => mam_message_xml, + pm => #{archive_groupchats => true}, + muc => #{host => HostPattern}})}, {mod_muc_light, default_mod_config(mod_muc_light)}]; mam_required_modules(CN, Backend) when CN =:= retrieve_mam_muc_private_msg; CN =:= retrieve_mam_muc -> HostPattern = subhost_pattern(muc_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, - pm => #{}, - muc => #{host => HostPattern}})}, + [{mod_mam, mam_helper:config_opts(#{backend => Backend, + pm => #{}, + muc => #{host => HostPattern}})}, {mod_muc, muc_helper:make_opts(#{host => HostPattern})}]; mam_required_modules(retrieve_mam_muc_store_pm, Backend) -> HostPattern = subhost_pattern(muc_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, - pm => #{archive_groupchats => true}, - muc => #{host => HostPattern}})}, + [{mod_mam, mam_helper:config_opts(#{backend => Backend, + pm => #{archive_groupchats => true}, + muc => #{host => HostPattern}})}, {mod_muc, muc_helper:make_opts(#{host => HostPattern})}]. pick_enabled_backend() -> diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 1367e42fcfd..f2af5271d9b 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -647,19 +647,19 @@ required_modules_for_group(C, muc_light, Config) -> Opts = config_opts(Extra#{pm => #{}, muc => #{host => MUCHost}}), Config1 = maybe_set_wait(C, [muc, pm], [{mam_meta_opts, Opts} | Config]), {[{mod_muc_light, default_mod_config(mod_muc_light)}, - {mod_mam_meta, Opts}], Config1}; + {mod_mam, Opts}], Config1}; required_modules_for_group(C, BG, Config) when BG =:= muc_all; BG =:= muc_disabled_retraction -> Extra = maps:merge(mam_opts_for_conf(C), mam_opts_for_base_group(BG)), MUCHost = subhost_pattern(muc_domain(Config)), Opts = config_opts(Extra#{muc => #{host => MUCHost}}), Config1 = maybe_set_wait(C, [muc], [{mam_meta_opts, Opts} | Config]), - {[{mod_mam_meta, Opts}], Config1}; + {[{mod_mam, Opts}], Config1}; required_modules_for_group(C, BG, Config) -> Extra = maps:merge(mam_opts_for_conf(C), mam_opts_for_base_group(BG)), Opts = config_opts(Extra#{pm => #{}}), Config1 = maybe_set_wait(C, [pm], [{mam_meta_opts, Opts} | Config]), - {[{mod_mam_meta, Opts}], Config1}. + {[{mod_mam, Opts}], Config1}. maybe_set_wait(C, Types, Config) when C =:= rdbms_async_pool; C =:= rdbms_async_cache -> @@ -980,31 +980,31 @@ end_per_testcase(CaseName, Config) -> required_modules(muc_light_stored_in_pm_if_allowed_to, Config) -> Opts = #{pm := PM} = ?config(mam_meta_opts, Config), NewOpts = Opts#{pm := PM#{archive_groupchats => true}}, - [{mod_mam_meta, NewOpts}]; + [{mod_mam, NewOpts}]; required_modules(muc_light_chat_markers_are_archived_if_enabled, Config) -> Opts = #{muc := MUC} = ?config(mam_meta_opts, Config), NewOpts = Opts#{muc := MUC#{archive_chat_markers => true}}, - [{mod_mam_meta, NewOpts}]; + [{mod_mam, NewOpts}]; required_modules(muc_no_elements, Config) -> Opts = #{muc := MUC} = ?config(mam_meta_opts, Config), NewOpts = Opts#{muc := MUC#{no_stanzaid_element => true}}, - [{mod_mam_meta, NewOpts}]; + [{mod_mam, NewOpts}]; required_modules(muc_only_stanzaid, Config) -> Opts = ?config(mam_meta_opts, Config), - [{mod_mam_meta, Opts}]; + [{mod_mam, Opts}]; % configurable_archiveid basic group required_modules(no_elements, Config) -> Opts = #{pm := PM} = ?config(mam_meta_opts, Config), NewOpts = Opts#{pm := PM#{no_stanzaid_element => true}}, - [{mod_mam_meta, NewOpts}]; + [{mod_mam, NewOpts}]; required_modules(CaseName, Config) when CaseName =:= same_stanza_id; CaseName =:= retract_message_on_stanza_id -> Opts = #{pm := PM} = ?config(mam_meta_opts, Config), NewOpts = Opts#{pm := PM#{same_mam_id_for_peers => true}}, - [{mod_mam_meta, NewOpts}]; + [{mod_mam, NewOpts}]; required_modules(_, Config) -> Opts = ?config(mam_meta_opts, Config), - [{mod_mam_meta, Opts}]. + [{mod_mam, Opts}]. %%-------------------------------------------------------------------- %% Group name helpers diff --git a/big_tests/tests/mam_helper.erl b/big_tests/tests/mam_helper.erl index 76b0dce2b3e..4dd47cea2a9 100644 --- a/big_tests/tests/mam_helper.erl +++ b/big_tests/tests/mam_helper.erl @@ -125,15 +125,15 @@ config_opts(ExtraOpts) -> lists:foldl(fun set_opts/2, ExtraOpts, [defaults, backend, pm, muc, async_writer]). set_opts(defaults, Opts) -> - mod_config(mod_mam_meta, Opts); + mod_config(mod_mam, Opts); set_opts(backend, #{backend := riak} = Opts) -> - Opts#{riak => config([modules, mod_mam_meta, riak], maps:get(riak, Opts, #{}))}; + Opts#{riak => config([modules, mod_mam, riak], maps:get(riak, Opts, #{}))}; set_opts(pm, #{pm := PMExtra} = Opts) -> - Opts#{pm := config([modules, mod_mam_meta, pm], PMExtra)}; + Opts#{pm := config([modules, mod_mam, pm], PMExtra)}; set_opts(muc, #{muc := MUCExtra} = Opts) -> - Opts#{muc := config([modules, mod_mam_meta, muc], MUCExtra)}; + Opts#{muc := config([modules, mod_mam, muc], MUCExtra)}; set_opts(async_writer, #{async_writer := AsyncExtra} = Opts) -> - Opts#{async_writer := config([modules, mod_mam_meta, async_writer], AsyncExtra)}; + Opts#{async_writer := config([modules, mod_mam, async_writer], AsyncExtra)}; set_opts(_, Opts) -> Opts. diff --git a/big_tests/tests/mam_proper_SUITE.erl b/big_tests/tests/mam_proper_SUITE.erl index a250052ecce..ee0d56d9cf0 100644 --- a/big_tests/tests/mam_proper_SUITE.erl +++ b/big_tests/tests/mam_proper_SUITE.erl @@ -34,7 +34,7 @@ init_per_group(G, _C) -> end. required_modules(_G) -> - [{mod_mam_meta, mam_helper:config_opts(#{pm => #{}})}]. + [{mod_mam, mam_helper:config_opts(#{pm => #{}})}]. end_per_group(_G, C) -> C. @@ -117,7 +117,7 @@ body() -> packet(To, Body) -> escalus_stanza:chat_to(jid:to_binary(To), Body). -%% Generates mod_mam_pm:archive_message_params() +%% Generates mod_mam:archive_message_params() params() -> ?LET({MessId, ArcId, LocalJid, RemoteJid, OriginId, Dir, Body, SenderId}, diff --git a/big_tests/tests/mam_send_message_SUITE.erl b/big_tests/tests/mam_send_message_SUITE.erl index 3aefec40a60..22cc57ec83f 100644 --- a/big_tests/tests/mam_send_message_SUITE.erl +++ b/big_tests/tests/mam_send_message_SUITE.erl @@ -73,9 +73,9 @@ end_per_group(_Groupname, Config) -> group_to_modules(send_message) -> MH = subhost_pattern(muc_light_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{pm => #{}, - muc => #{host => MH}, - send_message => mam_send_message_example})}, + [{mod_mam, mam_helper:config_opts(#{pm => #{}, + muc => #{host => MH}, + send_message => mam_send_message_example})}, {mod_muc_light, mod_config(mod_muc_light, #{backend => mongoose_helper:mnesia_or_rdbms_backend()})}, {mam_send_message_example, []}]. diff --git a/big_tests/tests/muc_SUITE.erl b/big_tests/tests/muc_SUITE.erl index 042cf0576d3..01bbf737701 100644 --- a/big_tests/tests/muc_SUITE.erl +++ b/big_tests/tests/muc_SUITE.erl @@ -529,7 +529,7 @@ setup_mam(disabled) -> ok; setup_mam(Backend) -> HostPattern = subhost_pattern(muc_helper:muc_host_pattern()), dynamic_modules:ensure_modules( - host_type(), [{mod_mam_meta, + host_type(), [{mod_mam, mam_helper:config_opts(#{backend => Backend, muc => #{host => HostPattern}})}]). diff --git a/big_tests/tests/muc_light_SUITE.erl b/big_tests/tests/muc_light_SUITE.erl index fb07b9aa58e..2ef2699184c 100644 --- a/big_tests/tests/muc_light_SUITE.erl +++ b/big_tests/tests/muc_light_SUITE.erl @@ -259,12 +259,12 @@ end_per_testcase(CaseName, Config) -> %% Module configuration per test case required_modules(CaseName, MAMBackend) -> - [{mod_mam_meta, mam_helper:config_opts(#{backend => MAMBackend, - muc => #{host => subhost_pattern(?MUCHOST)}})} | + [{mod_mam, mam_helper:config_opts(#{backend => MAMBackend, + muc => #{host => subhost_pattern(?MUCHOST)}})} | common_required_modules(CaseName)]. required_modules(CaseName) -> - [{mod_mam_meta, stopped} | common_required_modules(CaseName)]. + [{mod_mam, stopped} | common_required_modules(CaseName)]. common_required_modules(CaseName) -> BasicOpts = maps:merge(common_muc_light_opts(), muc_light_opts(CaseName)), diff --git a/big_tests/tests/muc_light_legacy_SUITE.erl b/big_tests/tests/muc_light_legacy_SUITE.erl index a2e05065855..5e864b54b5e 100644 --- a/big_tests/tests/muc_light_legacy_SUITE.erl +++ b/big_tests/tests/muc_light_legacy_SUITE.erl @@ -191,12 +191,12 @@ end_per_testcase(CaseName, Config) -> %% Module configuration per test case required_modules(CaseName, MAMBackend) -> - [{mod_mam_meta, mam_helper:config_opts(#{backend => MAMBackend, - muc => #{host => subhost_pattern(?MUCHOST)}})} | + [{mod_mam, mam_helper:config_opts(#{backend => MAMBackend, + muc => #{host => subhost_pattern(?MUCHOST)}})} | common_required_modules(CaseName)]. required_modules(CaseName) -> - [{mod_mam_meta, stopped} | common_required_modules(CaseName)]. + [{mod_mam, stopped} | common_required_modules(CaseName)]. common_required_modules(CaseName) -> Opts = maps:merge(common_muc_light_opts(), muc_light_opts(CaseName)), diff --git a/big_tests/tests/rest_helper.erl b/big_tests/tests/rest_helper.erl index eeddcff0e7c..b1a1961bffa 100644 --- a/big_tests/tests/rest_helper.erl +++ b/big_tests/tests/rest_helper.erl @@ -329,11 +329,11 @@ maybe_enable_mam(_, _, C) -> required_mam_modules(Backend) -> MucPattern = subhost_pattern(muc_light_helper:muc_host_pattern()), - [{mod_mam_meta, mam_helper:config_opts(#{backend => Backend, - pm => #{}, - muc => #{host => MucPattern}, - async_writer => #{enabled => false}, - archive_chat_markers => true})}]. + [{mod_mam, mam_helper:config_opts(#{backend => Backend, + pm => #{}, + muc => #{host => MucPattern}, + async_writer => #{enabled => false}, + archive_chat_markers => true})}]. maybe_skip_mam_test_cases(CaseName, CasesRequireingMAM, Config) -> case lists:member(CaseName, CasesRequireingMAM) of diff --git a/big_tests/tests/service_domain_db_SUITE.erl b/big_tests/tests/service_domain_db_SUITE.erl index 0a80e739750..2bc9b9ebc29 100644 --- a/big_tests/tests/service_domain_db_SUITE.erl +++ b/big_tests/tests/service_domain_db_SUITE.erl @@ -259,7 +259,7 @@ end_per_testcase(TestcaseName, Config) -> init_per_testcase2(TestcaseName, Config) when TestcaseName =:= rest_delete_domain_cleans_data_from_mam -> HostType = dummy_auth_host_type(), - Mods = [{mod_mam_meta, mam_helper:config_opts(#{pm => #{}})}], + Mods = [{mod_mam, mam_helper:config_opts(#{pm => #{}})}], dynamic_modules:ensure_modules(HostType, Mods), escalus:init_per_testcase(TestcaseName, Config); init_per_testcase2(_, Config) -> diff --git a/big_tests/tests/service_mongoose_system_metrics_SUITE.erl b/big_tests/tests/service_mongoose_system_metrics_SUITE.erl index 57da0fca4ce..108b9476b3b 100644 --- a/big_tests/tests/service_mongoose_system_metrics_SUITE.erl +++ b/big_tests/tests/service_mongoose_system_metrics_SUITE.erl @@ -237,7 +237,7 @@ rdbms_module_opts_are_reported(_Config) -> mongoose_helper:wait_until(fun are_modules_reported/0, true), check_module_backend(mod_auth_token, rdbms), check_module_backend(mod_inbox, rdbms), - check_module_backend(mod_mam_meta, rdbms). + check_module_backend(mod_mam, rdbms). check_module_backend(Module, Backend) -> check_module_opt(Module, backend, atom_to_binary(Backend)). @@ -356,7 +356,7 @@ modules_to_test(module_opts_are_reported) -> modules_to_test(rdbms_module_opts_are_reported) -> [required_module(mod_auth_token), required_module(mod_inbox), - required_module(mod_mam_meta)]. + required_module(mod_mam)]. required_module(Module) -> required_module(Module, #{}). diff --git a/src/config/mongoose_config_spec.erl b/src/config/mongoose_config_spec.erl index 26ee7c4dc8d..803a7b411fd 100644 --- a/src/config/mongoose_config_spec.erl +++ b/src/config/mongoose_config_spec.erl @@ -738,7 +738,7 @@ configurable_modules() -> mod_jingle_sip, mod_keystore, mod_last, - mod_mam_meta, + mod_mam, mod_muc, mod_muc_light, mod_muc_log, diff --git a/src/mam/mod_mam_meta.erl b/src/mam/mod_mam.erl similarity index 99% rename from src/mam/mod_mam_meta.erl rename to src/mam/mod_mam.erl index 588eb119820..cc3a5863df1 100644 --- a/src/mam/mod_mam_meta.erl +++ b/src/mam/mod_mam.erl @@ -14,7 +14,7 @@ %% limitations under the License. %%============================================================================== --module(mod_mam_meta). +-module(mod_mam). -behaviour(gen_mod). -behaviour(mongoose_module_metrics). diff --git a/src/mam/mod_mam_rdbms_arch_async.erl b/src/mam/mod_mam_rdbms_arch_async.erl index a46832b9bc6..b242a85acf4 100644 --- a/src/mam/mod_mam_rdbms_arch_async.erl +++ b/src/mam/mod_mam_rdbms_arch_async.erl @@ -45,7 +45,7 @@ supported_features() -> [dynamic_domains]. %%% internal callbacks --spec make_pool_opts(mod_mam_meta:mam_type(), gen_mod:module_opts()) -> +-spec make_pool_opts(mod_mam:mam_type(), gen_mod:module_opts()) -> {mongoose_async_pools:pool_opts(), mongoose_async_pools:pool_extra()}. make_pool_opts(Type, Opts) -> Extra = add_batch_name(Type, Opts), diff --git a/test/common/config_parser_helper.erl b/test/common/config_parser_helper.erl index 484a4efe6ba..8f6a64fc0dc 100644 --- a/test/common/config_parser_helper.erl +++ b/test/common/config_parser_helper.erl @@ -411,12 +411,12 @@ all_modules() -> mod_mam_muc => mod_config(mod_mam_muc, #{archive_chat_markers => true, - async_writer => config([modules, mod_mam_meta, async_writer], + async_writer => config([modules, mod_mam, async_writer], #{enabled => false}), host => {fqdn, <<"muc.example.com">>}, no_stanzaid_element => true}), mod_caps => default_mod_config(mod_caps), - mod_mam_cache_user => (default_config([modules, mod_mam_meta, cache]))#{muc => true, pm => true}, + mod_mam_cache_user => (default_config([modules, mod_mam, cache]))#{muc => true, pm => true}, mod_offline => mod_config(mod_offline, #{backend => riak, riak => #{bucket_type => <<"offline">>}}), @@ -435,7 +435,7 @@ all_modules() -> mod_event_pusher_rabbit => custom_mod_event_pusher_rabbit(), mod_event_pusher_sns => custom_mod_event_pusher_sns(), mod_adhoc => #{iqdisc => one_queue, report_commands_node => true}, - mod_mam_rdbms_arch_async => default_config([modules, mod_mam_meta, async_writer]), + mod_mam_rdbms_arch_async => default_config([modules, mod_mam, async_writer]), mod_keystore => mod_config(mod_keystore, #{keys => #{access_secret => ram, access_psk => {file, "priv/access_psk"}, @@ -480,7 +480,7 @@ all_modules() -> mod_config(mod_mam_pm, #{archive_chat_markers => true, archive_groupchats => false, - async_writer => default_config([modules, mod_mam_meta, async_writer]), + async_writer => default_config([modules, mod_mam, async_writer]), full_text_search => false, same_mam_id_for_peers => false, no_stanzaid_element => true}), @@ -573,11 +573,11 @@ all_modules() -> groupchat => [muclight], remove_on_kicked => true, reset_markers => [<<"displayed">>]}, - mod_mam_meta => - mod_config(mod_mam_meta, + mod_mam => + mod_config(mod_mam, #{archive_chat_markers => true, muc => - #{async_writer => config([modules, mod_mam_meta, async_writer], + #{async_writer => config([modules, mod_mam, async_writer], #{enabled => false}), db_message_format => mam_message_xml, host => {fqdn, <<"muc.example.com">>}, @@ -902,12 +902,12 @@ default_mod_config(mod_keystore) -> default_mod_config(mod_last) -> #{iqdisc => one_queue, backend => mnesia}; default_mod_config(mod_mam_pm) -> - maps:merge(common_mam_config(), default_config([modules, mod_mam_meta, pm])); -default_mod_config(mod_mam_meta) -> + maps:merge(common_mam_config(), default_config([modules, mod_mam, pm])); +default_mod_config(mod_mam) -> (common_mam_config())#{backend => rdbms, cache_users => true, - cache => default_config([modules, mod_mam_meta, cache])}; + cache => default_config([modules, mod_mam, cache])}; default_mod_config(mod_mam_muc) -> - maps:merge(common_mam_config(), default_config([modules, mod_mam_meta, muc])); + maps:merge(common_mam_config(), default_config([modules, mod_mam, muc])); default_mod_config(mod_mam_rdbms_arch) -> #{no_writer => false, db_message_format => mam_message_compressed_eterm, @@ -1173,17 +1173,17 @@ default_config([modules, mod_privacy, riak]) -> #{defaults_bucket_type => <<"privacy_defaults">>, names_bucket_type => <<"privacy_lists_names">>, bucket_type => <<"privacy_lists">>}; -default_config([modules, mod_mam_meta, pm]) -> +default_config([modules, mod_mam, pm]) -> #{archive_groupchats => false, same_mam_id_for_peers => false}; -default_config([modules, mod_mam_meta, muc]) -> +default_config([modules, mod_mam, muc]) -> #{host => {prefix, <<"conference.">>}}; -default_config([modules, mod_mam_meta, cache]) -> +default_config([modules, mod_mam, cache]) -> #{module => internal, strategy => fifo, time_to_live => 480, number_of_segments => 3}; -default_config([modules, mod_mam_meta, async_writer]) -> +default_config([modules, mod_mam, async_writer]) -> #{batch_size => 30, enabled => true, flush_interval => 2000, pool_size => 4 * erlang:system_info(schedulers_online)}; -default_config([modules, mod_mam_meta, riak]) -> +default_config([modules, mod_mam, riak]) -> #{bucket_type => <<"mam_yz">>, search_index => <<"mam">>}; default_config([modules, mod_muc_light, cache_affs]) -> #{module => internal, strategy => fifo, @@ -1292,7 +1292,7 @@ common_mam_config() -> full_text_search => true, default_result_limit => 50, max_result_limit => 50, - async_writer => default_config([modules, mod_mam_meta, async_writer])}. + async_writer => default_config([modules, mod_mam, async_writer])}. mod_event_pusher_http_handler() -> #{pool_name => http_pool, diff --git a/test/config_parser_SUITE.erl b/test/config_parser_SUITE.erl index dfe223249d0..07e732bbcf7 100644 --- a/test/config_parser_SUITE.erl +++ b/test/config_parser_SUITE.erl @@ -197,10 +197,10 @@ groups() -> mod_keystore, mod_keystore_keys, mod_last, - mod_mam_meta, - mod_mam_meta_riak, - mod_mam_meta_pm, - mod_mam_meta_muc, + mod_mam, + mod_mam_riak, + mod_mam_pm, + mod_mam_muc, mod_muc, mod_muc_default_room, mod_muc_default_room_affiliations, @@ -1970,19 +1970,19 @@ mod_last(_Config) -> ?errh(T(#{<<"backend">> => <<"frontend">>})), ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})). -mod_mam_meta(_Config) -> - check_module_defaults(mod_mam_meta), - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam_meta">> => Opts}} end, - P = [modules, mod_mam_meta], +mod_mam(_Config) -> + check_module_defaults(mod_mam), + T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => Opts}} end, + P = [modules, mod_mam], test_cache_config(P ++ [cache], fun(Opts) -> T(#{<<"cache">> => Opts}) end), - test_mod_mam_meta(P, T). + test_mod_mam(P, T). -mod_mam_meta_riak(_Config) -> +mod_mam_riak(_Config) -> T = fun(Opts) -> - #{<<"modules">> => #{<<"mod_mam_meta">> => Opts#{<<"backend">> => <<"riak">>}}} + #{<<"modules">> => #{<<"mod_mam">> => Opts#{<<"backend">> => <<"riak">>}}} end, - P = [modules, mod_mam_meta, riak], - ?cfgh(P, default_config([modules, mod_mam_meta, riak]), T(#{})), + P = [modules, mod_mam, riak], + ?cfgh(P, default_config([modules, mod_mam, riak]), T(#{})), ?cfgh(P ++ [bucket_type], <<"mam_bucket">>, T(#{<<"riak">> => #{<<"bucket_type">> => <<"mam_bucket">>}})), ?cfgh(P ++ [search_index], <<"mam_index">>, @@ -1990,10 +1990,10 @@ mod_mam_meta_riak(_Config) -> ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => <<>>}})), ?errh(T(#{<<"riak">> => #{<<"search_index">> => <<>>}})). -mod_mam_meta_pm(_Config) -> - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam_meta">> => #{<<"pm">> => Opts}}} end, - P = [modules, mod_mam_meta, pm], - test_mod_mam_meta(P, T), +mod_mam_pm(_Config) -> + T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => #{<<"pm">> => Opts}}} end, + P = [modules, mod_mam, pm], + test_mod_mam(P, T), ?cfgh(P, default_config(P), T(#{})), ?cfgh(P ++ [archive_groupchats], true, T(#{<<"archive_groupchats">> => true})), ?cfgh(P ++ [same_mam_id_for_peers], true, T(#{<<"same_mam_id_for_peers">> => true})), @@ -2001,10 +2001,10 @@ mod_mam_meta_pm(_Config) -> ?errh(T(#{<<"archive_groupchats">> => <<"not really">>})), ?errh(T(#{<<"same_mam_id_for_peers">> => <<"not really">>})). -mod_mam_meta_muc(_Config) -> - T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam_meta">> => #{<<"muc">> => Opts}}} end, - P = [modules, mod_mam_meta, muc], - test_mod_mam_meta(P, T), +mod_mam_muc(_Config) -> + T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => #{<<"muc">> => Opts}}} end, + P = [modules, mod_mam, muc], + test_mod_mam(P, T), ?cfgh(P, default_config(P), T(#{})), ?cfgh(P ++ [host], {prefix, <<"muc.">>}, T(#{<<"host">> => <<"muc.@HOST@">>})), ?cfgh(P ++ [host], {fqdn, <<"muc.test">>}, T(#{<<"host">> => <<"muc.test">>})), @@ -2014,7 +2014,7 @@ mod_mam_meta_muc(_Config) -> ?errh(T(#{<<"archive_groupchats">> => true})), % pm-only ?errh(T(#{<<"same_mam_id_for_peers">> => true})). % pm-only -test_mod_mam_meta(P, T) -> +test_mod_mam(P, T) -> test_async_writer(P, T), ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})), diff --git a/test/config_parser_SUITE_data/modules.toml b/test/config_parser_SUITE_data/modules.toml index 874c8e28564..f11a1a4d6a5 100644 --- a/test/config_parser_SUITE_data/modules.toml +++ b/test/config_parser_SUITE_data/modules.toml @@ -153,7 +153,7 @@ backend = "mnesia" iqdisc = {"type" = "queues", "workers" = 10} -[modules.mod_mam_meta] +[modules.mod_mam] backend = "rdbms" no_stanzaid_element = true is_archivable_message = "mod_mam_utils" diff --git a/test/mod_mam_meta_SUITE.erl b/test/mod_mam_SUITE.erl similarity index 74% rename from test/mod_mam_meta_SUITE.erl rename to test/mod_mam_SUITE.erl index 6b4f6765ab1..36136ac8772 100644 --- a/test/mod_mam_meta_SUITE.erl +++ b/test/mod_mam_SUITE.erl @@ -1,4 +1,4 @@ --module(mod_mam_meta_SUITE). +-module(mod_mam_SUITE). -compile([export_all, nowarn_export_all]). -include_lib("eunit/include/eunit.hrl"). @@ -27,48 +27,48 @@ end_per_testcase(_CaseName, Config) -> Config. overrides_general_options(_Config) -> Deps = deps(#{backend => rdbms, - pm => config([modules, mod_mam_meta, pm], #{backend => cassandra}), - muc => default_config([modules, mod_mam_meta, muc]) + pm => config([modules, mod_mam, pm], #{backend => cassandra}), + muc => default_config([modules, mod_mam, muc]) }), ?assert(lists:keymember(mod_mam_cassandra_arch, 1, Deps)), ?assert(lists:keymember(mod_mam_muc_rdbms_arch, 1, Deps)), ?assertNot(lists:keymember(mod_mam_rdbms_arch, 1, Deps)). sets_rdbms_as_default_backend(_Config) -> - Deps = deps(#{pm => default_config([modules, mod_mam_meta, pm])}), + Deps = deps(#{pm => default_config([modules, mod_mam, pm])}), ?assert(lists:keymember(mod_mam_rdbms_arch, 1, Deps)). handles_only_pm(_Config) -> - Deps = deps(#{pm => default_config([modules, mod_mam_meta, pm])}), + Deps = deps(#{pm => default_config([modules, mod_mam, pm])}), ?assert(lists:keymember(mod_mam_pm, 1, Deps)), ?assertNot(lists:keymember(mod_mam_muc, 1, Deps)). handles_only_muc(_Config) -> - Deps = deps(#{muc => default_config([modules, mod_mam_meta, muc])}), + Deps = deps(#{muc => default_config([modules, mod_mam, muc])}), ?assertNot(lists:keymember(mod_mam_pm, 1, Deps)), ?assert(lists:keymember(mod_mam_muc, 1, Deps)). disables_sync_writer_on_async_writer(_Config) -> - PM = default_config([modules, mod_mam_meta, pm]), + PM = default_config([modules, mod_mam, pm]), Deps = deps(#{pm => PM}), check_equal_opts(mod_mam_rdbms_arch, mod_config(mod_mam_rdbms_arch, #{no_writer => true}), Deps). disables_sync_muc_writer_on_async_writer(_Config) -> - MUC = default_config([modules, mod_mam_meta, muc]), + MUC = default_config([modules, mod_mam, muc]), Deps = deps(#{muc => MUC}), check_equal_opts(mod_mam_muc_rdbms_arch, mod_config(mod_mam_muc_rdbms_arch, #{no_writer => true}), Deps). produces_valid_configurations(_Config) -> - AsyncOpts = default_config([modules, mod_mam_meta, async_writer]), + AsyncOpts = default_config([modules, mod_mam, async_writer]), PMCoreOpts = #{archive_groupchats => true, async_writer => AsyncOpts#{enabled => false}}, - PM = config([modules, mod_mam_meta, pm], PMCoreOpts#{user_prefs_store => rdbms}), + PM = config([modules, mod_mam, pm], PMCoreOpts#{user_prefs_store => rdbms}), MUCCoreOpts = #{host => <<"host">>}, MUCArchOpts = #{db_message_format => mam_message_xml}, - MUC = config([modules, mod_mam_meta, muc], + MUC = config([modules, mod_mam, muc], maps:merge(MUCCoreOpts, MUCArchOpts#{user_prefs_store => mnesia})), Deps = deps(#{pm => PM, muc => MUC}), - Cache = default_config([modules, mod_mam_meta, cache]), + Cache = default_config([modules, mod_mam, cache]), check_equal_opts(mod_mam_pm, mod_config(mod_mam_pm, PMCoreOpts), Deps), check_equal_opts(mod_mam_muc, mod_config(mod_mam_muc, MUCCoreOpts), Deps), @@ -82,12 +82,12 @@ produces_valid_configurations(_Config) -> check_equal_opts(mod_mam_muc_rdbms_arch_async, AsyncOpts, Deps). handles_riak_config(_Config) -> - PM = config([modules, mod_mam_meta, pm], #{user_prefs_store => mnesia}), - MUC = default_config([modules, mod_mam_meta, muc]), + PM = config([modules, mod_mam, pm], #{user_prefs_store => mnesia}), + MUC = default_config([modules, mod_mam, muc]), Deps = deps(#{backend => riak, db_message_format => some_format, - pm => config([modules, mod_mam_meta, pm], PM), - muc => config([modules, mod_mam_meta, muc], MUC)}), + pm => config([modules, mod_mam, pm], PM), + muc => config([modules, mod_mam, muc], MUC)}), ?assert(lists:keymember(mod_mam_pm, 1, Deps)), ?assert(lists:keymember(mod_mam_muc, 1, Deps)), check_equal_opts(mod_mam_riak_timed_arch_yz, @@ -95,12 +95,12 @@ handles_riak_config(_Config) -> check_equal_opts(mod_mam_mnesia_prefs, #{pm => true}, Deps). handles_cassandra_config(_Config) -> - PM = config([modules, mod_mam_meta, pm], #{user_prefs_store => cassandra, + PM = config([modules, mod_mam, pm], #{user_prefs_store => cassandra, db_message_format => some_format}), - MUC = config([modules, mod_mam_meta, muc], #{user_prefs_store => mnesia}), + MUC = config([modules, mod_mam, muc], #{user_prefs_store => mnesia}), Deps = deps(#{backend => cassandra, - pm => config([modules, mod_mam_meta, pm], PM), - muc => config([modules, mod_mam_meta, muc], MUC)}), + pm => config([modules, mod_mam, pm], PM), + muc => config([modules, mod_mam, muc], MUC)}), check_equal_opts(mod_mam_mnesia_prefs, #{muc => true}, Deps), check_equal_opts(mod_mam_cassandra_prefs, #{pm => true}, Deps), @@ -109,10 +109,10 @@ handles_cassandra_config(_Config) -> example_muc_only_no_pref_good_performance(_Config) -> MUCOpts = #{host => {prefix, "muc."}}, - MUC = config([modules, mod_mam_meta, muc], MUCOpts), + MUC = config([modules, mod_mam, muc], MUCOpts), Deps = deps(#{muc => MUC}), - AsyncOpts = default_config([modules, mod_mam_meta, async_writer]), - Cache = default_config([modules, mod_mam_meta, cache]), + AsyncOpts = default_config([modules, mod_mam, async_writer]), + Cache = default_config([modules, mod_mam, cache]), check_equal_deps( [{mod_mam_rdbms_user, #{muc => true, pm => true}}, @@ -123,10 +123,10 @@ example_muc_only_no_pref_good_performance(_Config) -> ], Deps). example_pm_only_good_performance(_Config) -> - PM = default_config([modules, mod_mam_meta, pm]), + PM = default_config([modules, mod_mam, pm]), Deps = deps(#{pm => PM, user_prefs_store => mnesia}), - AsyncOpts = default_config([modules, mod_mam_meta, async_writer]), - Cache = default_config([modules, mod_mam_meta, cache]), + AsyncOpts = default_config([modules, mod_mam, async_writer]), + Cache = default_config([modules, mod_mam, cache]), check_equal_deps( [{mod_mam_rdbms_user, #{pm => true}}, @@ -147,4 +147,4 @@ check_equal_opts(Mod, Opts, Deps) -> ?assertEqual(Opts, ActualOpts). deps(Opts) -> - mod_mam_meta:deps(<<"host">>, mod_config(mod_mam_meta, Opts)). + mod_mam:deps(<<"host">>, mod_config(mod_mam, Opts)). From d596496cc4cb7c99c5a71a7b758eb925c2686fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Jun 2022 14:04:44 +0200 Subject: [PATCH 3/5] Move exported MAM types to mod_mam --- src/mam/ejabberd_gen_mam_archive.erl | 6 +- src/mam/ejabberd_gen_mam_prefs.erl | 14 ++-- src/mam/mam_decoder.erl | 6 +- src/mam/mam_encoder.erl | 2 +- src/mam/mam_iq.erl | 10 +-- src/mam/mam_lookup.erl | 8 +- src/mam/mam_send_message.erl | 4 +- src/mam/mod_mam.erl | 60 +++++++++++++- src/mam/mod_mam_cache_user.erl | 8 +- src/mam/mod_mam_cassandra_arch.erl | 2 +- src/mam/mod_mam_cassandra_prefs.erl | 18 ++-- src/mam/mod_mam_elasticsearch_arch.erl | 14 ++-- src/mam/mod_mam_mnesia_prefs.erl | 12 +-- src/mam/mod_mam_muc.erl | 26 +++--- src/mam/mod_mam_muc_cassandra_arch.erl | 2 +- src/mam/mod_mam_muc_elasticsearch_arch.erl | 14 ++-- src/mam/mod_mam_muc_rdbms_arch.erl | 14 ++-- src/mam/mod_mam_muc_rdbms_arch_async.erl | 2 +- src/mam/mod_mam_pm.erl | 83 ++++--------------- src/mam/mod_mam_rdbms_arch.erl | 16 ++-- src/mam/mod_mam_rdbms_arch_async.erl | 2 +- src/mam/mod_mam_rdbms_prefs.erl | 20 ++--- src/mam/mod_mam_rdbms_user.erl | 6 +- src/mam/mod_mam_utils.erl | 40 ++++----- src/metrics/mongoose_metrics_mam_hooks.erl | 10 +-- src/mod_commands.erl | 2 +- .../mongoose_client_api_rooms_messages.erl | 2 +- src/mongoose_deprecations.erl | 2 +- src/mongoose_hooks.erl | 62 +++++++------- 29 files changed, 234 insertions(+), 233 deletions(-) diff --git a/src/mam/ejabberd_gen_mam_archive.erl b/src/mam/ejabberd_gen_mam_archive.erl index f4753b61bb9..a02dbcc873a 100644 --- a/src/mam/ejabberd_gen_mam_archive.erl +++ b/src/mam/ejabberd_gen_mam_archive.erl @@ -3,15 +3,15 @@ -ignore_xref([behaviour_info/1]). -callback archive_size(Size :: integer(), Host :: jid:server(), - ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) -> integer(). -callback archive_message(Result :: any(), Host :: jid:server(), - Params :: mod_mam_pm:archive_message_params()) -> ok | {error, timeout}. + Params :: mod_mam:archive_message_params()) -> ok | {error, timeout}. -callback lookup_messages(Result :: any(), Host :: jid:server(), Params :: map()) -> Result when - Result :: {ok, mod_mam_pm:lookup_result()} | {error, 'policy-violation'}. + Result :: {ok, mod_mam:lookup_result()} | {error, 'policy-violation'}. -callback get_mam_pm_gdpr_data(mam_pm_gdpr_data(), mongooseim:host_type(), jid:jid()) -> mam_pm_gdpr_data(). diff --git a/src/mam/ejabberd_gen_mam_prefs.erl b/src/mam/ejabberd_gen_mam_prefs.erl index 91da0a69484..d0fafb2a5f0 100644 --- a/src/mam/ejabberd_gen_mam_prefs.erl +++ b/src/mam/ejabberd_gen_mam_prefs.erl @@ -2,17 +2,17 @@ -ignore_xref([behaviour_info/1]). --callback get_behaviour(Default :: mod_mam_pm:archive_behaviour(), - Host :: jid:server(), ArcID :: mod_mam_pm:archive_id(), +-callback get_behaviour(Default :: mod_mam:archive_behaviour(), + Host :: jid:server(), ArcID :: mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). -callback set_prefs(Result :: any(), Host :: jid:server(), - ArcID :: mod_mam_pm:archive_id(), ArcJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + ArcID :: mod_mam:archive_id(), ArcJID :: jid:jid(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). --callback get_prefs(mod_mam_pm:preference(), _Host :: jid:server(), - ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) - -> mod_mam_pm:preference(). +-callback get_prefs(mod_mam:preference(), _Host :: jid:server(), + ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) + -> mod_mam:preference(). diff --git a/src/mam/mam_decoder.erl b/src/mam/mam_decoder.erl index 3cd35ce0c7c..147a46ec935 100644 --- a/src/mam/mam_decoder.erl +++ b/src/mam/mam_decoder.erl @@ -11,14 +11,14 @@ -type db_muc_gdpr_row() :: {ext_mess_id(), ExtData :: binary()}. -type decoded_muc_gdpr_row() :: {ext_mess_id(), exml:element()}. --spec decode_row(db_row(), env_vars()) -> mod_mam_pm:message_row(). +-spec decode_row(db_row(), env_vars()) -> mod_mam:message_row(). decode_row({ExtMessID, ExtSrcJID, ExtData}, Env) -> MessID = mongoose_rdbms:result_to_integer(ExtMessID), SrcJID = decode_jid(ExtSrcJID, Env), Packet = decode_packet(ExtData, Env), #{id => MessID, jid => SrcJID, packet => Packet}. --spec decode_muc_row(db_muc_row(), env_vars()) -> mod_mam_pm:message_row(). +-spec decode_muc_row(db_muc_row(), env_vars()) -> mod_mam:message_row(). decode_muc_row({ExtMessID, Nick, ExtData}, Env = #{archive_jid := RoomJID}) -> MessID = mongoose_rdbms:result_to_integer(ExtMessID), SrcJID = jid:replace_resource(RoomJID, Nick), @@ -31,7 +31,7 @@ decode_muc_gdpr_row({ExtMessID, ExtData}, Env) -> {ExtMessID, Packet}. -spec decode_retraction_info(env_vars(), - [{binary(), mod_mam_pm:message_id(), binary()}], + [{binary(), mod_mam:message_id(), binary()}], mod_mam_utils:retraction_id()) -> skip | mod_mam_utils:retraction_info(). decode_retraction_info(_Env, [], _) -> skip; diff --git a/src/mam/mam_encoder.erl b/src/mam/mam_encoder.erl index 1a408c134a8..76904a0b0f6 100644 --- a/src/mam/mam_encoder.erl +++ b/src/mam/mam_encoder.erl @@ -22,7 +22,7 @@ extend_lookup_params(#{start_ts := Start, end_ts := End, with_jid := WithJID, remote_bare_jid => maybe_encode_bare_jid(WithJID, Env), remote_resource => jid_to_non_empty_resource(WithJID)}. --spec encode_message(mod_mam_pm:archive_message_params(), env_vars(), list(db_mapping())) -> +-spec encode_message(mod_mam:archive_message_params(), env_vars(), list(db_mapping())) -> [encoded_field_value()]. encode_message(Params, Env, Mappings) -> [encode_value_using_mapping(Params, Env, Mapping) || Mapping <- Mappings]. diff --git a/src/mam/mam_iq.erl b/src/mam/mam_iq.erl index 197c3cb2d6e..41c698bf079 100644 --- a/src/mam/mam_iq.erl +++ b/src/mam/mam_iq.erl @@ -37,7 +37,7 @@ | 'mam_get_message_form'. -type lookup_params() :: #{ - archive_id => mod_mam_pm:archive_id(), + archive_id => mod_mam:archive_id(), owner_jid => jid:jid(), caller_jid => jid:jid(), rsm => jlib:rsm_in() | undefined, @@ -47,16 +47,16 @@ page_size => non_neg_integer(), ordering_direction => backward | forward, %% unix_timestamp() is in microseconds - now => mod_mam_pm:unix_timestamp(), + now => mod_mam:unix_timestamp(), %% Filtering by date - start_ts => mod_mam_pm:unix_timestamp() | undefined, - end_ts => mod_mam_pm:unix_timestamp() | undefined, + start_ts => mod_mam:unix_timestamp() | undefined, + end_ts => mod_mam:unix_timestamp() | undefined, %% Filtering by contact with_jid => jid:jid() | undefined, %% Filtering by body text search_text => binary() | undefined, %% Filtering Result Set based on message ids - borders => mod_mam_pm:borders() | undefined, + borders => mod_mam:borders() | undefined, %% Affects 'policy-violation' for a case when: %% - user does not use forms to query archive %% - user does not provide "set" element diff --git a/src/mam/mam_lookup.erl b/src/mam/mam_lookup.erl index 7c80564f1ea..c55d8b33166 100644 --- a/src/mam/mam_lookup.erl +++ b/src/mam/mam_lookup.erl @@ -9,7 +9,7 @@ -type filter() :: mam_filter:filter(). -type env_vars() :: mod_mam_rdbms_arch:env_vars(). -type params() :: map(). --type message_id() :: mod_mam_pm:message_id(). +-type message_id() :: mod_mam:message_id(). -type maybe_rsm() :: #rsm_in{} | undefined. -type opt_count_type() :: last_page | by_offset | none. @@ -18,7 +18,7 @@ %% - lookup_fn %% - decode_row_fn -spec lookup(env_vars(), filter(), params()) -> - {ok, mod_mam_pm:lookup_result()} | {error, item_not_found}. + {ok, mod_mam:lookup_result()} | {error, item_not_found}. lookup(Env = #{}, Filter, Params = #{rsm := RSM}) when is_list(Filter) -> OptParams = Params#{opt_count_type => opt_count_type(RSM)}, choose_lookup_messages_strategy(Env, Filter, OptParams). @@ -155,12 +155,12 @@ rsm_to_regular_lookup_vars(RSM, Filter, Offset, PageSize) -> decode_rows(MessageRows, Env) -> [decode_row(Row, Env) || Row <- MessageRows]. --spec decoded_row_to_message_id(mod_mam_pm:message_row()) -> mod_mam_pm:message_id(). +-spec decoded_row_to_message_id(mod_mam:message_row()) -> mod_mam:message_id(). decoded_row_to_message_id(#{id := MessId}) -> MessId. -spec extract_messages(Env :: env_vars(), Filter :: filter(), Offset :: non_neg_integer(), Max :: pos_integer(), - Order :: asc | desc) -> [mod_mam_pm:message_row()]. + Order :: asc | desc) -> [mod_mam:message_row()]. extract_messages(_Env, _Filter, _Offset, 0 = _Max, _Order) -> []; extract_messages(Env, Filter, Offset, Max, Order) -> diff --git a/src/mam/mam_send_message.erl b/src/mam/mam_send_message.erl index 0fd3aaf20cb..6db54ee32a1 100644 --- a/src/mam/mam_send_message.erl +++ b/src/mam/mam_send_message.erl @@ -6,14 +6,14 @@ -ignore_xref([behaviour_info/1]). -callback send_message( - Row :: mod_mam_pm:message_row(), + Row :: mod_mam:message_row(), ArcJID :: jid:jid(), From :: jid:jid(), Packet :: exml:element()) -> Acc :: mongoose_acc:t(). -spec call_send_message( SendModule :: module(), - Row :: mod_mam_pm:message_row(), + Row :: mod_mam:message_row(), ArcJID :: jid:jid(), From :: jid:jid(), Packet :: exml:element()) -> Acc :: mongoose_acc:t(). diff --git a/src/mam/mod_mam.erl b/src/mam/mod_mam.erl index cc3a5863df1..41cdddfe91f 100644 --- a/src/mam/mod_mam.erl +++ b/src/mam/mod_mam.erl @@ -18,15 +18,71 @@ -behaviour(gen_mod). -behaviour(mongoose_module_metrics). +-include("mod_mam.hrl"). +-include("mongoose_config_spec.hrl"). + -type module_opts() :: gen_mod:module_opts(). -type module_map() :: gen_mod_deps:module_map(). +%% ---------------------------------------------------------------------- +%% Datetime types +%% Microseconds from 01.01.1970 +-type unix_timestamp() :: non_neg_integer(). + +%% ---------------------------------------------------------------------- +%% Other types +-type archive_behaviour() :: roster | always | never. +-type message_id() :: non_neg_integer(). + +-type archive_id() :: non_neg_integer(). + +-type borders() :: #mam_borders{}. + +-type message_row() :: #{id := message_id(), jid := jid:jid(), packet := exml:element()}. +-type lookup_result() :: {TotalCount :: non_neg_integer() | undefined, + Offset :: non_neg_integer() | undefined, + MessageRows :: [message_row()]}. + +%% Internal types +-type iterator_fun() :: fun(() -> {'ok', {_, _}}). +-type rewriter_fun() :: fun((JID :: jid:literal_jid()) + -> jid:literal_jid()). +-type restore_option() :: {rewrite_jids, rewriter_fun() | [{binary(), binary()}]} + | new_message_ids. + +-type preference() :: {DefaultMode :: archive_behaviour(), + AlwaysJIDs :: [jid:literal_jid()], + NeverJIDs :: [jid:literal_jid()]}. + +-type archive_message_params() :: #{message_id := message_id(), + archive_id := archive_id(), + local_jid := jid:jid(), + remote_jid := jid:jid(), + source_jid := jid:jid(), + origin_id := binary() | none, + direction := atom(), + packet := exml:element(), + %% Only in mod_mam_muc_rdbms_arch:retract_message/2 + sender_id => archive_id()}. + +-export_type([rewriter_fun/0, + borders/0, + preference/0, + archive_behaviour/0, + iterator_fun/0, + unix_timestamp/0, + archive_id/0, + lookup_result/0, + message_row/0, + message_id/0, + restore_option/0, + archive_message_params/0 + ]). + -export([start/2, stop/1, config_spec/0, supported_features/0, deps/2, config_metrics/1]). -export([remove_unused_backend_opts/1]). --include("mongoose_config_spec.hrl"). - %%-------------------------------------------------------------------- %% API %%-------------------------------------------------------------------- diff --git a/src/mam/mod_mam_cache_user.erl b/src/mam/mod_mam_cache_user.erl index 5ffbe763d5d..c0b7b28ef93 100644 --- a/src/mam/mod_mam_cache_user.erl +++ b/src/mam/mod_mam_cache_user.erl @@ -75,7 +75,7 @@ muc_hooks(HostType) -> %% API %%==================================================================== -spec cached_archive_id(undefined, mongooseim:host_type(), jid:jid()) -> - mod_mam_pm:archive_id(). + mod_mam:archive_id(). cached_archive_id(undefined, HostType, ArcJid) -> case mongoose_user_cache:get_entry(HostType, ?MODULE, ArcJid) of #{id := ArchId} -> ArchId; @@ -84,8 +84,8 @@ cached_archive_id(undefined, HostType, ArcJid) -> undefined end. --spec store_archive_id(mod_mam_pm:archive_id(), mongooseim:host_type(), jid:jid()) - -> mod_mam_pm:archive_id(). +-spec store_archive_id(mod_mam:archive_id(), mongooseim:host_type(), jid:jid()) + -> mod_mam:archive_id(). store_archive_id(ArchId, HostType, ArcJid) -> case erase(mam_not_cached_flag) of undefined -> @@ -96,7 +96,7 @@ store_archive_id(ArchId, HostType, ArcJid) -> end. -spec remove_archive(Acc :: map(), HostType :: mongooseim:host_type(), - ArchId :: mod_mam_pm:archive_id(), ArcJid :: jid:jid()) -> map(). + ArchId :: mod_mam:archive_id(), ArcJid :: jid:jid()) -> map(). remove_archive(Acc, HostType, _UserID, ArcJid) -> mongoose_user_cache:delete_user(HostType, ?MODULE, ArcJid), Acc. diff --git a/src/mam/mod_mam_cassandra_arch.erl b/src/mam/mod_mam_cassandra_arch.erl index 1f9f6f7c2fc..f228a820b6c 100644 --- a/src/mam/mod_mam_cassandra_arch.erl +++ b/src/mam/mod_mam_cassandra_arch.erl @@ -210,7 +210,7 @@ remove_archive(HostType, UserJID) -> %% SELECT MESSAGES -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam_pm:lookup_result()}. + {ok, mod_mam:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, _HostType, #{search_text := <<_/binary>>}) -> diff --git a/src/mam/mod_mam_cassandra_prefs.erl b/src/mam/mod_mam_cassandra_prefs.erl index 4bb64c5780b..a3ec8e119a9 100644 --- a/src/mam/mod_mam_cassandra_prefs.erl +++ b/src/mam/mod_mam_cassandra_prefs.erl @@ -82,8 +82,8 @@ prepared_queries() -> %% ---------------------------------------------------------------------- %% Internal functions and callbacks --spec get_behaviour(Default :: mod_mam_pm:archive_behaviour(), - HostType :: host_type(), ArchiveID :: mod_mam_pm:archive_id(), +-spec get_behaviour(Default :: mod_mam:archive_behaviour(), + HostType :: host_type(), ArchiveID :: mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, HostType, _UserID, LocJID, RemJID) -> BUserJID = mod_mam_utils:bare_jid(LocJID), @@ -105,8 +105,8 @@ get_behaviour(DefaultBehaviour, HostType, _UserID, LocJID, RemJID) -> -spec set_prefs(Result :: any(), HostType :: host_type(), - ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, HostType, _UserID, UserJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -144,9 +144,9 @@ encode_row(BUserJID, BRemoteJID, Behaviour, Timestamp) -> behaviour => Behaviour, '[timestamp]' => Timestamp}. --spec get_prefs(mod_mam_pm:preference(), _HostType :: host_type(), - ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) - -> mod_mam_pm:preference(). +-spec get_prefs(mod_mam:preference(), _HostType :: host_type(), + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) + -> mod_mam:preference(). get_prefs({GlobalDefaultMode, _, _}, HostType, _UserID, UserJID) -> BUserJID = mod_mam_utils:bare_jid(UserJID), Params = #{user_jid => BUserJID}, @@ -155,7 +155,7 @@ get_prefs({GlobalDefaultMode, _, _}, HostType, _UserID, UserJID) -> decode_prefs_rows(Rows, GlobalDefaultMode, [], []). --spec remove_archive(mongoose_acc:t(), host_type(), mod_mam_pm:archive_id(), jid:jid()) -> +-spec remove_archive(mongoose_acc:t(), host_type(), mod_mam:archive_id(), jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, _UserID, UserJID) -> remove_archive(HostType, UserJID), @@ -197,7 +197,7 @@ decode_behaviour(<<"N">>) -> never. -spec decode_prefs_rows([[term()]], DefaultMode, AlwaysJIDs, NeverJIDs) -> {DefaultMode, AlwaysJIDs, NeverJIDs} when - DefaultMode :: mod_mam_pm:archive_behaviour(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]. decode_prefs_rows([], DefaultMode, AlwaysJIDs, NeverJIDs) -> diff --git a/src/mam/mod_mam_elasticsearch_arch.erl b/src/mam/mod_mam_elasticsearch_arch.erl index b21192f4f04..85a83b3a80f 100644 --- a/src/mam/mod_mam_elasticsearch_arch.erl +++ b/src/mam/mod_mam_elasticsearch_arch.erl @@ -140,7 +140,7 @@ archive_size(_Size, _Host, _ArchiveId, OwnerJid) -> -spec remove_archive(Acc :: mongoose_acc:t(), Host :: jid:server(), - ArchiveId :: mod_mam_pm:archive_id(), + ArchiveId :: mod_mam:archive_id(), OwnerJid :: jid:jid()) -> Acc when Acc :: map(). remove_archive(Acc, Host, _ArchiveId, OwnerJid) -> remove_archive(Host, OwnerJid), @@ -169,11 +169,11 @@ hooks(Host) -> {mam_remove_archive, Host, ?MODULE, remove_archive, 50}, {get_mam_pm_gdpr_data, Host, ?MODULE, get_mam_pm_gdpr_data, 50}]. --spec make_document_id(binary(), mod_mam_pm:message_id()) -> binary(). +-spec make_document_id(binary(), mod_mam:message_id()) -> binary(). make_document_id(Owner, MessageId) -> <>. --spec make_document(mod_mam_pm:message_id(), binary(), binary(), binary(), exml:element()) -> +-spec make_document(mod_mam:message_id(), binary(), binary(), binary(), exml:element()) -> map(). make_document(MessageId, Owner, Remote, SourceBinJid, Packet) -> #{mam_id => MessageId, @@ -225,13 +225,13 @@ range_filter(#{end_ts := End, start_ts := Start, borders := Borders, rsm := RSM} range_filter(_) -> []. --spec maybe_add_end_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). +-spec maybe_add_end_filter(undefined | mod_mam:message_id(), map()) -> map(). maybe_add_end_filter(undefined, RangeMap) -> RangeMap; maybe_add_end_filter(Value, RangeMap) -> RangeMap#{le => Value}. --spec maybe_add_start_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). +-spec maybe_add_start_filter(undefined | mod_mam:message_id(), map()) -> map(). maybe_add_start_filter(undefined, RangeMap) -> RangeMap; maybe_add_start_filter(Value, RangeMap) -> @@ -258,7 +258,7 @@ maybe_add_from_constraint(Query, #{rsm := #rsm_in{index = Offset}}) when is_inte maybe_add_from_constraint(Query, _) -> Query. --spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam_pm:lookup_result(). +-spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam:lookup_result(). search_result_to_mam_lookup_result(Result, Params) -> #{<<"hits">> := #{<<"hits">> := Hits, @@ -277,7 +277,7 @@ search_result_to_mam_lookup_result(Result, Params) -> {CorrectedTotalCount, Offset, Messages} end. --spec hit_to_mam_message(map()) -> mod_mam_pm:message_row(). +-spec hit_to_mam_message(map()) -> mod_mam:message_row(). hit_to_mam_message(#{<<"_source">> := JSON}) -> MessageId = maps:get(<<"mam_id">>, JSON), Packet = maps:get(<<"message">>, JSON), diff --git a/src/mam/mod_mam_mnesia_prefs.erl b/src/mam/mod_mam_mnesia_prefs.erl index b1d2fce84c3..76161df3ee0 100644 --- a/src/mam/mod_mam_mnesia_prefs.erl +++ b/src/mam/mod_mam_mnesia_prefs.erl @@ -80,7 +80,7 @@ hooks(_HostType, _Opt, _Opts) -> %% Internal functions and callbacks -spec get_behaviour(Default :: behaviour(), Host :: jid:server(), - ArcID :: mod_mam_pm:archive_id(), LocJID :: jid:jid(), + ArcID :: mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, _Host, _ArcID, @@ -122,8 +122,8 @@ get_behaviour(#mam_prefs{default_mode = roster, -spec set_prefs(Result :: any(), Host :: jid:server(), - ArcID :: mod_mam_pm:archive_id(), ArcJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + ArcID :: mod_mam:archive_id(), ArcJID :: jid:jid(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, _Host, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -149,9 +149,9 @@ set_prefs1(_ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> ok. --spec get_prefs(mod_mam_pm:preference(), _Host :: jid:server(), - _ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid() - ) -> mod_mam_pm:preference(). +-spec get_prefs(mod_mam:preference(), _Host :: jid:server(), + _ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid() + ) -> mod_mam:preference(). get_prefs({GlobalDefaultMode, _, _}, _Host, _ArcID, ArcJID) -> SU = su_key(ArcJID), case mnesia:dirty_read(mam_prefs, SU) of diff --git a/src/mam/mod_mam_muc.erl b/src/mam/mod_mam_muc.erl index 1e85ec60830..cf1f1031f08 100644 --- a/src/mam/mod_mam_muc.erl +++ b/src/mam/mod_mam_muc.erl @@ -105,7 +105,7 @@ -type row_batch() :: {TotalCount :: non_neg_integer(), Offset :: non_neg_integer(), MessageRows :: [row()]}. --type row() :: mod_mam_pm:message_row(). +-type row() :: mod_mam:message_row(). -type host_type() :: mongooseim:host_type(). -type muc_action() :: atom(). @@ -398,7 +398,7 @@ handle_set_message_form(HostType, #jid{} = From, #jid{} = ArcJID, IQ) -> -spec do_handle_set_message_form(HostType :: mongooseim:host_type(), From :: jid:jid(), - ArcId :: mod_mam_pm:archive_id(), + ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid(), IQ :: jlib:iq(), Params :: mam_iq:lookup_params()) -> @@ -408,7 +408,7 @@ do_handle_set_message_form(HostType, From, ArcID, ArcJID, IQ, Params0) -> Result = lookup_messages(HostType, Params), handle_lookup_result(Result, HostType, From, IQ, Params). --spec handle_lookup_result({ok, mod_mam_pm:lookup_result()} | {error, term()}, +-spec handle_lookup_result({ok, mod_mam:lookup_result()} | {error, term()}, host_type(), jid:jid(), jlib:iq(), map()) -> jlib:iq() | ignore | {error, term(), jlib:iq()}. handle_lookup_result(Result, HostType, From, IQ, #{owner_jid := ArcJID} = Params) -> @@ -469,18 +469,18 @@ handle_get_message_form(HostType, archive_id_int(HostType, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_archive_id(HostType, ArcJID). --spec archive_size(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), +-spec archive_size(HostType :: host_type(), ArcID :: mod_mam:archive_id(), ArcJID ::jid:jid()) -> non_neg_integer(). archive_size(HostType, ArcID, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_archive_size(HostType, ArcID, ArcJID). --spec get_behaviour(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), +-spec get_behaviour(HostType :: host_type(), ArcID :: mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(HostType, ArcID, LocJID = #jid{}, RemJID = #jid{}) -> mongoose_hooks:mam_muc_get_behaviour(HostType, ArcID, LocJID, RemJID). --spec set_prefs(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), - ArcJID :: jid:jid(), DefaultMode :: mod_mam_pm:archive_behaviour(), +-spec set_prefs(HostType :: host_type(), ArcID :: mod_mam:archive_id(), + ArcJID :: jid:jid(), DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -488,13 +488,13 @@ set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> AlwaysJIDs, NeverJIDs). %% @doc Load settings from the database. --spec get_prefs(HostType :: host_type(), ArcID :: mod_mam_pm:archive_id(), - ArcJID :: jid:jid(), GlobalDefaultMode :: mod_mam_pm:archive_behaviour()) - -> mod_mam_pm:preference() | {error, Reason :: term()}. +-spec get_prefs(HostType :: host_type(), ArcID :: mod_mam:archive_id(), + ArcJID :: jid:jid(), GlobalDefaultMode :: mod_mam:archive_behaviour()) + -> mod_mam:preference() | {error, Reason :: term()}. get_prefs(HostType, ArcID, ArcJID, GlobalDefaultMode) -> mongoose_hooks:mam_muc_get_prefs(HostType, GlobalDefaultMode, ArcID, ArcJID). --spec remove_archive(host_type(), mod_mam_pm:archive_id() | undefined, +-spec remove_archive(host_type(), mod_mam:archive_id() | undefined, jid:jid()) -> ok. remove_archive(HostType, ArcID, ArcJID = #jid{}) -> mongoose_hooks:mam_muc_remove_archive(HostType, ArcID, ArcJID), @@ -502,7 +502,7 @@ remove_archive(HostType, ArcID, ArcJID = #jid{}) -> %% See description in mod_mam_pm. -spec lookup_messages(HostType :: host_type(), Params :: map()) -> - {ok, mod_mam_pm:lookup_result()} + {ok, mod_mam:lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. lookup_messages(HostType, Params) -> @@ -530,7 +530,7 @@ archive_message_for_ct(Params = #{local_jid := RoomJid}) -> HostType = mod_muc_light_utils:room_jid_to_host_type(RoomJid), archive_message(HostType, Params). --spec archive_message(host_type(), mod_mam_pm:archive_message_params()) -> ok | {error, timeout}. +-spec archive_message(host_type(), mod_mam:archive_message_params()) -> ok | {error, timeout}. archive_message(HostType, Params) -> mongoose_hooks:mam_muc_archive_message(HostType, Params). diff --git a/src/mam/mod_mam_muc_cassandra_arch.erl b/src/mam/mod_mam_muc_cassandra_arch.erl index 2abcc2991af..4d60a2542d2 100644 --- a/src/mam/mod_mam_muc_cassandra_arch.erl +++ b/src/mam/mod_mam_muc_cassandra_arch.erl @@ -206,7 +206,7 @@ remove_archive(Acc, HostType, _RoomID, RoomJID) -> %% SELECT MESSAGES -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam_pm:lookup_result()}. + {ok, mod_mam:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, _HostType, #{search_text := <<_/binary>>}) -> diff --git a/src/mam/mod_mam_muc_elasticsearch_arch.erl b/src/mam/mod_mam_muc_elasticsearch_arch.erl index 32feaa042d9..af41199f603 100644 --- a/src/mam/mod_mam_muc_elasticsearch_arch.erl +++ b/src/mam/mod_mam_muc_elasticsearch_arch.erl @@ -144,7 +144,7 @@ archive_size(_Size, _Host, _ArchiveId, RoomJid) -> -spec remove_archive(Acc :: mongoose_acc:t(), Host :: jid:server(), - ArchiveId :: mod_mam_pm:archive_id(), + ArchiveId :: mod_mam:archive_id(), RoomJid :: jid:jid()) -> Acc when Acc :: map(). remove_archive(Acc, Host, _ArchiveId, RoomJid) -> SearchQuery = build_search_query(#{owner_jid => RoomJid}), @@ -170,11 +170,11 @@ hooks(Host) -> {mam_muc_remove_archive, Host, ?MODULE, remove_archive, 50}, {get_mam_muc_gdpr_data, Host, ?MODULE, get_mam_muc_gdpr_data, 50}]. --spec make_document_id(binary(), mod_mam_pm:message_id()) -> binary(). +-spec make_document_id(binary(), mod_mam:message_id()) -> binary(). make_document_id(Room, MessageId) -> <>. --spec make_document(mod_mam_pm:message_id(), binary(), binary(), exml:element(), +-spec make_document(mod_mam:message_id(), binary(), binary(), exml:element(), binary()) -> map(). make_document(MessageId, Room, SourceBinJid, Packet, FromJID) -> #{mam_id => MessageId, @@ -227,13 +227,13 @@ range_filter(#{end_ts := End, start_ts := Start, borders := Borders, rsm := RSM} range_filter(_) -> []. --spec maybe_add_end_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). +-spec maybe_add_end_filter(undefined | mod_mam:message_id(), map()) -> map(). maybe_add_end_filter(undefined, RangeMap) -> RangeMap; maybe_add_end_filter(Value, RangeMap) -> RangeMap#{le => Value}. --spec maybe_add_start_filter(undefined | mod_mam_pm:message_id(), map()) -> map(). +-spec maybe_add_start_filter(undefined | mod_mam:message_id(), map()) -> map(). maybe_add_start_filter(undefined, RangeMap) -> RangeMap; maybe_add_start_filter(Value, RangeMap) -> @@ -260,7 +260,7 @@ maybe_add_from_constraint(Query, #{rsm := #rsm_in{index = Offset}}) when is_inte maybe_add_from_constraint(Query, _) -> Query. --spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam_pm:lookup_result(). +-spec search_result_to_mam_lookup_result(map(), map()) -> mod_mam:lookup_result(). search_result_to_mam_lookup_result(Result, Params) -> #{<<"hits">> := #{<<"hits">> := Hits, @@ -279,7 +279,7 @@ search_result_to_mam_lookup_result(Result, Params) -> {CorrectedTotalCount, Offset, Messages} end. --spec hit_to_mam_message(map()) -> mod_mam_pm:message_row(). +-spec hit_to_mam_message(map()) -> mod_mam:message_row(). hit_to_mam_message(#{<<"_source">> := JSON}) -> MessageId = maps:get(<<"mam_id">>, JSON), Packet = maps:get(<<"message">>, JSON), diff --git a/src/mam/mod_mam_muc_rdbms_arch.erl b/src/mam/mod_mam_muc_rdbms_arch.erl index 646b4bce960..e08248b9294 100644 --- a/src/mam/mod_mam_muc_rdbms_arch.erl +++ b/src/mam/mod_mam_muc_rdbms_arch.erl @@ -212,7 +212,7 @@ get_retract_id(Packet, #{has_message_retraction := Enabled}) -> %% Internal functions and callbacks -spec archive_size(Size :: integer(), HostType :: mongooseim:host_type(), - ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) -> integer(). + ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) -> integer(). archive_size(Size, HostType, ArcID, ArcJID) when is_integer(Size) -> Filter = [{equal, room_id, ArcID}], Env = env_vars(HostType, ArcJID), @@ -225,7 +225,7 @@ extend_params_with_sender_id(HostType, Params = #{remote_jid := SenderJID}) -> Params#{sender_id => SenderID}. -spec archive_message(_Result, HostType :: mongooseim:host_type(), - mod_mam_pm:archive_message_params()) -> ok. + mod_mam:archive_message_params()) -> ok. archive_message(_Result, HostType, Params0 = #{local_jid := ArcJID}) -> try Params = extend_params_with_sender_id(HostType, Params0), @@ -246,12 +246,12 @@ do_archive_message(HostType, Params, Env) -> %% Retraction logic %% Called after inserting a new message --spec retract_message(mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. +-spec retract_message(mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. retract_message(HostType, #{local_jid := ArcJID} = Params) -> Env = env_vars(HostType, ArcJID), retract_message(HostType, Params, Env). --spec retract_message(mongooseim:host_type(), mod_mam_pm:archive_message_params(), env_vars()) -> ok. +-spec retract_message(mongooseim:host_type(), mod_mam:archive_message_params(), env_vars()) -> ok. retract_message(HostType, #{archive_id := ArcID, sender_id := SenderID, packet := Packet} = Params, Env) -> case get_retract_id(Packet, Env) of @@ -291,7 +291,7 @@ execute_make_tombstone(HostType, TombstoneData, ArcID, MessID) -> [TombstoneData, ArcID, MessID]). %% Insert logic --spec prepare_message(mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> list(). +-spec prepare_message(mongooseim:host_type(), mod_mam:archive_message_params()) -> list(). prepare_message(HostType, Params = #{local_jid := ArcJID}) -> Env = env_vars(HostType, ArcJID), mam_encoder:encode_message(Params, Env, db_mappings()). @@ -306,7 +306,7 @@ prepare_insert(Name, NumRows) -> %% Removal logic -spec remove_archive(Acc :: mongoose_acc:t(), HostType :: mongooseim:host_type(), - ArcID :: mod_mam_pm:archive_id(), + ArcID :: mod_mam:archive_id(), ArcJID :: jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, ArcID, _ArcJID) -> mongoose_rdbms:execute_successfully(HostType, mam_muc_archive_remove, [ArcID]), @@ -345,7 +345,7 @@ extract_gdpr_messages(HostType, SenderID) -> %% Lookup logic -spec lookup_messages(Result :: any(), HostType :: mongooseim:host_type(), Params :: map()) -> - {ok, mod_mam_pm:lookup_result()}. + {ok, mod_mam:lookup_result()}. lookup_messages({error, _Reason} = Result, _HostType, _Params) -> Result; lookup_messages(_Result, HostType, Params = #{owner_jid := ArcJID}) -> diff --git a/src/mam/mod_mam_muc_rdbms_arch_async.erl b/src/mam/mod_mam_muc_rdbms_arch_async.erl index 5d8a6d92e4d..6199a9e8d4c 100644 --- a/src/mam/mod_mam_muc_rdbms_arch_async.erl +++ b/src/mam/mod_mam_muc_rdbms_arch_async.erl @@ -12,7 +12,7 @@ -export([archive_muc_message/3, mam_muc_archive_sync/2, flush/2]). -ignore_xref([archive_muc_message/3, mam_muc_archive_sync/2, flush/2]). --spec archive_muc_message(_Result, mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. +-spec archive_muc_message(_Result, mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. archive_muc_message(_Result, HostType, Params0 = #{archive_id := RoomID}) -> Params = mod_mam_muc_rdbms_arch:extend_params_with_sender_id(HostType, Params0), mongoose_async_pools:put_task(HostType, muc_mam, RoomID, Params). diff --git a/src/mam/mod_mam_pm.erl b/src/mam/mod_mam_pm.erl index 0c835e100b2..40f08bb9641 100644 --- a/src/mam/mod_mam_pm.erl +++ b/src/mam/mod_mam_pm.erl @@ -68,6 +68,8 @@ get_personal_data/3, remove_user/3, sm_filter_offline_message/4, user_send_packet/4]). +-type host_type() :: mongooseim:host_type(). + %% ---------------------------------------------------------------------- %% Imports @@ -104,63 +106,6 @@ -include("mongoose.hrl"). -include("jlib.hrl"). -include("amp.hrl"). --include("mod_mam.hrl"). - -%% ---------------------------------------------------------------------- -%% Datetime types -%% Microseconds from 01.01.1970 --type unix_timestamp() :: non_neg_integer(). --type host_type() :: mongooseim:host_type(). - -%% ---------------------------------------------------------------------- -%% Other types --type archive_behaviour() :: roster | always | never. --type message_id() :: non_neg_integer(). - --type archive_id() :: non_neg_integer(). - --type borders() :: #mam_borders{}. - --type message_row() :: #{id := message_id(), jid := jid:jid(), packet := exml:element()}. --type lookup_result() :: {TotalCount :: non_neg_integer() | undefined, - Offset :: non_neg_integer() | undefined, - MessageRows :: [message_row()]}. - -%% Internal types --type iterator_fun() :: fun(() -> {'ok', {_, _}}). --type rewriter_fun() :: fun((JID :: jid:literal_jid()) - -> jid:literal_jid()). --type restore_option() :: {rewrite_jids, rewriter_fun() | [{binary(), binary()}]} - | new_message_ids. - --type preference() :: {DefaultMode :: archive_behaviour(), - AlwaysJIDs :: [jid:literal_jid()], - NeverJIDs :: [jid:literal_jid()]}. - --type archive_message_params() :: #{message_id := message_id(), - archive_id := archive_id(), - local_jid := jid:jid(), - remote_jid := jid:jid(), - source_jid := jid:jid(), - origin_id := binary() | none, - direction := atom(), - packet := exml:element(), - %% Only in mod_mam_muc_rdbms_arch:retract_message/2 - sender_id => archive_id()}. - --export_type([rewriter_fun/0, - borders/0, - preference/0, - archive_behaviour/0, - iterator_fun/0, - unix_timestamp/0, - archive_id/0, - lookup_result/0, - message_row/0, - message_id/0, - restore_option/0, - archive_message_params/0 - ]). %% ---------------------------------------------------------------------- %% API @@ -443,7 +388,7 @@ handle_set_message_form(#jid{} = From, #jid{} = ArcJID, #iq{} = IQ, Acc) -> -spec do_handle_set_message_form(Params :: mam_iq:lookup_params(), From :: jid:jid(), - ArcId :: archive_id(), + ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid(), IQ :: jlib:iq(), HostType :: mongooseim:host_type()) -> @@ -587,16 +532,16 @@ is_interesting(HostType, LocJID, RemJID, ArcID) -> archive_id_int(HostType, ArcJID=#jid{}) -> mongoose_hooks:mam_archive_id(HostType, ArcJID). --spec archive_size(host_type(), archive_id(), jid:jid()) -> integer(). +-spec archive_size(host_type(), mod_mam:archive_id(), jid:jid()) -> integer(). archive_size(HostType, ArcID, ArcJID=#jid{}) -> mongoose_hooks:mam_archive_size(HostType, ArcID, ArcJID). --spec get_behaviour(host_type(), archive_id(), LocJID :: jid:jid(), +-spec get_behaviour(host_type(), mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> atom(). get_behaviour(HostType, ArcID, LocJID=#jid{}, RemJID=#jid{}) -> mongoose_hooks:mam_get_behaviour(HostType, ArcID, LocJID, RemJID). --spec set_prefs(host_type(), archive_id(), ArcJID :: jid:jid(), +-spec set_prefs(host_type(), mod_mam:archive_id(), ArcJID :: jid:jid(), DefaultMode :: atom(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -604,19 +549,19 @@ set_prefs(HostType, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> AlwaysJIDs, NeverJIDs). %% @doc Load settings from the database. --spec get_prefs(HostType :: host_type(), ArcID :: archive_id(), - ArcJID :: jid:jid(), GlobalDefaultMode :: archive_behaviour() - ) -> preference() | {error, Reason :: term()}. +-spec get_prefs(HostType :: host_type(), ArcID :: mod_mam:archive_id(), + ArcJID :: jid:jid(), GlobalDefaultMode :: mod_mam:archive_behaviour() + ) -> mod_mam:preference() | {error, Reason :: term()}. get_prefs(HostType, ArcID, ArcJID, GlobalDefaultMode) -> mongoose_hooks:mam_get_prefs(HostType, GlobalDefaultMode, ArcID, ArcJID). --spec remove_archive_hook(host_type(), archive_id(), jid:jid()) -> 'ok'. +-spec remove_archive_hook(host_type(), mod_mam:archive_id(), jid:jid()) -> 'ok'. remove_archive_hook(HostType, ArcID, ArcJID=#jid{}) -> mongoose_hooks:mam_remove_archive(HostType, ArcID, ArcJID), ok. -spec lookup_messages(HostType :: host_type(), Params :: map()) -> - {ok, lookup_result()} + {ok, mod_mam:lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. lookup_messages(HostType, Params) -> @@ -644,7 +589,7 @@ archive_message_from_ct(Params = #{local_jid := JID}) -> HostType = jid_to_host_type(JID), archive_message(HostType, Params). --spec archive_message(host_type(), archive_message_params()) -> +-spec archive_message(host_type(), mod_mam:archive_message_params()) -> ok | {error, timeout}. archive_message(HostType, Params) -> StartT = erlang:monotonic_time(microsecond), @@ -656,7 +601,7 @@ archive_message(HostType, Params) -> %% ---------------------------------------------------------------------- %% Helpers --spec message_row_to_xml(binary(), message_row(), QueryId :: binary(), boolean()) -> +-spec message_row_to_xml(binary(), mod_mam:message_row(), QueryId :: binary(), boolean()) -> exml:element(). message_row_to_xml(MamNs, #{id := MessID, jid := SrcJID, packet := Packet}, QueryID, SetClientNs) -> @@ -666,7 +611,7 @@ message_row_to_xml(MamNs, #{id := MessID, jid := SrcJID, packet := Packet}, Packet1 = mod_mam_utils:maybe_set_client_xmlns(SetClientNs, Packet), wrap_message(MamNs, Packet1, QueryID, BExtMessID, TS, SrcJID). --spec message_row_to_ext_id(message_row()) -> binary(). +-spec message_row_to_ext_id(mod_mam:message_row()) -> binary(). message_row_to_ext_id(#{id := MessID}) -> mess_id_to_external_binary(MessID). diff --git a/src/mam/mod_mam_rdbms_arch.erl b/src/mam/mod_mam_rdbms_arch.erl index f8a0809b90e..f72d05c8ecd 100644 --- a/src/mam/mod_mam_rdbms_arch.erl +++ b/src/mam/mod_mam_rdbms_arch.erl @@ -94,7 +94,7 @@ get_mam_pm_gdpr_data(Acc, HostType, [uniform_to_gdpr(row_to_uniform_format(Row, Env)) || Row <- Rows] ++ Acc end. --spec uniform_to_gdpr(mod_mam_pm:message_row()) -> tuple(). +-spec uniform_to_gdpr(mod_mam:message_row()) -> tuple(). uniform_to_gdpr(#{id := MessID, jid := RemoteJID, packet := Packet}) -> {integer_to_binary(MessID), jid:to_binary(RemoteJID), exml:to_binary(Packet)}. @@ -242,14 +242,14 @@ get_retract_id(Packet, #{has_message_retraction := Enabled}) -> %% Internal functions and callbacks -spec archive_size(Size :: integer(), HostType :: host_type(), - ArcId :: mod_mam_pm:archive_id(), ArcJID :: jid:jid()) -> integer(). + ArcId :: mod_mam:archive_id(), ArcJID :: jid:jid()) -> integer(). archive_size(Size, HostType, ArcID, ArcJID) when is_integer(Size) -> Filter = [{equal, user_id, ArcID}], Env = env_vars(HostType, ArcJID), Result = lookup_query(count, Env, Filter, unordered, all), mongoose_rdbms:selected_to_integer(Result). --spec archive_message(_Result, host_type(), mod_mam_pm:archive_message_params()) -> ok. +-spec archive_message(_Result, host_type(), mod_mam:archive_message_params()) -> ok. archive_message(_Result, HostType, Params = #{local_jid := ArcJID}) -> try assert_archive_id_provided(Params), @@ -270,12 +270,12 @@ do_archive_message(HostType, Params, Env) -> %% Retraction logic %% Called after inserting a new message --spec retract_message(host_type(), mod_mam_pm:archive_message_params()) -> ok. +-spec retract_message(host_type(), mod_mam:archive_message_params()) -> ok. retract_message(HostType, #{local_jid := ArcJID} = Params) -> Env = env_vars(HostType, ArcJID), retract_message(HostType, Params, Env). --spec retract_message(host_type(), mod_mam_pm:archive_message_params(), env_vars()) -> ok. +-spec retract_message(host_type(), mod_mam:archive_message_params(), env_vars()) -> ok. retract_message(HostType, #{archive_id := ArcID, remote_jid := RemJID, direction := Dir, packet := Packet} = Params, Env) -> case get_retract_id(Packet, Env) of @@ -320,7 +320,7 @@ execute_make_tombstone(HostType, TombstoneData, ArcID, MessID) -> [TombstoneData, ArcID, MessID]). %% Insert logic --spec prepare_message(host_type(), mod_mam_pm:archive_message_params()) -> list(). +-spec prepare_message(host_type(), mod_mam:archive_message_params()) -> list(). prepare_message(HostType, Params = #{local_jid := ArcJID}) -> Env = env_vars(HostType, ArcJID), mam_encoder:encode_message(Params, Env, db_mappings()). @@ -335,7 +335,7 @@ prepare_insert(Name, NumRows) -> %% Removal logic -spec remove_archive(Acc :: mongoose_acc:t(), HostType :: host_type(), - ArcID :: mod_mam_pm:archive_id(), + ArcID :: mod_mam:archive_id(), RoomJID :: jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, ArcID, _ArcJID) -> mongoose_rdbms:execute_successfully(HostType, mam_archive_remove, [ArcID]), @@ -358,7 +358,7 @@ extract_gdpr_messages(Env, ArcID) -> %% Lookup logic -spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) -> - {ok, mod_mam_pm:lookup_result()}. + {ok, mod_mam:lookup_result()}. lookup_messages({error, _Reason}=Result, _HostType, _Params) -> Result; lookup_messages(_Result, HostType, Params = #{owner_jid := ArcJID}) -> diff --git a/src/mam/mod_mam_rdbms_arch_async.erl b/src/mam/mod_mam_rdbms_arch_async.erl index b242a85acf4..dd765cfcec4 100644 --- a/src/mam/mod_mam_rdbms_arch_async.erl +++ b/src/mam/mod_mam_rdbms_arch_async.erl @@ -14,7 +14,7 @@ -export([make_pool_opts/2, prepare_insert_queries/2]). --spec archive_pm_message(_Result, mongooseim:host_type(), mod_mam_pm:archive_message_params()) -> ok. +-spec archive_pm_message(_Result, mongooseim:host_type(), mod_mam:archive_message_params()) -> ok. archive_pm_message(_Result, HostType, Params = #{archive_id := ArcID}) -> mongoose_async_pools:put_task(HostType, pm_mam, ArcID, Params). diff --git a/src/mam/mod_mam_rdbms_prefs.erl b/src/mam/mod_mam_rdbms_prefs.erl index 02261c0b146..b4cfa01b012 100644 --- a/src/mam/mod_mam_rdbms_prefs.erl +++ b/src/mam/mod_mam_rdbms_prefs.erl @@ -103,8 +103,8 @@ order_by_remote_jid_in_delete(HostType) -> %% ---------------------------------------------------------------------- %% Internal functions and callbacks --spec get_behaviour(Default :: mod_mam_pm:archive_behaviour(), - HostType :: mongooseim:host_type(), ArchiveID :: mod_mam_pm:archive_id(), +-spec get_behaviour(Default :: mod_mam:archive_behaviour(), + HostType :: mongooseim:host_type(), ArchiveID :: mod_mam:archive_id(), LocJID :: jid:jid(), RemJID :: jid:jid()) -> any(). get_behaviour(DefaultBehaviour, HostType, UserID, _LocJID, RemJID) when is_integer(UserID) -> @@ -136,8 +136,8 @@ choose_behaviour(BRemLJID, BRemLBareJID, RemoteJid2Behaviour) -> end. -spec set_prefs(Result :: any(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> any(). set_prefs(_Result, HostType, UserID, _ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> @@ -159,15 +159,15 @@ set_prefs1(HostType, UserID, DefaultMode, AlwaysJIDs, NeverJIDs) -> end, #{user_id => UserID, retries => 5, delay => 100}), ok. --spec get_prefs(mod_mam_pm:preference(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam_pm:archive_id(), ArchiveJID :: jid:jid()) - -> mod_mam_pm:preference(). +-spec get_prefs(mod_mam:preference(), HostType :: mongooseim:host_type(), + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) + -> mod_mam:preference(). get_prefs({GlobalDefaultMode, _, _}, HostType, UserID, _ArcJID) -> {selected, Rows} = mongoose_rdbms:execute(HostType, mam_prefs_select, [UserID]), decode_prefs_rows(Rows, GlobalDefaultMode, [], []). -spec remove_archive(mongoose_acc:t(), mongooseim:host_type(), - mod_mam_pm:archive_id(), jid:jid()) -> + mod_mam:archive_id(), jid:jid()) -> mongoose_acc:t(). remove_archive(Acc, HostType, UserID, _ArcJID) -> remove_archive(HostType, UserID), @@ -210,10 +210,10 @@ prefs_to_rows(UserID, DefaultMode, AlwaysJIDs, NeverJIDs) -> [DefaultRow|lists:sort(AlwaysRows ++ NeverRows)]. -spec decode_prefs_rows([{binary() | jid:jid(), binary()}], - DefaultMode :: mod_mam_pm:archive_behaviour(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literal_jid()]) -> - {mod_mam_pm:archive_behaviour(), [jid:literal_jid()], [jid:literal_jid()]}. + {mod_mam:archive_behaviour(), [jid:literal_jid()], [jid:literal_jid()]}. decode_prefs_rows([{<<>>, Behaviour}|Rows], _DefaultMode, AlwaysJIDs, NeverJIDs) -> decode_prefs_rows(Rows, decode_behaviour(Behaviour), AlwaysJIDs, NeverJIDs); decode_prefs_rows([{JID, <<"A">>}|Rows], DefaultMode, AlwaysJIDs, NeverJIDs) -> diff --git a/src/mam/mod_mam_rdbms_user.erl b/src/mam/mod_mam_rdbms_user.erl index 12399bc19a2..ba2a6e477f1 100644 --- a/src/mam/mod_mam_rdbms_user.erl +++ b/src/mam/mod_mam_rdbms_user.erl @@ -69,16 +69,16 @@ prepare_queries() -> %%==================================================================== %% API %%==================================================================== --spec archive_id(ArcID :: undefined | mod_mam_pm:archive_id(), +-spec archive_id(ArcID :: undefined | mod_mam:archive_id(), HostType :: mongooseim:host_type(), - ArchiveJID :: jid:jid()) -> mod_mam_pm:archive_id(). + ArchiveJID :: jid:jid()) -> mod_mam:archive_id(). archive_id(undefined, HostType, _ArcJID=#jid{lserver = LServer, luser = LUser}) -> query_archive_id(HostType, LServer, LUser); archive_id(ArcID, _Host, _ArcJID) -> ArcID. -spec remove_archive(Acc :: map(), HostType :: mongooseim:host_type(), - ArchiveID :: mod_mam_pm:archive_id(), + ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid()) -> map(). remove_archive(Acc, HostType, _ArcID, _ArcJID = #jid{lserver = LServer, luser = LUser}) -> execute_user_remove(HostType, LServer, LUser), diff --git a/src/mam/mod_mam_utils.erl b/src/mam/mod_mam_utils.erl index 6c091b4aad4..0340a1a96c0 100644 --- a/src/mam/mod_mam_utils.erl +++ b/src/mam/mod_mam_utils.erl @@ -136,16 +136,16 @@ -type ne_binary() :: <<_:8, _:_*8>>. -type iso8601_datetime_binary() :: ne_binary(). %% Microseconds from 01.01.1970 --type unix_timestamp() :: mod_mam_pm:unix_timestamp(). +-type unix_timestamp() :: mod_mam:unix_timestamp(). --type archive_behaviour() :: mod_mam_pm:archive_behaviour(). +-type archive_behaviour() :: mod_mam:archive_behaviour(). -type archive_behaviour_bin() :: binary(). % `<<"roster">> | <<"always">> | <<"never">>'. -type direction() :: incoming | outgoing. -type retraction_id() :: {origin_id | stanza_id, binary()}. -type retraction_info() :: #{retract_on := origin_id | stanza_id, packet := exml:element(), - message_id := mod_mam_pm:message_id(), + message_id := mod_mam:message_id(), origin_id := null | binary()}. %% ----------------------------------------------------------------------- @@ -577,7 +577,7 @@ maybe_transform_fin_elem(undefined, _HostType, _Params, FinEl) -> maybe_transform_fin_elem(Module, HostType, Params, FinEl) -> Module:extra_fin_element(HostType, Params, FinEl). --spec parse_prefs(PrefsEl :: exml:element()) -> mod_mam_pm:preference(). +-spec parse_prefs(PrefsEl :: exml:element()) -> mod_mam:preference(). parse_prefs(El = #xmlel{ name = <<"prefs">> }) -> Default = exml_query:attr(El, <<"default">>), AlwaysJIDs = parse_jid_list(El, <<"always">>), @@ -620,7 +620,7 @@ binary_jid_to_lower(BinJid) when is_binary(BinJid) -> skip_bad_jids(MaybeJids) -> [Jid || Jid <- MaybeJids, is_binary(Jid)]. --spec borders_decode(exml:element()) -> 'undefined' | mod_mam_pm:borders(). +-spec borders_decode(exml:element()) -> 'undefined' | mod_mam:borders(). borders_decode(QueryEl) -> AfterID = tag_id(QueryEl, <<"after_id">>), BeforeID = tag_id(QueryEl, <<"before_id">>), @@ -628,7 +628,7 @@ borders_decode(QueryEl) -> ToID = tag_id(QueryEl, <<"to_id">>), borders(AfterID, BeforeID, FromID, ToID). --spec form_borders_decode(exml:element()) -> 'undefined' | mod_mam_pm:borders(). +-spec form_borders_decode(exml:element()) -> 'undefined' | mod_mam:borders(). form_borders_decode(QueryEl) -> AfterID = form_field_mess_id(QueryEl, <<"after_id">>), BeforeID = form_field_mess_id(QueryEl, <<"before_id">>), @@ -641,7 +641,7 @@ form_borders_decode(QueryEl) -> BeforeID :: 'undefined' | non_neg_integer(), FromID :: 'undefined' | non_neg_integer(), ToID :: 'undefined' | non_neg_integer() - ) -> 'undefined' | mod_mam_pm:borders(). + ) -> 'undefined' | mod_mam:borders(). borders(undefined, undefined, undefined, undefined) -> undefined; borders(AfterID, BeforeID, FromID, ToID) -> @@ -945,7 +945,7 @@ maybe_integer(<<>>, Def) -> Def; maybe_integer(Bin, _Def) when is_binary(Bin) -> binary_to_integer(Bin). --spec apply_start_border('undefined' | mod_mam_pm:borders(), undefined | integer()) -> +-spec apply_start_border('undefined' | mod_mam:borders(), undefined | integer()) -> undefined | integer(). apply_start_border(undefined, StartID) -> StartID; @@ -953,16 +953,16 @@ apply_start_border(#mam_borders{after_id=AfterID, from_id=FromID}, StartID) -> maybe_max(maybe_next_id(AfterID), maybe_max(FromID, StartID)). --spec apply_end_border('undefined' | mod_mam_pm:borders(), undefined | integer()) -> +-spec apply_end_border('undefined' | mod_mam:borders(), undefined | integer()) -> undefined | integer(). apply_end_border(undefined, EndID) -> EndID; apply_end_border(#mam_borders{before_id=BeforeID, to_id=ToID}, EndID) -> maybe_min(maybe_previous_id(BeforeID), maybe_min(ToID, EndID)). --spec calculate_msg_id_borders(mod_mam_pm:borders() | undefined, - mod_mam_pm:unix_timestamp() | undefined, - mod_mam_pm:unix_timestamp() | undefined) -> R when +-spec calculate_msg_id_borders(mod_mam:borders() | undefined, + mod_mam:unix_timestamp() | undefined, + mod_mam:unix_timestamp() | undefined) -> R when R :: {integer() | undefined, integer() | undefined}. calculate_msg_id_borders(Borders, Start, End) -> StartID = maybe_encode_compact_uuid(Start, 0), @@ -972,9 +972,9 @@ calculate_msg_id_borders(Borders, Start, End) -> -spec calculate_msg_id_borders(RSM, Borders, Start, End) -> R when RSM :: jlib:rsm_in() | undefined, - Borders :: mod_mam_pm:borders() | undefined, - Start :: mod_mam_pm:unix_timestamp() | undefined, - End :: mod_mam_pm:unix_timestamp() | undefined, + Borders :: mod_mam:borders() | undefined, + Start :: mod_mam:unix_timestamp() | undefined, + End :: mod_mam:unix_timestamp() | undefined, R :: {integer() | undefined, integer() | undefined}. calculate_msg_id_borders(undefined, Borders, Start, End) -> calculate_msg_id_borders(Borders, Start, End); @@ -989,7 +989,7 @@ calculate_msg_id_borders(#rsm_in{direction = before, id = Id}, Borders, Start, E {StartId, EndId} = mod_mam_utils:calculate_msg_id_borders(Borders, Start, End), {StartId, mod_mam_utils:maybe_min(EndId, Id)}. --spec maybe_encode_compact_uuid(mod_mam_pm:unix_timestamp() | undefined, integer()) -> +-spec maybe_encode_compact_uuid(mod_mam:unix_timestamp() | undefined, integer()) -> undefined | integer(). maybe_encode_compact_uuid(undefined, _) -> undefined; @@ -1113,7 +1113,7 @@ wait_shaper(HostType, Host, Action, From) -> %% ----------------------------------------------------------------------- %% Ejabberd --spec send_message(mod_mam_pm:message_row(), jid:jid(), jid:jid(), exml:element()) -> mongoose_acc:t(). +-spec send_message(mod_mam:message_row(), jid:jid(), jid:jid(), exml:element()) -> mongoose_acc:t(). send_message(_Row, From, To, Mess) -> ejabberd_sm:route(From, To, Mess). @@ -1131,7 +1131,7 @@ wrapper_id() -> -spec check_result_for_policy_violation(Params, Result) -> Result when Params :: mam_iq:lookup_params(), - Result :: {ok, mod_mam_pm:lookup_result()} + Result :: {ok, mod_mam:lookup_result()} | {error, 'policy-violation'} | {error, Reason :: term()}. check_result_for_policy_violation( @@ -1162,8 +1162,8 @@ is_policy_violation(TotalCount, Offset, MaxResultLimit, LimitPassed) -> -spec check_for_item_not_found(RSM, PageSize, LookupResult) -> R when RSM :: jlib:rsm_in() | undefined, PageSize :: non_neg_integer(), - LookupResult :: mod_mam_pm:lookup_result(), - R :: {ok, mod_mam_pm:lookup_result()} | {error, item_not_found}. + LookupResult :: mod_mam:lookup_result(), + R :: {ok, mod_mam:lookup_result()} | {error, item_not_found}. check_for_item_not_found(#rsm_in{direction = before, id = ID}, PageSize, {TotalCount, Offset, MessageRows}) -> case maybe_last(MessageRows) of diff --git a/src/metrics/mongoose_metrics_mam_hooks.erl b/src/metrics/mongoose_metrics_mam_hooks.erl index c2738de5718..870910db12f 100644 --- a/src/metrics/mongoose_metrics_mam_hooks.erl +++ b/src/metrics/mongoose_metrics_mam_hooks.erl @@ -66,14 +66,14 @@ get_mam_muc_hooks(Host) -> -spec mam_get_prefs(Result :: any(), Host :: jid:server(), - _ArcID :: mod_mam_pm:archive_id(), + _ArcID :: mod_mam:archive_id(), _ArcJID :: jid:jid()) -> any(). mam_get_prefs(Result, Host, _ArcID, _ArcJID) -> mongoose_metrics:update(Host, modMamPrefsGets, 1), Result. -spec mam_set_prefs(Result :: any(), Host :: jid:server(), - _ArcID :: mod_mam_pm:archive_id(), _ArcJID :: jid:jid(), + _ArcID :: mod_mam:archive_id(), _ArcJID :: jid:jid(), _DefaultMode :: any(), _AlwaysJIDs :: [jid:literal_jid()], _NeverJIDs :: [jid:literal_jid()]) -> any(). mam_set_prefs(Result, Host, _ArcID, _ArcJID, _DefaultMode, _AlwaysJIDs, _NeverJIDs) -> @@ -82,7 +82,7 @@ mam_set_prefs(Result, Host, _ArcID, _ArcJID, _DefaultMode, _AlwaysJIDs, _NeverJI -spec mam_remove_archive(Acc :: map(), Host :: jid:server(), - _ArcID :: mod_mam_pm:archive_id(), + _ArcID :: mod_mam:archive_id(), _ArcJID :: jid:jid()) -> metrics_notify_return(). mam_remove_archive(Acc, Host, _ArcID, _ArcJID) -> mongoose_metrics:update(Host, modMamArchiveRemoved, 1), @@ -103,7 +103,7 @@ mam_lookup_messages(Result = {error, _}, _Host, _Params) -> Result. -spec mam_archive_message(Result :: any(), Host :: jid:server(), - _Params :: mod_mam_pm:archive_message_params()) -> any(). + _Params :: mod_mam:archive_message_params()) -> any(). mam_archive_message(Result, Host, _Params) -> mongoose_metrics:update(Host, modMamArchived, 1), Result. @@ -137,7 +137,7 @@ mam_muc_lookup_messages(Result = {error, _}, Result. -spec mam_muc_archive_message(Result :: any(), Host :: jid:server(), - _Params :: mod_mam_pm:archive_message_params()) -> any(). + _Params :: mod_mam:archive_message_params()) -> any(). mam_muc_archive_message(Result, Host, _Params) -> mongoose_metrics:update(Host, modMucMamArchived, 1), Result. diff --git a/src/mod_commands.erl b/src/mod_commands.erl index bf8a489ca65..fae96ef53df 100644 --- a/src/mod_commands.erl +++ b/src/mod_commands.erl @@ -463,7 +463,7 @@ change_user_password(Host, User, Password) -> {error, bad_request, "invalid jid"} end. --spec row_to_map(mod_mam_pm:message_row()) -> map(). +-spec row_to_map(mod_mam:message_row()) -> map(). row_to_map(#{id := Id, jid := From, packet := Msg}) -> Jbin = jid:to_binary(From), {Msec, _} = mod_mam_utils:decode_compact_uuid(Id), diff --git a/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl b/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl index f687ca511d3..2dc779543b5 100644 --- a/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl +++ b/src/mongoose_client_api/mongoose_client_api_rooms_messages.erl @@ -164,7 +164,7 @@ encode(Packet, Timestamp) -> Msg = make_json_item(Packet, FromJID, Timestamp), Msg#{room => FromJID#jid.luser}. --spec make_json_item(mod_mam_pm:message_row()) -> term(). +-spec make_json_item(mod_mam:message_row()) -> term(). make_json_item(#{id := MAMID, jid := JID, packet := Msg}) -> {Microsec, _} = mod_mam_utils:decode_compact_uuid(MAMID), make_json_item(Msg, JID, Microsec div 1000). diff --git a/src/mongoose_deprecations.erl b/src/mongoose_deprecations.erl index 4891c371f36..bc1659ae503 100644 --- a/src/mongoose_deprecations.erl +++ b/src/mongoose_deprecations.erl @@ -29,7 +29,7 @@ -type deprecation_tag() :: any(). % Specifies the deprecation -type log_level() :: warning | error. --type unix_timestamp() :: mod_mam_pm:unix_timestamp(). +-type unix_timestamp() :: mod_mam:unix_timestamp(). -type log_map() :: map(). diff --git a/src/mongoose_hooks.erl b/src/mongoose_hooks.erl index ebe9f054519..c60646178f9 100644 --- a/src/mongoose_hooks.erl +++ b/src/mongoose_hooks.erl @@ -961,7 +961,7 @@ room_new_affiliations(Acc, Room, NewAffs, Version) -> -spec mam_archive_id(HostType, OwnerJID) -> Result when HostType :: mongooseim:host_type(), OwnerJID :: jid:jid(), - Result :: undefined | mod_mam_pm:archive_id(). + Result :: undefined | mod_mam:archive_id(). mam_archive_id(HostType, OwnerJID) -> run_hook_for_host_type(mam_archive_id, HostType, undefined, [HostType, OwnerJID]). @@ -969,7 +969,7 @@ mam_archive_id(HostType, OwnerJID) -> %%% of the archive for a given JID -spec mam_archive_size(HostType, ArchiveID, OwnerJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), OwnerJID :: jid:jid(), Result :: integer(). mam_archive_size(HostType, ArchiveID, OwnerJID) -> @@ -981,10 +981,10 @@ mam_archive_size(HostType, ArchiveID, OwnerJID) -> -spec mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> Result when HookServer :: jid:lserver(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), OwnerJID :: jid:jid(), RemoteJID :: jid:jid(), - Result :: mod_mam_pm:archive_behaviour(). + Result :: mod_mam:archive_behaviour(). mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> run_hook_for_host_type(mam_get_behaviour, HookServer, always, [HookServer, ArchiveID, OwnerJID, RemoteJID]). @@ -995,9 +995,9 @@ mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> -spec mam_set_prefs(HookServer, ArchiveId, OwnerJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when HookServer :: jid:lserver(), - ArchiveId :: undefined | mod_mam_pm:archive_id(), + ArchiveId :: undefined | mod_mam:archive_id(), OwnerJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literel_jid()], Result :: any(). @@ -1010,12 +1010,12 @@ mam_set_prefs(HookServer, ArchiveID, OwnerJID, DefaultMode, AlwaysJIDs, NeverJI %%% the archive settings for a given user. -spec mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> Result when HookServer :: jid:lserver(), - DefaultMode :: mod_mam_pm:archive_behaviour(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + DefaultMode :: mod_mam:archive_behaviour(), + ArchiveID :: undefined | mod_mam:archive_id(), OwnerJID :: jid:jid(), - Result :: mod_mam_pm:preference() | {error, Reason :: term()}. + Result :: mod_mam:preference() | {error, Reason :: term()}. mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> - InitialAccValue = {DefaultMode, [], []}, %% mod_mam_pm:preference() type + InitialAccValue = {DefaultMode, [], []}, %% mod_mam:preference() type run_hook_for_host_type(mam_get_prefs, HookServer, InitialAccValue, [HookServer, ArchiveID, OwnerJID]). @@ -1023,7 +1023,7 @@ mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> %%% remove the entire archive for a particular user. -spec mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> any() when HookServer :: jid:lserver(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), OwnerJID :: jid:jid(). mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> run_hook_for_host_type(mam_remove_archive, HookServer, ok, @@ -1034,9 +1034,9 @@ mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> -spec mam_lookup_messages(HookServer, Params) -> Result when HookServer :: jid:lserver(), Params :: map(), - Result :: {ok, mod_mam_pm:lookup_result()}. + Result :: {ok, mod_mam:lookup_result()}. mam_lookup_messages(HookServer, Params) -> - InitialLookupValue = {0, 0, []}, %% mod_mam_pm:lookup_result() type + InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type run_hook_for_host_type(mam_lookup_messages, HookServer, {ok, InitialLookupValue}, [HookServer, Params]). @@ -1045,7 +1045,7 @@ mam_lookup_messages(HookServer, Params) -> -spec mam_archive_message(HookServer, Params) -> Result when HookServer :: jid:lserver(), - Params :: mod_mam_pm:archive_message_params(), + Params :: mod_mam:archive_message_params(), Result :: ok | {error, timeout}. mam_archive_message(HookServer, Params) -> run_hook_for_host_type(mam_archive_message, HookServer, ok, [HookServer, Params]). @@ -1066,7 +1066,7 @@ mam_archive_sync(HostType) -> %% @doc Notifies of a message retraction -spec mam_retraction(mongooseim:host_type(), mod_mam_utils:retraction_info(), - mod_mam_pm:archive_message_params()) -> + mod_mam:archive_message_params()) -> mod_mam_utils:retraction_info(). mam_retraction(HostType, RetractionInfo, Env) -> run_fold(mam_retraction, HostType, RetractionInfo, Env). @@ -1087,7 +1087,7 @@ mam_retraction(HostType, RetractionInfo, Env) -> -spec mam_muc_archive_id(HookServer, OwnerJID) -> Result when HookServer :: jid:lserver(), OwnerJID :: jid:jid(), - Result :: undefined | mod_mam_pm:archive_id(). + Result :: undefined | mod_mam:archive_id(). mam_muc_archive_id(HookServer, OwnerJID) -> run_hook_for_host_type(mam_muc_archive_id, HookServer, undefined, [HookServer, OwnerJID]). @@ -1096,7 +1096,7 @@ mam_muc_archive_id(HookServer, OwnerJID) -> %%% the archive size for a given room. -spec mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), RoomJID :: jid:jid(), Result :: integer(). mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> @@ -1108,12 +1108,12 @@ mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> -spec mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> Result when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), RoomJID :: jid:jid(), RemoteJID :: jid:jid(), - Result :: mod_mam_pm:archive_behaviour(). + Result :: mod_mam:archive_behaviour(). mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> - DefaultBehaviour = always, %% mod_mam_pm:archive_behaviour() type + DefaultBehaviour = always, %% mod_mam:archive_behaviour() type run_hook_for_host_type(mam_muc_get_behaviour, HostType, DefaultBehaviour, [HostType, ArchiveID, RoomJID, RemoteJID]). @@ -1123,9 +1123,9 @@ mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> -spec mam_muc_set_prefs(HostType, ArchiveId, RoomJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when HostType :: mongooseim:host_type(), - ArchiveId :: undefined | mod_mam_pm:archive_id(), + ArchiveId :: undefined | mod_mam:archive_id(), RoomJID :: jid:jid(), - DefaultMode :: mod_mam_pm:archive_behaviour(), + DefaultMode :: mod_mam:archive_behaviour(), AlwaysJIDs :: [jid:literal_jid()], NeverJIDs :: [jid:literel_jid()], Result :: any(). @@ -1139,12 +1139,12 @@ mam_muc_set_prefs(HostType, ArchiveID, RoomJID, DefaultMode, AlwaysJIDs, NeverJI %%% the archive settings for a given room. -spec mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> Result when HostType :: mongooseim:host_type(), - DefaultMode :: mod_mam_pm:archive_behaviour(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + DefaultMode :: mod_mam:archive_behaviour(), + ArchiveID :: undefined | mod_mam:archive_id(), RoomJID :: jid:jid(), - Result :: mod_mam_pm:preference() | {error, Reason :: term()}. + Result :: mod_mam:preference() | {error, Reason :: term()}. mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> - InitialAcc = {DefaultMode, [], []}, %% mod_mam_pm:preference() type + InitialAcc = {DefaultMode, [], []}, %% mod_mam:preference() type run_hook_for_host_type(mam_muc_get_prefs, HostType, InitialAcc, [HostType, ArchiveID, RoomJID]). @@ -1152,7 +1152,7 @@ mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> %%% archive for a particular user. -spec mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> any() when HostType :: mongooseim:host_type(), - ArchiveID :: undefined | mod_mam_pm:archive_id(), + ArchiveID :: undefined | mod_mam:archive_id(), RoomJID :: jid:jid(). mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> run_hook_for_host_type(mam_muc_remove_archive, HostType, ok, @@ -1163,9 +1163,9 @@ mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> -spec mam_muc_lookup_messages(HostType, Params) -> Result when HostType :: mongooseim:host_type(), Params :: map(), - Result :: {ok, mod_mam_pm:lookup_result()}. + Result :: {ok, mod_mam:lookup_result()}. mam_muc_lookup_messages(HostType, Params) -> - InitialLookupValue = {0, 0, []}, %% mod_mam_pm:lookup_result() type + InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type run_hook_for_host_type(mam_muc_lookup_messages, HostType, {ok, InitialLookupValue}, [HostType, Params]). @@ -1173,7 +1173,7 @@ mam_muc_lookup_messages(HostType, Params) -> %%% to store the MUC message in the archive. -spec mam_muc_archive_message(HostType, Params) -> Result when HostType :: mongooseim:host_type(), - Params :: mod_mam_pm:archive_message_params(), + Params :: mod_mam:archive_message_params(), Result :: ok | {error, timeout}. mam_muc_archive_message(HostType, Params) -> run_hook_for_host_type(mam_muc_archive_message, HostType, ok, [HostType, Params]). @@ -1194,7 +1194,7 @@ mam_muc_archive_sync(HostType) -> %% @doc Notifies of a muc message retraction -spec mam_muc_retraction(mongooseim:host_type(), mod_mam_utils:retraction_info(), - mod_mam_pm:archive_message_params()) -> + mod_mam:archive_message_params()) -> mod_mam_utils:retraction_info(). mam_muc_retraction(HostType, RetractionInfo, Env) -> run_fold(mam_muc_retraction, HostType, RetractionInfo, Env). From 0fa917f5d2cc729c1921a1fea110e6b58ec00c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Jun 2022 14:56:59 +0200 Subject: [PATCH 4/5] Update MAM docs --- doc/modules/mod_mam.md | 116 +++++++++--------- .../Logging-&-monitoring.md | 4 +- doc/operation-and-maintenance/known-issues.md | 2 +- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/doc/modules/mod_mam.md b/doc/modules/mod_mam.md index 260d4220062..c5b10ecb390 100644 --- a/doc/modules/mod_mam.md +++ b/doc/modules/mod_mam.md @@ -14,7 +14,7 @@ Configure MAM with different storage backends: * Cassandra (NoSQL) * ElasticSearch (NoSQL) -`mod_mam_meta` is a meta-module that ensures all relevant `mod_mam_*` modules are loaded and properly configured. +`mod_mam` is a meta-module that ensures all relevant `mod_mam_*` modules are loaded and properly configured. ### Message retraction This module supports [XEP-0424: Message Retraction](http://xmpp.org/extensions/xep-0424.html) with RDBMS storage backends. When a [retraction message](https://xmpp.org/extensions/xep-0424.html#example-4) is received, the MAM module finds the message to retract and replaces it with a tombstone. @@ -64,28 +64,28 @@ Also note that the default separator for the search query is `AND` (which roughl ## Options -### `modules.mod_mam_meta.backend` +### `modules.mod_mam.backend` * **Syntax:** string, one of `"rdbms"`, `"riak"`, `"cassandra"` and `"elasticsearch"` * **Default:** `"rdbms"` * **Example:** `backend = "riak"` Database backend to use. -### `modules.mod_mam_meta.no_stanzaid_element` +### `modules.mod_mam.no_stanzaid_element` * **Syntax:** boolean * **Default:** `false` * **Example:** `no_stanzaid_element = true` Do not add a `` element from MAM v0.6. -### `modules.mod_mam_meta.is_archivable_message` +### `modules.mod_mam.is_archivable_message` * **Syntax:** non-empty string * **Default:** `"mod_mam_utils"` * **Example:** `is_archivable_message = "mod_mam_utils"` Name of a module implementing [`is_archivable_message/3` callback](#is_archivable_message) that determines if the message should be archived. -### `modules.mod_mam_meta.send_message` +### `modules.mod_mam.send_message` * **Syntax:** non-empty string * **Default:** `"mod_mam_utils"` * **Example:** `send_message = "mod_mam_utils"` @@ -96,7 +96,7 @@ Consult with `mod_mam_utils:send_message/4` code for more information. Check `big_tests/tests/mam_send_message_SUITE_data/mam_send_message_example.erl` file in the MongooseIM repository for the usage example. -### `modules.mod_mam_meta.archive_chat_markers` +### `modules.mod_mam.archive_chat_markers` * **Syntax:** boolean * **Default:** `false` * **Example:** `archive_chat_markers = true` @@ -104,7 +104,7 @@ in the MongooseIM repository for the usage example. If set to true, XEP-0333 chat markers will be archived. See more details [here](#archiving-chat-markers). -### `modules.mod_mam_meta.message_retraction` +### `modules.mod_mam.message_retraction` * **Syntax:** boolean * **Default:** `true` * **Example:** `message_retraction = false` @@ -119,17 +119,17 @@ This functionality is currently implemented only for the `rdbms` backend. Archive for one-to-one messages can be enabled in one of two ways: -* Specify `[mod_mam_meta.pm]` section +* Specify `[mod_mam.pm]` section ```toml -[modules.mod_mam_meta] -[modules.mod_mam_meta.pm] # defining this section enables PM support +[modules.mod_mam] +[modules.mod_mam.pm] # defining this section enables PM support ``` * Define any PM related option ```toml -[modules.mod_mam_meta] +[modules.mod_mam] pm.backend = "rdbms" # enables PM support and overrides its backend ``` @@ -139,17 +139,17 @@ To disable archive for one-to-one messages please remove PM section or any PM re ### PM-specific options -#### `modules.mod_mam_meta.pm.archive_groupchats` +#### `modules.mod_mam.pm.archive_groupchats` * **Syntax:** boolean * **Default:** `false` -* **Example:** `modules.mod_mam_meta.pm.archive_groupchats = true` +* **Example:** `modules.mod_mam.pm.archive_groupchats = true` When enabled, MAM will store groupchat messages in recipients' individual archives. **USE WITH CAUTION!** May increase archive size significantly. Disabling this option for existing installation will neither remove such messages from MAM storage, nor will filter out them from search results. -#### `modules.mod_mam_meta.pm.same_mam_id_for_peers` +#### `modules.mod_mam.pm.same_mam_id_for_peers` * **Syntax:** boolean * **Default:** `false` -* **Example:** `modules.mod_mam_meta.pm.same_mam_id_for_peers = true` +* **Example:** `modules.mod_mam.pm.same_mam_id_for_peers = true` When enabled, MAM will set the same MAM ID for both sender and recipient. This can be useful in combination with [retraction on the stanza-id](#retraction-on-the-stanza-id). Note that this might not work with clients across federation, as the recipient might not implement the same retraction, nor the same IDs. @@ -157,17 +157,17 @@ When enabled, MAM will set the same MAM ID for both sender and recipient. This c Archive for MUC messages can be enabled in one of two ways: -* Specify `[mod_mam_meta.muc]` section +* Specify `[mod_mam.muc]` section ```toml -[modules.mod_mam_meta] -[modules.mod_mam_meta.muc] # defining this section enables MUC support +[modules.mod_mam] +[modules.mod_mam.muc] # defining this section enables MUC support ``` * Define any MUC related option ```toml -[modules.mod_mam_meta] +[modules.mod_mam] muc.backend = "rdbms" # enables MUC support and overrides its backend ``` @@ -177,10 +177,10 @@ To disable archive for MUC messages please remove MUC section or any MUC related ### MUC-specific options -#### `modules.mod_mam_meta.muc.host` +#### `modules.mod_mam.muc.host` * **Syntax:** string * **Default:** `"conference.@HOST@"` -* **Example:** `modules.mod_mam_meta.muc.host = "conference.@HOST@"` +* **Example:** `modules.mod_mam.muc.host = "conference.@HOST@"` The MUC host that will be archived if MUC archiving is enabled. @@ -193,7 +193,7 @@ The example below presents how to override common option for `muc` module specif Please note that you can override all common options (except `cache`) in a similar way. ```toml -[modules.mod_mam_meta] +[modules.mod_mam] backend = "rdbms" async_writer.enabled = true # this option enables async writer for RDBMS backend muc.async_writer.enabled = false # disable async writer for MUC archive only @@ -203,64 +203,64 @@ Please note that you can override all common options (except `cache`) in a simil These options will only have effect when the `rdbms` backend is used: -#### `modules.mod_mam_meta.cache_users` +#### `modules.mod_mam.cache_users` * **Syntax:** boolean * **Default:** `true` -* **Example:** `modules.mod_mam_meta.cache_users = false` +* **Example:** `modules.mod_mam.cache_users = false` Enables Archive ID to integer mappings cache. If caching is enabled, by default it will spawn its own [segmented cache](https://github.com/esl/segmented_cache) cache, with defaults as in [`mod_cache_users`](./mod_cache_users.md). To change these defaults, the same config can be accessed within the `cache` key. To see details about the meaning of each flag, see [`mod_cache_users`](./mod_cache_users.md). To reuse the cache already created by `mod_cache_users`, see the option below. ```toml -modules.mod_mam_meta.cache.strategy -modules.mod_mam_meta.cache.time_to_live -modules.mod_mam_meta.cache.number_of_segments +modules.mod_mam.cache.strategy +modules.mod_mam.cache.time_to_live +modules.mod_mam.cache.number_of_segments ``` -#### `modules.mod_mam_meta.cache.module` +#### `modules.mod_mam.cache.module` * **Syntax:** string, one of `"mod_cache_users"` or `"internal"` * **Default:** `internal` -* **Example:** `modules.mod_mam_meta.cache.module = "mod_cache_users"` +* **Example:** `modules.mod_mam.cache.module = "mod_cache_users"` Configures which cache to use, either start an internal instance, or reuse the cache created by `mod_cache_users`, if such module was enabled. Note that if reuse is desired – that is, `cache.module = "mod_cache_users"`, other cache configuration parameters will be ignored. -#### `modules.mod_mam_meta.async_writer.enabled` +#### `modules.mod_mam.async_writer.enabled` * **Syntax:** boolean * **Default:** `true` -* **Example:** `modules.mod_mam_meta.async_writer.enabled = false` +* **Example:** `modules.mod_mam.async_writer.enabled = false` Enables an asynchronous writer that is faster than the synchronous one but harder to debug. The async writers store batches of messages that will be flush on a timeout (see **flush_interval**) or when the batch reaches a size (see **batch_size**), so the results of the lookup operations executed right after message routing may be incomplete until the configured time passes or the queue is full. -#### `modules.mod_mam_meta.async_writer.flush_interval` +#### `modules.mod_mam.async_writer.flush_interval` * **Syntax:** non-negative integer * **Default:** `2000` -* **Example:** `modules.mod_mam_meta.async_writer.flush_interval = 2000` +* **Example:** `modules.mod_mam.async_writer.flush_interval = 2000` How often (in milliseconds) the buffered messages are flushed to DB. -#### `modules.mod_mam_meta.async_writer.batch_size` +#### `modules.mod_mam.async_writer.batch_size` * **Syntax:** non-negative integer * **Default:** `30` -* **Example:** `modules.mod_mam_meta.async_writer.batch_size = 30` +* **Example:** `modules.mod_mam.async_writer.batch_size = 30` Max size of the batch for an async writer before the queue is considered full and flushed. If the buffer is full, messages are flushed to a database immediately and the flush timer is reset. -#### `modules.mod_mam_meta.async_writer.pool_size` +#### `modules.mod_mam.async_writer.pool_size` * **Syntax:** non-negative integer * **Default:** `4 * erlang:system_info(schedulers_online)` -* **Example:** `modules.mod_mam_meta.async_writer.pool_size = 32` +* **Example:** `modules.mod_mam.async_writer.pool_size = 32` Number of workers in the pool. More than the number of available schedulers is recommended, to minimise lock contention on the message queues, and more than the number of DB workers, to fully utilise the DB capacity. How much more than these two parameters is then a good fine-tuning for specific deployments. ### Common backend options -#### `modules.mod_mam_meta.user_prefs_store` +#### `modules.mod_mam.user_prefs_store` * **Syntax:** one of `"rdbms"`, `"cassandra"`, `"mnesia"` * **Default:** not set -* **Example:** `modules.mod_mam_meta.user_prefs_store = "rdbms"` +* **Example:** `modules.mod_mam.user_prefs_store = "rdbms"` Leaving this option unset will prevent users from setting their archiving preferences. It will also increase performance. @@ -270,10 +270,10 @@ The possible values are: * `"cassandra"` (Cassandra backend only) - User archiving preferences are saved in Cassandra. * `"mnesia"` (recommended) - User archiving preferences saved in Mnesia and accessed without transactions. Recommended in most deployments, could be overloaded with lots of users updating their preferences at once. There's a small risk of an inconsistent (in a rather harmless way) state of the preferences table. -#### `modules.mod_mam_meta.full_text_search` +#### `modules.mod_mam.full_text_search` * **Syntax:** boolean * **Default:** `true` -* **Example:** `modules.mod_mam_meta.full_text_search = false` +* **Example:** `modules.mod_mam.full_text_search = false` Enables full text search in message archive (see *Full Text Search* paragraph). Please note that the full text search is currently only implemented for `"rdbms"` and `"riak"` backends. @@ -309,17 +309,17 @@ This backend works with Riak KV 2.0 and above, but we recommend version 2.1.1. #### Riak-specific options -#### `modules.mod_mam_meta.riak.bucket_type` +#### `modules.mod_mam.riak.bucket_type` * **Syntax:** non-empty string * **Default:** `"mam_yz"` -* **Example:** `modules.mod_mam_meta.riak.bucket_type = "mam_yz"` +* **Example:** `modules.mod_mam.riak.bucket_type = "mam_yz"` Riak bucket type. -#### `modules.mod_mam_meta.riak.search_index` +#### `modules.mod_mam.riak.search_index` * **Syntax:** non-empty string * **Default:** `"mam"` -* **Example:** `modules.mod_mam_meta.riak.search_index = "mam"` +* **Example:** `modules.mod_mam.riak.search_index = "mam"` Riak index name. @@ -338,63 +338,63 @@ Please consult [Outgoing connections](../configuration/outgoing-connections.md#e These options allow for fine-grained control over MAM behaviour. -#### `modules.mod_mam_meta.default_result_limit` +#### `modules.mod_mam.default_result_limit` * **Syntax:** non-negative integer * **Default:** `50` -* **Example:** `modules.mod_mam_meta.default_result_limit = 100` +* **Example:** `modules.mod_mam.default_result_limit = 100` This sets the default page size of returned results. -#### `modules.mod_mam_meta.max_result_limit` +#### `modules.mod_mam.max_result_limit` * **Syntax:** non-negative integer * **Default:** `50` -* **Example:** `modules.mod_mam_meta.max_result_limit = 100` +* **Example:** `modules.mod_mam.max_result_limit = 100` This sets the maximum page size of returned results. -#### `modules.mod_mam_meta.db_jid_format` +#### `modules.mod_mam.db_jid_format` * **Syntax:** string, one of `"mam_jid_rfc"`, `"mam_jid_rfc_trust"`, `"mam_jid_mini"` or a module implementing `mam_jid` behaviour * **Default:** `"mam_jid_rfc"` for MUC archive, `"mam_jid_mini"` for PM archive -* **Example:** `modules.mod_mam_meta.db_jid_format = "mam_jid_mini"` +* **Example:** `modules.mod_mam.db_jid_format = "mam_jid_mini"` Sets the internal MAM jid encoder/decoder module for RDBMS. !!! Warning Archive MUST be empty to change this option -#### `modules.mod_mam_meta.db_message_format` +#### `modules.mod_mam.db_message_format` * **Syntax:** string, one of `"mam_message_xml"`, `"mam_message_eterm"`, `"mam_message_compressed_eterm"` or a module implementing `mam_message` behaviour * **Default:** `"mam_message_compressed_eterm"` for RDBMS, `"mam_message_xml"` for Riak and Cassandra -* **Example:** `modules.mod_mam_meta.db_message_format = "mam_message_compressed_eterm"` +* **Example:** `modules.mod_mam.db_message_format = "mam_message_compressed_eterm"` Sets the internal MAM message encoder/decoder module. !!! Warning Archive MUST be empty to change this option -#### `modules.mod_mam_meta.extra_fin_element` +#### `modules.mod_mam.extra_fin_element` * **Syntax:** string, a module implementing the `extra_fin_element/3` callback * **Default:** none -* **Example:** `modules.mod_mam_meta.extra_fin_element = "example_mod"` +* **Example:** `modules.mod_mam.extra_fin_element = "example_mod"` This module can be used to add subelements to the `` element of the MAM lookup query response. It can be useful to be able to add information to a mam query, that doesn't belong to any specific message but to all of them. -#### `modules.mod_mam_meta.extra_lookup_params` +#### `modules.mod_mam.extra_lookup_params` * **Syntax:** string, a module implementing the `extra_lookup_params/2` callback * **Default:** none -* **Example:** `modules.mod_mam_meta.extra_lookup_params = "example_mod"` +* **Example:** `modules.mod_mam.extra_lookup_params = "example_mod"` This module can be used to add extra lookup parameters to MAM lookup queries. ## Example configuration ```toml -[modules.mod_mam_meta] +[modules.mod_mam] backend = "rdbms" no_stanzaid_element = true diff --git a/doc/operation-and-maintenance/Logging-&-monitoring.md b/doc/operation-and-maintenance/Logging-&-monitoring.md index 12c30fa8d2d..2105d327200 100644 --- a/doc/operation-and-maintenance/Logging-&-monitoring.md +++ b/doc/operation-and-maintenance/Logging-&-monitoring.md @@ -125,8 +125,8 @@ Authorization time: ..backends.auth.authorize...backends.mongoose_rdbms.query. RDBMS prepared query time: ..backends.mongoose_rdbms.execute. MAM lookups: ..mam_lookup_messages.one -MAM archivization time: ..backends.mod_mam.archive. -MAM lookup time: ..backends.mod_mam.lookup. +MAM archivization time: ..backends.mod_mam_pm.archive. +MAM lookup time: ..backends.mod_mam_pm.lookup. MAM private messages flush time: ..mod_mam_rdbms_async_pool_writer.flush_time. MAM MUC messages flush time: ..mod_mam_muc_rdbms_async_pool_writer.flush_time. ``` diff --git a/doc/operation-and-maintenance/known-issues.md b/doc/operation-and-maintenance/known-issues.md index a4f1add8128..f7577c09686 100644 --- a/doc/operation-and-maintenance/known-issues.md +++ b/doc/operation-and-maintenance/known-issues.md @@ -46,7 +46,7 @@ The problems should now be resolved, and MSSQL is verified to work on Ubuntu 20. ## GDPR retrieval for MAM MUC limitation When the personal data retrieval is executed for a user in a specific domain, Message Archive Management for groupchats must be running for this particular domain. -This is the case for most configurations, but the problem manifests when a MongooseIM operator configures `mod_mam_muc`/`mod_mam_meta` to start only for a subset of domains supported by the cluster (`host_config` option). +This is the case for most configurations, but the problem manifests when a MongooseIM operator configures `mod_mam_muc`/`mod_mam` to start only for a subset of domains supported by the cluster (`host_config` option). In such case, personal data stored by MAM MUC will not be retrieved for this user. From 70796b88107750eb67601f4d0540995fd721760e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Jun 2022 15:06:26 +0200 Subject: [PATCH 5/5] Document the migration of mod_mam --- doc/migrations/5.1.0_6.0.0.md | 7 +++++++ mkdocs.yml | 1 + 2 files changed, 8 insertions(+) create mode 100644 doc/migrations/5.1.0_6.0.0.md diff --git a/doc/migrations/5.1.0_6.0.0.md b/doc/migrations/5.1.0_6.0.0.md new file mode 100644 index 00000000000..5fbbba012a3 --- /dev/null +++ b/doc/migrations/5.1.0_6.0.0.md @@ -0,0 +1,7 @@ +## Configuration + +The `mod_mam_meta` module is now named `mod_mam` for simplicity, so if you are using this module, you need to update the module name in `mongooseim.toml`. + +## Metrics + +The `mod_mam` backend module is now named `mod_mam_pm` for consistency with `mod_mam_muc`. As a result, the backend metrics have updated names, i.e. each `[backends, mod_mam, Metric]` name is changed to `[backends, mod_mam_pm, Metric]`, where `Metric` can be `lookup` or `archive`. diff --git a/mkdocs.yml b/mkdocs.yml index e6831d9b55c..18dfbf90fdd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -186,6 +186,7 @@ nav: - '4.1.0 to 4.2.0': 'migrations/4.1.0_4.2.0.md' - '4.2.0 to 5.0.0': 'migrations/4.2.0_5.0.0.md' - '5.0.0 to 5.1.0': 'migrations/5.0.0_5.1.0.md' + - '5.1.0 to 6.0.0': 'migrations/5.1.0_6.0.0.md' - 'MAM MUC migration helper': 'migrations/jid-from-mam-muc-script.md' - 'Contributions to the Ecosystem': 'Contributions.md' - 'MongooseIM History': 'History.md'