mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
mod_mam: Make sure a stanza ID is always added
Let mod_mam store incoming messages from a new hook in ejabberd_sm. This makes sure all messages are tagged with a stanza ID, including those that are forked to multiple resources in ejabberd_sm. Closes #1344.
This commit is contained in:
parent
902c6d476b
commit
5cf4e200ba
@ -137,10 +137,17 @@ route(To, Term) ->
|
|||||||
|
|
||||||
-spec route(stanza()) -> ok.
|
-spec route(stanza()) -> ok.
|
||||||
route(Packet) ->
|
route(Packet) ->
|
||||||
try do_route(Packet), ok
|
#jid{lserver = LServer} = xmpp:get_to(Packet),
|
||||||
catch E:R ->
|
case ejabberd_hooks:run_fold(sm_receive_packet, LServer, Packet, []) of
|
||||||
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
drop ->
|
||||||
[xmpp:pp(Packet), {E, {R, erlang:get_stacktrace()}}])
|
?DEBUG("hook dropped stanza:~n~s", [xmpp:pp(Packet)]);
|
||||||
|
Packet1 ->
|
||||||
|
try do_route(Packet1), ok
|
||||||
|
catch E:R ->
|
||||||
|
?ERROR_MSG("failed to route packet:~n~s~nReason = ~p",
|
||||||
|
[xmpp:pp(Packet1),
|
||||||
|
{E, {R, erlang:get_stacktrace()}}])
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec open_session(sid(), binary(), binary(), binary(), prio(), info()) -> ok.
|
-spec open_session(sid(), binary(), binary(), binary(), prio(), info()) -> ok.
|
||||||
|
@ -32,12 +32,12 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([start/2, stop/1, reload/3, depends/2]).
|
-export([start/2, stop/1, reload/3, depends/2]).
|
||||||
|
|
||||||
-export([user_send_packet/1, user_send_packet_strip_tag/1, user_receive_packet/1,
|
-export([user_send_packet/1, user_send_packet_strip_tag/1, sm_receive_packet/1,
|
||||||
process_iq_v0_2/1, process_iq_v0_3/1, disco_sm_features/5,
|
process_iq_v0_2/1, process_iq_v0_3/1, disco_sm_features/5,
|
||||||
remove_user/2, remove_room/3, mod_opt_type/1, muc_process_iq/2,
|
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,
|
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,
|
get_commands_spec/0, msg_to_el/4, get_room_config/4, set_room_option/3,
|
||||||
offline_message/1, export/1]).
|
export/1]).
|
||||||
|
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -77,14 +77,12 @@ start(Host, Opts) ->
|
|||||||
Mod:init(Host, Opts),
|
Mod:init(Host, Opts),
|
||||||
init_cache(Host, Opts),
|
init_cache(Host, Opts),
|
||||||
register_iq_handlers(Host, IQDisc),
|
register_iq_handlers(Host, IQDisc),
|
||||||
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE,
|
ejabberd_hooks:add(sm_receive_packet, Host, ?MODULE,
|
||||||
user_receive_packet, 88),
|
sm_receive_packet, 50),
|
||||||
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
||||||
user_send_packet, 88),
|
user_send_packet, 88),
|
||||||
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
|
||||||
user_send_packet_strip_tag, 500),
|
user_send_packet_strip_tag, 500),
|
||||||
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
|
|
||||||
offline_message, 40),
|
|
||||||
ejabberd_hooks:add(muc_filter_message, Host, ?MODULE,
|
ejabberd_hooks:add(muc_filter_message, Host, ?MODULE,
|
||||||
muc_filter_message, 50),
|
muc_filter_message, 50),
|
||||||
ejabberd_hooks:add(muc_process_iq, Host, ?MODULE,
|
ejabberd_hooks:add(muc_process_iq, Host, ?MODULE,
|
||||||
@ -140,14 +138,12 @@ cache_opts(Host, Opts) ->
|
|||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
unregister_iq_handlers(Host),
|
unregister_iq_handlers(Host),
|
||||||
|
ejabberd_hooks:delete(sm_receive_packet, Host, ?MODULE,
|
||||||
|
sm_receive_packet, 50),
|
||||||
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
||||||
user_send_packet, 88),
|
user_send_packet, 88),
|
||||||
ejabberd_hooks:delete(user_receive_packet, Host, ?MODULE,
|
|
||||||
user_receive_packet, 88),
|
|
||||||
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
|
||||||
user_send_packet_strip_tag, 500),
|
user_send_packet_strip_tag, 500),
|
||||||
ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE,
|
|
||||||
offline_message, 40),
|
|
||||||
ejabberd_hooks:delete(muc_filter_message, Host, ?MODULE,
|
ejabberd_hooks:delete(muc_filter_message, Host, ?MODULE,
|
||||||
muc_filter_message, 50),
|
muc_filter_message, 50),
|
||||||
ejabberd_hooks:delete(muc_process_iq, Host, ?MODULE,
|
ejabberd_hooks:delete(muc_process_iq, Host, ?MODULE,
|
||||||
@ -265,12 +261,11 @@ set_room_option(_Acc, {mam, Val}, _Lang) ->
|
|||||||
set_room_option(Acc, _Property, _Lang) ->
|
set_room_option(Acc, _Property, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
-spec user_receive_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()}.
|
-spec sm_receive_packet(stanza()) -> stanza().
|
||||||
user_receive_packet({Pkt, #{jid := JID} = C2SState}) ->
|
sm_receive_packet(#message{from = Peer, to = JID} = Pkt) ->
|
||||||
Peer = xmpp:get_from(Pkt),
|
|
||||||
LUser = JID#jid.luser,
|
LUser = JID#jid.luser,
|
||||||
LServer = JID#jid.lserver,
|
LServer = JID#jid.lserver,
|
||||||
Pkt2 = case should_archive(Pkt, LServer) of
|
case should_archive(Pkt, LServer) of
|
||||||
true ->
|
true ->
|
||||||
Pkt1 = strip_my_archived_tag(Pkt, LServer),
|
Pkt1 = strip_my_archived_tag(Pkt, LServer),
|
||||||
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
||||||
@ -281,8 +276,9 @@ user_receive_packet({Pkt, #{jid := JID} = C2SState}) ->
|
|||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
Pkt
|
Pkt
|
||||||
end,
|
end;
|
||||||
{Pkt2, C2SState}.
|
sm_receive_packet(Acc) ->
|
||||||
|
Acc.
|
||||||
|
|
||||||
-spec user_send_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()}.
|
-spec user_send_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()}.
|
||||||
user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
|
user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
|
||||||
@ -304,23 +300,6 @@ user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
|
|||||||
end,
|
end,
|
||||||
{Pkt2, C2SState}.
|
{Pkt2, C2SState}.
|
||||||
|
|
||||||
-spec offline_message({any(), message()}) -> {any(), message()}.
|
|
||||||
offline_message({_Action, #message{from = Peer, to = To} = Pkt} = Acc) ->
|
|
||||||
LUser = To#jid.luser,
|
|
||||||
LServer = To#jid.lserver,
|
|
||||||
case should_archive(Pkt, LServer) of
|
|
||||||
true ->
|
|
||||||
Pkt1 = strip_my_archived_tag(Pkt, LServer),
|
|
||||||
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
|
||||||
{ok, ID} ->
|
|
||||||
{archived, set_stanza_id(Pkt1, To, ID)};
|
|
||||||
_ ->
|
|
||||||
Acc
|
|
||||||
end;
|
|
||||||
false ->
|
|
||||||
Acc
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec user_send_packet_strip_tag({stanza(), c2s_state()}) ->
|
-spec user_send_packet_strip_tag({stanza(), c2s_state()}) ->
|
||||||
{stanza(), c2s_state()}.
|
{stanza(), c2s_state()}.
|
||||||
user_send_packet_strip_tag({Pkt, #{jid := JID} = C2SState}) ->
|
user_send_packet_strip_tag({Pkt, #{jid := JID} = C2SState}) ->
|
||||||
@ -547,8 +526,6 @@ process_iq(LServer, #iq{from = #jid{luser = LUser}, lang = Lang,
|
|||||||
|
|
||||||
should_archive(#message{type = error}, _LServer) ->
|
should_archive(#message{type = error}, _LServer) ->
|
||||||
false;
|
false;
|
||||||
should_archive(#message{meta = #{sm_copy := true}}, _LServer) ->
|
|
||||||
false;
|
|
||||||
should_archive(#message{meta = #{from_offline := true}}, _LServer) ->
|
should_archive(#message{meta = #{from_offline := true}}, _LServer) ->
|
||||||
false;
|
false;
|
||||||
should_archive(#message{body = Body, subject = Subject,
|
should_archive(#message{body = Body, subject = Subject,
|
||||||
|
Loading…
Reference in New Issue
Block a user