Skip to content

Commit

Permalink
Use host_type() instead of server_hostname()
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Oct 27, 2021
1 parent c94502a commit 01ba08c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
22 changes: 10 additions & 12 deletions src/mam/mod_mam_cassandra_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
%gdpr
-export([get_mam_pm_gdpr_data/3]).

-define(MOD_MAM_CASSANDRA_ARCH_PARAMS, mod_mam_cassandra_arch_params).
-ignore_xref([
behaviour_info/1, remove_archive/4
]).
Expand Down Expand Up @@ -74,8 +73,7 @@

-type filter() :: #mam_ca_filter{}.
-type message_id() :: non_neg_integer().
-type server_hostname() :: binary().

-type host_type() :: mongooseim:host_type().

%% ----------------------------------------------------------------------
%% gen_mod callbacks
Expand Down Expand Up @@ -229,7 +227,7 @@ remove_archive(HostType, UserJID) ->
%% ----------------------------------------------------------------------
%% SELECT MESSAGES

-spec lookup_messages(Result :: any(), HostType :: mongooseim:host_type(), Params :: map()) ->
-spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) ->
{ok, mod_mam:lookup_result()}.
lookup_messages({error, _Reason} = Result, _HostType, _Params) ->
Result;
Expand Down Expand Up @@ -436,7 +434,7 @@ row_to_message_id(#{id := MsgID}) ->
MsgID.

-spec get_mam_pm_gdpr_data(ejabberd_gen_mam_archive:mam_pm_gdpr_data(),
mongooseim:host_type(), jid:jid()) ->
host_type(), jid:jid()) ->
ejabberd_gen_mam_archive:mam_pm_gdpr_data().
get_mam_pm_gdpr_data(Acc, HostType, JID) ->
BinJID = jid:to_binary(jid:to_lower(JID)),
Expand All @@ -456,7 +454,7 @@ rows_to_gdpr_mam_message(HostType, #{message := Data, id:= Id, from_jid:=FromJid
[Row] when
PoolName :: mongoose_cassandra:pool_name(),
UserJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
IMax :: pos_integer(),
ReverseLimit :: boolean(),
Expand Down Expand Up @@ -489,7 +487,7 @@ fetch_user_messages(PoolName, UserJID, FilterMap) ->
when
PoolName :: mongoose_cassandra:pool_name(),
UserJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
MessID :: message_id(),
Count :: non_neg_integer().
Expand All @@ -504,7 +502,7 @@ calc_index(PoolName, UserJID, HostType, Filter, MessID) ->
when
PoolName :: mongoose_cassandra:pool_name(),
UserJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
MessID :: message_id(),
Count :: non_neg_integer().
Expand All @@ -518,7 +516,7 @@ calc_before(PoolName, UserJID, HostType, Filter, MessID) ->
when
PoolName :: mongoose_cassandra:pool_name(),
UserJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
Count :: non_neg_integer().
calc_count(PoolName, UserJID, _HostType, Filter) ->
Expand Down Expand Up @@ -672,7 +670,7 @@ filter_to_cql() ->
when
PoolName :: mongoose_cassandra:pool_name(),
UserJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
PageSize :: non_neg_integer(),
TotalCount :: non_neg_integer(),
Expand Down Expand Up @@ -757,10 +755,10 @@ stored_binary_to_packet(HostType, Bin) ->
%% ----------------------------------------------------------------------
%% Params getters

-spec db_message_format(HostType :: mongooseim:host_type()) -> module().
-spec db_message_format(HostType :: host_type()) -> module().
db_message_format(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, db_message_format, mam_message_xml).

-spec pool_name(HostType :: mongooseim:host_type()) -> term().
-spec pool_name(HostType :: host_type()) -> term().
pool_name(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, pool_name, default).
17 changes: 9 additions & 8 deletions src/mam/mod_mam_cassandra_prefs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
-include("jlib.hrl").
-include_lib("exml/include/exml.hrl").

-type host_type() :: mongooseim:host_type().

%% ----------------------------------------------------------------------
%% gen_mod callbacks
%% Starting and stopping functions for users' archives

-spec start(mongooseim:host_type(), _) -> ok.
-spec start(host_type(), _) -> ok.
start(HostType, _Opts) ->
ejabberd_hooks:add(hooks(HostType)).

-spec stop(mongooseim:host_type()) -> ok.
-spec stop(host_type()) -> ok.
stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)).

Expand Down Expand Up @@ -87,7 +88,7 @@ prepared_queries() ->
%% Internal functions and callbacks

-spec get_behaviour(Default :: mod_mam:archive_behaviour(),
HostType :: mongooseim:host_type(), ArchiveID :: mod_mam:archive_id(),
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),
Expand All @@ -108,7 +109,7 @@ get_behaviour(DefaultBehaviour, HostType, _UserID, LocJID, RemJID) ->
end.


