Skip to content

Commit

Permalink
Create hooks for mam_retractions
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 12, 2022
1 parent 926d995 commit e762c53
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/mam/mod_mam_muc_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ make_tombstone(_HostType, ArcID, RetractionId, skip, _Env) ->
make_tombstone(HostType, ArcID, _RetractionId,
RetractionInfo = #{message_id := MessID},
#{archive_jid := ArcJID} = Env) ->
Tombstone = mod_mam_utils:tombstone(RetractionInfo, ArcJID),
RetractionInfo1 = mongoose_hooks:mam_muc_retraction(HostType, RetractionInfo, Env),
Tombstone = mod_mam_utils:tombstone(RetractionInfo1, ArcJID),
TombstoneData = mam_encoder:encode_packet(Tombstone, Env),
execute_make_tombstone(HostType, TombstoneData, ArcID, MessID).

Expand Down
3 changes: 2 additions & 1 deletion src/mam/mod_mam_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ make_tombstone(_HostType, ArcID, RetractionId, skip, _Env) ->
make_tombstone(HostType, ArcID, _RetractionId,
RetractionInfo = #{message_id := MessID},
#{archive_jid := ArcJID} = Env) ->
Tombstone = mod_mam_utils:tombstone(RetractionInfo, ArcJID),
RetractionInfo1 = mongoose_hooks:mam_retraction(HostType, RetractionInfo, Env),
Tombstone = mod_mam_utils:tombstone(RetractionInfo1, ArcJID),
TombstoneData = mam_encoder:encode_packet(Tombstone, Env),
execute_make_tombstone(HostType, TombstoneData, ArcID, MessID).

Expand Down
34 changes: 32 additions & 2 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
mam_lookup_messages/2,
mam_archive_message/2,
mam_flush_messages/2,
mam_archive_sync/1]).
mam_archive_sync/1,
mam_retraction/3]).

-export([mam_muc_archive_id/2,
mam_muc_archive_size/3,
Expand All @@ -107,7 +108,8 @@
mam_muc_lookup_messages/2,
mam_muc_archive_message/2,
mam_muc_flush_messages/2,
mam_muc_archive_sync/1]).
mam_muc_archive_sync/1,
mam_muc_retraction/3]).

-export([get_mam_pm_gdpr_data/2,
get_mam_muc_gdpr_data/2,
Expand Down Expand Up @@ -1025,6 +1027,19 @@ mam_flush_messages(HookServer, MessageCount) ->
mam_archive_sync(HostType) ->
run_hook_for_host_type(mam_archive_sync, HostType, ok, [HostType]).

%% @doc Notifies of a message retraction
-spec mam_retraction(mongooseim:host_type(),
mod_mam_utils:retraction_info(),
mod_mam_rdbms_arch:env_vars()) ->
mod_mam_utils:retraction_info().
mam_retraction(HostType, RetractionInfo, Env) ->
case gen_hook:run_fold(mam_retraction, HostType, RetractionInfo, Env) of
{ok, RetractionInfo1} ->
RetractionInfo1;
{error, Reason} ->
?LOG_ERROR(#{what => mam_retraction_hook_failed, reason => Reason}),
RetractionInfo
end.

%% MAM MUC related hooks

Expand Down Expand Up @@ -1146,6 +1161,21 @@ mam_muc_flush_messages(HookServer, MessageCount) ->
mam_muc_archive_sync(HostType) ->
run_hook_for_host_type(mam_muc_archive_sync, HostType, ok, [HostType]).

%% @doc Notifies of a muc message retraction
-spec mam_muc_retraction(mongooseim:host_type(),
mod_mam_utils:retraction_info(),
mod_mam_rdbms_arch:env_vars()) ->
mod_mam_utils:retraction_info().
mam_muc_retraction(HostType, RetractionInfo, Env) ->
case gen_hook:run_fold(mam_muc_retraction, HostType, RetractionInfo, Env) of
{ok, RetractionInfo1} ->
RetractionInfo1;
{error, Reason} ->
?LOG_ERROR(#{what => mam_retraction_hook_failed, reason => Reason}),
RetractionInfo
end.


%% GDPR related hooks

%%% @doc `get_mam_pm_gdpr_data' hook is called to provide
Expand Down

0 comments on commit e762c53

Please sign in to comment.