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 84b267f commit c09b867
Show file tree
Hide file tree
Showing 3 changed files with 26 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
24 changes: 22 additions & 2 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 @@ -109,7 +110,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 @@ -1044,6 +1046,14 @@ 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) ->
{ok, RetractionInfo1} = gen_hook:run_fold(mam_retraction, HostType, RetractionInfo, Env),
RetractionInfo1.

%% MAM MUC related hooks

Expand Down Expand Up @@ -1165,6 +1175,16 @@ 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) ->
{ok, RetractionInfo1} = gen_hook:run_fold(mam_muc_retraction, HostType, RetractionInfo, Env),
RetractionInfo1.


%% GDPR related hooks

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

0 comments on commit c09b867

Please sign in to comment.