From dffcfe74d4f3ecbdc6c0e0f082b1f278e8851a79 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 10 Oct 2016 00:17:17 +0200 Subject: [PATCH] Don't let "send_message" duplicate the message In the past, the "send_message" command sent a copy of the message to each resource if the message was addressed to the bare JID of a local online user. When message carbons are enabled, this creates duplicates; and with MAM enabled, each copy is archived. Therefore, "send_message" no longer creates copies of the message. --- src/mod_admin_extra.erl | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl index 2bb436f31..8ce11b872 100644 --- a/src/mod_admin_extra.erl +++ b/src/mod_admin_extra.erl @@ -1357,44 +1357,9 @@ srg_user_del(User, Host, Group, GroupHost) -> %% @doc Send a message to a Jabber account. %% @spec (Type::binary(), From::binary(), To::binary(), Subject::binary(), Body::binary()) -> ok send_message(Type, From, To, Subject, Body) -> + FromJID = jid:from_string(From), + ToJID = jid:from_string(To), Packet = build_packet(Type, Subject, Body), - send_packet_all_resources(From, To, Packet). - -%% @doc Send a packet to a Jabber account. -%% If a resource was specified in the JID, -%% the packet is sent only to that specific resource. -%% If no resource was specified in the JID, -%% and the user is remote or local but offline, -%% the packet is sent to the bare JID. -%% If the user is local and is online in several resources, -%% the packet is sent to all its resources. -send_packet_all_resources(FromJIDString, ToJIDString, Packet) -> - FromJID = jid:from_string(FromJIDString), - ToJID = jid:from_string(ToJIDString), - ToUser = ToJID#jid.user, - ToServer = ToJID#jid.server, - case ToJID#jid.resource of - <<>> -> - send_packet_all_resources(FromJID, ToUser, ToServer, Packet); - Res -> - send_packet_all_resources(FromJID, ToUser, ToServer, Res, Packet) - end. - -send_packet_all_resources(FromJID, ToUser, ToServer, Packet) -> - case ejabberd_sm:get_user_resources(ToUser, ToServer) of - [] -> - send_packet_all_resources(FromJID, ToUser, ToServer, <<>>, Packet); - ToResources -> - lists:foreach( - fun(ToResource) -> - send_packet_all_resources(FromJID, ToUser, ToServer, - ToResource, Packet) - end, - ToResources) - end. - -send_packet_all_resources(FromJID, ToU, ToS, ToR, Packet) -> - ToJID = jid:make(ToU, ToS, ToR), ejabberd_router:route(FromJID, ToJID, Packet). build_packet(Type, Subject, Body) -> -- 2.40.0