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,29 +227,38 @@ 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
skip ->
C2SState;
delete ->
LFrom = jid:tolower(From), LFrom = jid:tolower(From),
Rs = maps:get(caps_resources, C2SState, gb_trees:empty()), Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
Caps = read_caps(Presence), C2SState#{caps_resources => gb_trees:delete_any(LFrom, Rs)};
NewRs = case Caps of insert ->
nothing when Insert == true -> Rs; LFrom = jid:tolower(From),
_ when Insert == true -> Rs = maps:get(caps_resources, C2SState, gb_trees:empty()),
case gb_trees:lookup(LFrom, Rs) of NewRs = case gb_trees:lookup(LFrom, Rs) of
{value, Caps} -> Rs; {value, Caps} -> Rs;
none -> none ->
ejabberd_hooks:run(caps_add, To#jid.lserver, ejabberd_hooks:run(caps_add, To#jid.lserver,
@ -261,12 +270,8 @@ c2s_presence_in(C2SState,
[From, To, [From, To,
get_features(To#jid.lserver, Caps)]), get_features(To#jid.lserver, Caps)]),
gb_trees:update(LFrom, Caps, Rs) gb_trees:update(LFrom, Caps, Rs)
end;
_ -> gb_trees:delete_any(LFrom, Rs)
end, end,
C2SState#{caps_resources => NewRs}; C2SState#{caps_resources => NewRs}
true ->
C2SState
end. end.
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}]. -spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].