mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Skip reading roster in one more case in mod_caps
This commit is contained in:
parent
72ecf91f08
commit
14d87cb5e9
@ -227,46 +227,51 @@ disco_info(Acc, _, _, _Node, _Lang) ->
|
||||
c2s_presence_in(C2SState,
|
||||
#presence{from = From, to = To, type = Type} = Presence) ->
|
||||
ToSelf = (From#jid.luser == To#jid.luser)
|
||||
and (From#jid.lserver == To#jid.lserver),
|
||||
{Insert, Delete} =
|
||||
case {Type, ToSelf} of
|
||||
{unavailable, _} -> {false, true};
|
||||
{error, _} -> {false, true};
|
||||
{available, true} -> {true, false};
|
||||
{available, _} ->
|
||||
andalso (From#jid.lserver == To#jid.lserver),
|
||||
Caps = read_caps(Presence),
|
||||
Operation =
|
||||
case {Type, ToSelf, Caps} of
|
||||
{unavailable, _, _} -> delete;
|
||||
{error, _, _} -> delete;
|
||||
{available, _, nothing} -> skip;
|
||||
{available, true, _} -> insert;
|
||||
{available, _, _} ->
|
||||
{Subscription, _, _} = ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, To#jid.lserver,
|
||||
{none, none, []},
|
||||
[To#jid.luser, To#jid.lserver, From]),
|
||||
{Subscription == both orelse Subscription == from, false};
|
||||
case Subscription of
|
||||
from -> insert;
|
||||
both -> insert;
|
||||
_ -> skip
|
||||
end;
|
||||
_ ->
|
||||
{false, false}
|
||||
skip
|
||||
end,
|
||||
if Insert or Delete ->
|
||||
LFrom = jid:tolower(From),
|
||||
Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
|
||||
Caps = read_caps(Presence),
|
||||
NewRs = case Caps of
|
||||
nothing when Insert == true -> Rs;
|
||||
_ when Insert == true ->
|
||||
case gb_trees:lookup(LFrom, Rs) of
|
||||
{value, Caps} -> Rs;
|
||||
none ->
|
||||
ejabberd_hooks:run(caps_add, To#jid.lserver,
|
||||
[From, To,
|
||||
get_features(To#jid.lserver, Caps)]),
|
||||
gb_trees:insert(LFrom, Caps, Rs);
|
||||
_ ->
|
||||
ejabberd_hooks:run(caps_update, To#jid.lserver,
|
||||
[From, To,
|
||||
get_features(To#jid.lserver, Caps)]),
|
||||
gb_trees:update(LFrom, Caps, Rs)
|
||||
end;
|
||||
_ -> gb_trees:delete_any(LFrom, Rs)
|
||||
end,
|
||||
C2SState#{caps_resources => NewRs};
|
||||
true ->
|
||||
C2SState
|
||||
case Operation of
|
||||
skip ->
|
||||
C2SState;
|
||||
delete ->
|
||||
LFrom = jid:tolower(From),
|
||||
Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
|
||||
C2SState#{caps_resources => gb_trees:delete_any(LFrom, Rs)};
|
||||
insert ->
|
||||
LFrom = jid:tolower(From),
|
||||
Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
|
||||
NewRs = case gb_trees:lookup(LFrom, Rs) of
|
||||
{value, Caps} -> Rs;
|
||||
none ->
|
||||
ejabberd_hooks:run(caps_add, To#jid.lserver,
|
||||
[From, To,
|
||||
get_features(To#jid.lserver, Caps)]),
|
||||
gb_trees:insert(LFrom, Caps, Rs);
|
||||
_ ->
|
||||
ejabberd_hooks:run(caps_update, To#jid.lserver,
|
||||
[From, To,
|
||||
get_features(To#jid.lserver, Caps)]),
|
||||
gb_trees:update(LFrom, Caps, Rs)
|
||||
end,
|
||||
C2SState#{caps_resources => NewRs}
|
||||
end.
|
||||
|
||||
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
|
||||
|
Loading…
Reference in New Issue
Block a user