-spec set_prefs(Result :: any(), HostType :: mongooseim:host_type(),
-spec set_prefs(Result :: any(), HostType :: host_type(),
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: jid:jid(),
DefaultMode :: mod_mam:archive_behaviour(),
AlwaysJIDs :: [jid:literal_jid()],
Expand Down Expand Up @@ -148,7 +149,7 @@ encode_row(BUserJID, BRemoteJID, Behaviour, Timestamp) ->
behaviour => Behaviour, '[timestamp]' => Timestamp}.


-spec get_prefs(mod_mam:preference(), _HostType :: mongooseim:host_type(),
-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) ->
Expand All @@ -159,7 +160,7 @@ get_prefs({GlobalDefaultMode, _, _}, HostType, _UserID, UserJID) ->
decode_prefs_rows(Rows, GlobalDefaultMode, [], []).


-spec remove_archive(mongoose_acc:t(), mongooseim:host_type(), mod_mam: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),
Expand All @@ -172,7 +173,7 @@ remove_archive(HostType, UserJID) ->
mongoose_cassandra:cql_write(pool_name(HostType), UserJID,
?MODULE, del_prefs_ts_query, [Params]).

-spec query_behaviour(mongooseim:host_type(), UserJID :: jid:jid(), BUserJID :: binary() | string(),
-spec query_behaviour(host_type(), UserJID :: jid:jid(), BUserJID :: binary() | string(),
BRemJID :: binary() | string(), BRemBareJID :: binary() | string()) -> any().
query_behaviour(HostType, UserJID, BUserJID, BRemJID, BRemBareJID)
when BRemJID == BRemBareJID ->
Expand Down Expand Up @@ -220,6 +221,6 @@ decode_prefs_rows([#{remote_jid := JID, behaviour := <<"N">>} | Rows],
%% ----------------------------------------------------------------------
%% Params getters

-spec pool_name(HostType :: mongooseim:host_type()) -> term().
-spec pool_name(HostType :: host_type()) -> term().
pool_name(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, pool_name, default).
25 changes: 12 additions & 13 deletions src/mam/mod_mam_muc_cassandra_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,17 @@

-type filter() :: #mam_muc_ca_filter{}.
-type message_id() :: non_neg_integer().
-type server_hostname() :: binary().

-type host_type() :: mongooseim:host_type().

%% ----------------------------------------------------------------------
%% gen_mod callbacks
%% Starting and stopping functions for users' archives

-spec start(mongooseim:host_type(), _) -> ok.
-spec start(host_type(), _) -> ok.
start(HostType, _Opts) ->
ejabberd_hooks:add(hooks(HostType)).

-spec stop(mongooseim:host_type()) -> ok.
-spec stop(host_type()) -> ok.
stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)).

Expand Down Expand Up @@ -214,7 +213,7 @@ remove_archive(Acc, HostType, _RoomID, RoomJID) ->
%% ----------------------------------------------------------------------
%% SELECT MESSAGES

-spec lookup_messages(Result :: any(), HostType :: mongooseim:host_type(), Params :: map()) ->
-spec lookup_messages(Result :: any(), HostType :: host_type(), Params :: map()) ->
{ok, mod_mam:lookup_result()}.
lookup_messages({error, _Reason} = Result, _HostType, _Params) ->
Result;
Expand Down Expand Up @@ -431,7 +430,7 @@ row_to_message_id(#{id := MsgID}) ->
MsgID.

-spec get_mam_muc_gdpr_data(ejabberd_gen_mam_archive:mam_muc_gdpr_data(),
mongooseim:host_type(), jid:jid()) ->
host_type(), jid:jid()) ->
ejabberd_gen_mam_archive:mam_muc_gdpr_data().
get_mam_muc_gdpr_data(Acc, HostType, Jid) ->
BinJid = jid:to_binary(jid:to_lower(Jid)),
Expand All @@ -450,7 +449,7 @@ get_mam_muc_gdpr_data(Acc, HostType, Jid) ->
[Row] when
PoolName :: mongoose_cassandra:pool_name(),
RoomJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
IMax :: pos_integer(),
ReverseLimit :: boolean(),
Expand Down Expand Up @@ -483,7 +482,7 @@ fetch_user_messages(PoolName, UserJID, FilterMap) ->
when
PoolName :: mongoose_cassandra:pool_name(),
RoomJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
MessID :: message_id(),
Count :: non_neg_integer().
Expand All @@ -498,7 +497,7 @@ calc_index(PoolName, RoomJID, HostType, Filter, MessID) ->
when
PoolName :: mongoose_cassandra:pool_name(),
RoomJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
MessID :: message_id(),
Count :: non_neg_integer().
Expand All @@ -512,7 +511,7 @@ calc_before(PoolName, RoomJID, HostType, Filter, MessID) ->
when
PoolName :: mongoose_cassandra:pool_name(),
RoomJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
Count :: non_neg_integer().
calc_count(PoolName, RoomJID, _HostType, Filter) ->
Expand Down Expand Up @@ -672,7 +671,7 @@ filter_to_cql() ->
when
PoolName :: mongoose_cassandra:pool_name(),
RoomJID :: jid:jid(),
HostType :: server_hostname(),
HostType :: host_type(),
Filter :: filter(),
PageSize :: non_neg_integer(),
TotalCount :: non_neg_integer(),
Expand Down Expand Up @@ -761,10 +760,10 @@ stored_binary_to_packet(HostType, Bin) ->
%% ----------------------------------------------------------------------
%% Params getters

-spec db_message_format(HostType :: mongooseim:host_type()) -> module().
-spec db_message_format(HostType :: host_type()) -> module().
db_message_format(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, db_message_format, mam_message_xml).

-spec pool_name(HostType :: mongooseim:host_type()) -> mongoose_wpool:pool_name().
-spec pool_name(HostType :: host_type()) -> mongoose_wpool:pool_name().
pool_name(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, pool_name, default).

0 comments on commit 01ba08c

Please sign in to comment.