mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
Check availability before carbon copying
Before generating a carbon copy for a resource, make sure it's actually available. This handles the case where, for some reason, the 'unset_presence_hook' wasn't called during logout of a resource. Carbon copies sent to that resource would otherwise be re-routed to another resource (which might've received a copy of that message already).
This commit is contained in:
parent
9f822dd2b8
commit
bc7f93ad1e
@ -165,6 +165,7 @@ remove_connection(User, Server, Resource, _Status)->
|
||||
send_copies(JID, To, Packet, Direction)->
|
||||
{U, S, R} = jlib:jid_tolower(JID),
|
||||
PrioRes = ejabberd_sm:get_user_present_resources(U, S),
|
||||
{_, AvailRs} = lists:unzip(PrioRes),
|
||||
{MaxPrio, MaxRes} = case catch lists:max(PrioRes) of
|
||||
{Prio, Res} -> {Prio, Res};
|
||||
_ -> {0, undefined}
|
||||
@ -186,7 +187,8 @@ send_copies(JID, To, Packet, Direction)->
|
||||
{true, MaxRes} ->
|
||||
OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end,
|
||||
[ {jlib:make_jid({U, S, CCRes}), CC_Version}
|
||||
|| {CCRes, CC_Version} <- list(U, S), not OrigTo(CCRes) ];
|
||||
|| {CCRes, CC_Version} <- list(U, S),
|
||||
lists:member(CCRes, AvailRs), not OrigTo(CCRes) ];
|
||||
{true, _} ->
|
||||
%% The message was sent to our bare JID, and we currently have
|
||||
%% multiple resources with the same highest priority, so the session
|
||||
@ -196,7 +198,8 @@ send_copies(JID, To, Packet, Direction)->
|
||||
[];
|
||||
{false, _} ->
|
||||
[ {jlib:make_jid({U, S, CCRes}), CC_Version}
|
||||
|| {CCRes, CC_Version} <- list(U, S), CCRes /= R ]
|
||||
|| {CCRes, CC_Version} <- list(U, S),
|
||||
lists:member(CCRes, AvailRs), CCRes /= R ]
|
||||
%TargetJIDs = lists:delete(JID, [ jlib:make_jid({U, S, CCRes}) || CCRes <- list(U, S) ]),
|
||||
end,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user