diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2018-06-28 10:37:20 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2018-06-28 10:37:20 +0300 |
commit | 8879d1d533cdea83efebad54b37e22f849092ac1 (patch) | |
tree | e532bfbca6e70d5e8e734523ac108de9859096d0 /src/mod_block_strangers.erl | |
parent | Work-around against public_key incompatibility introduced in OTP21 (diff) |
Avoid code duplication when checking presence subscription
Diffstat (limited to 'src/mod_block_strangers.erl')
-rw-r--r-- | src/mod_block_strangers.erl | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/mod_block_strangers.erl b/src/mod_block_strangers.erl index fbbef1899..6e9d1097a 100644 --- a/src/mod_block_strangers.erl +++ b/src/mod_block_strangers.erl @@ -208,29 +208,19 @@ need_check(Pkt) -> -spec check_subscription(jid(), jid()) -> boolean(). check_subscription(From, To) -> - {LocalUser, LocalServer, _} = jid:tolower(To), + LocalServer = To#jid.lserver, {RemoteUser, RemoteServer, _} = jid:tolower(From), - case has_subscription(LocalUser, LocalServer, From) of + case mod_roster:is_subscribed(From, To) of false when RemoteUser == <<"">> -> false; false -> %% Check if the contact's server is in the roster gen_mod:get_module_opt(LocalServer, ?MODULE, allow_transports) - andalso has_subscription(LocalUser, LocalServer, - jid:make(RemoteServer)); + andalso mod_roster:is_subscribed(jid:make(RemoteServer), To); true -> true end. --spec has_subscription(binary(), binary(), jid()) -> boolean(). -has_subscription(User, Server, JID) -> - {Sub, Ask, _} = ejabberd_hooks:run_fold( - roster_get_jid_info, Server, - {none, none, []}, - [User, Server, JID]), - (Sub /= none) orelse (Ask == subscribe) - orelse (Ask == out) orelse (Ask == both). - sets_bare_member({U, S, <<"">>} = LBJID, Set) -> case ?SETS:next(sets_iterator_from(LBJID, Set)) of {{U, S, _}, _} -> true; |