]> granicus.if.org Git - ejabberd/commitdiff
Don't let "send_message" duplicate the message
authorHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 9 Oct 2016 22:17:17 +0000 (00:17 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 9 Oct 2016 22:17:17 +0000 (00:17 +0200)
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

index 2bb436f31f4ec4a44fa22fe97875ac664a5534ff..8ce11b8722db122d6793a630eca887b27f513629 100644 (file)
@@ -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) ->