From 54c8ae4d2b6d333a2495ac65d5c192a7774611c5 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 10 Nov 2017 18:09:33 +0100 Subject: [PATCH] mod_mam: Make sure archived message isn't bounced If mod_offline is disabled but a message is archived by mod_mam, no error bounce should be generated. This functionality got lost when mod_mam stopped using the 'offline_message_hook'. --- src/mod_mam.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index 834b6bb5e..92e905b6e 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -38,7 +38,7 @@ remove_user/2, remove_room/3, mod_opt_type/1, muc_process_iq/2, muc_filter_message/3, message_is_archived/3, delete_old_messages/2, get_commands_spec/0, msg_to_el/4, get_room_config/4, set_room_option/3, - export/1]). + offline_message/1, export/1]). -include("xmpp.hrl"). -include("logger.hrl"). @@ -84,6 +84,8 @@ start(Host, Opts) -> user_send_packet, 88), ejabberd_hooks:add(user_send_packet, Host, ?MODULE, user_send_packet_strip_tag, 500), + ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, + offline_message, 50), ejabberd_hooks:add(muc_filter_message, Host, ?MODULE, muc_filter_message, 50), ejabberd_hooks:add(muc_process_iq, Host, ?MODULE, @@ -145,6 +147,8 @@ stop(Host) -> user_send_packet, 88), ejabberd_hooks:delete(user_send_packet, Host, ?MODULE, user_send_packet_strip_tag, 500), + ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE, + offline_message, 50), ejabberd_hooks:delete(muc_filter_message, Host, ?MODULE, muc_filter_message, 50), ejabberd_hooks:delete(muc_process_iq, Host, ?MODULE, @@ -313,6 +317,12 @@ user_send_packet_strip_tag({#message{} = Pkt, #{jid := JID} = C2SState}) -> user_send_packet_strip_tag(Acc) -> Acc. +-spec offline_message({any(), message()}) -> {any(), message()}. +offline_message({_Action, #message{meta = #{mam_archived := true}} = Pkt}) -> + {archived, Pkt}; +offline_message(Acc) -> + Acc. + -spec muc_filter_message(message(), mod_muc_room:state(), binary()) -> message(). muc_filter_message(#message{from = From} = Pkt,