25
1
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:
Paweł Chmielowski 2021-02-16 13:39:34 +01:00
parent 72ecf91f08
commit 14d87cb5e9

View File

@ -227,46 +227,51 @@ disco_info(Acc, _, _, _Node, _Lang) ->
c2s_presence_in(C2SState, c2s_presence_in(C2SState,
#presence{from = From, to = To, type = Type} = Presence) -> #presence{from = From, to = To, type = Type} = Presence) ->
ToSelf = (From#jid.luser == To#jid.luser) ToSelf = (From#jid.luser == To#jid.luser)
and (From#jid.lserver == To#jid.lserver), andalso (From#jid.lserver == To#jid.lserver),
{Insert, Delete} = Caps = read_caps(Presence),
case {Type, ToSelf} of Operation =
{unavailable, _} -> {false, true}; case {Type, ToSelf, Caps} of
{error, _} -> {false, true}; {unavailable, _, _} -> delete;
{available, true} -> {true, false}; {error, _, _} -> delete;
{available, _} -> {available, _, nothing} -> skip;
{available, true, _} -> insert;
{available, _, _} ->
{Subscription, _, _} = ejabberd_hooks:run_fold( {Subscription, _, _} = ejabberd_hooks:run_fold(
roster_get_jid_info, To#jid.lserver, roster_get_jid_info, To#jid.lserver,
{none, none, []}, {none, none, []},
[To#jid.luser, To#jid.lserver, From]), [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, end,
if Insert or Delete -> case Operation of
LFrom = jid:tolower(From), skip ->
Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), C2SState;
Caps = read_caps(Presence), delete ->
NewRs = case Caps of LFrom = jid:tolower(From),
nothing when Insert == true -> Rs; Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
_ when Insert == true -> C2SState#{caps_resources => gb_trees:delete_any(LFrom, Rs)};
case gb_trees:lookup(LFrom, Rs) of insert ->
{value, Caps} -> Rs; LFrom = jid:tolower(From),
none -> Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
ejabberd_hooks:run(caps_add, To#jid.lserver, NewRs = case gb_trees:lookup(LFrom, Rs) of
[From, To, {value, Caps} -> Rs;
get_features(To#jid.lserver, Caps)]), none ->
gb_trees:insert(LFrom, Caps, Rs); ejabberd_hooks:run(caps_add, To#jid.lserver,
_ -> [From, To,
ejabberd_hooks:run(caps_update, To#jid.lserver, get_features(To#jid.lserver, Caps)]),
[From, To, gb_trees:insert(LFrom, Caps, Rs);
get_features(To#jid.lserver, Caps)]), _ ->
gb_trees:update(LFrom, Caps, Rs) ejabberd_hooks:run(caps_update, To#jid.lserver,
end; [From, To,
_ -> gb_trees:delete_any(LFrom, Rs) get_features(To#jid.lserver, Caps)]),
end, gb_trees:update(LFrom, Caps, Rs)
C2SState#{caps_resources => NewRs}; end,
true -> C2SState#{caps_resources => NewRs}
C2SState
end. end.
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}]. -spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].