diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-11-22 19:25:20 +0100 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-11-22 19:25:20 +0100 |
commit | 114ca786ee051b68c6ddc88b012af2226b07601e (patch) | |
tree | a2ceeeedfbf2705f7ab78384d0a682a23c037741 /src/mod_carboncopy.erl | |
parent | Fix xref issue injected by fbfbb96 (diff) |
Let ejabberd_sm mark copied messages
When multiple resources have the same (highest) priority, ejabberd_sm
dispatches messages addressed to the bare JID (or to an unavailable
resource) to each of these resources. Such messages are now marked with
an 'sm_copy' flag for all but one of the resources. This makes it
easier for other modules to identify those duplicates.
Resolves #1356.
Diffstat (limited to 'src/mod_carboncopy.erl')
-rw-r--r-- | src/mod_carboncopy.erl | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 1c8ca1fdc..f1eb3e790 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -153,7 +153,7 @@ send_copies(JID, To, Packet, Direction)-> {U, S, R} = jid:tolower(JID), PrioRes = ejabberd_sm:get_user_present_resources(U, S), {_, AvailRs} = lists:unzip(PrioRes), - {MaxPrio, MaxRes} = case catch lists:max(PrioRes) of + {MaxPrio, _MaxRes} = case catch lists:max(PrioRes) of {Prio, Res} -> {Prio, Res}; _ -> {0, undefined} end, @@ -166,19 +166,19 @@ send_copies(JID, To, Packet, Direction)-> end, %% list of JIDs that should receive a carbon copy of this message (excluding the %% receiver(s) of the original message - TargetJIDs = case {IsBareTo, R} of - {true, MaxRes} -> - OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end, - [ {jid:make({U, S, CCRes}), CC_Version} - || {CCRes, CC_Version} <- list(U, S), - lists:member(CCRes, AvailRs), not OrigTo(CCRes) ]; - {true, _} -> + TargetJIDs = case {IsBareTo, Packet} of + {true, #message{meta = #{sm_copy := true}}} -> %% The message was sent to our bare JID, and we currently have %% multiple resources with the same highest priority, so the session %% manager routes the message to each of them. We create carbon - %% copies only from one of those resources (the one where R equals - %% MaxRes) in order to avoid duplicates. + %% copies only from one of those resources in order to avoid + %% duplicates. []; + {true, _} -> + OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end, + [ {jid:make({U, S, CCRes}), CC_Version} + || {CCRes, CC_Version} <- list(U, S), + lists:member(CCRes, AvailRs), not OrigTo(CCRes) ]; {false, _} -> [ {jid:make({U, S, CCRes}), CC_Version} || {CCRes, CC_Version} <- list(U, S), |