Software /
code /
prosody
Changeset
7777:65836cf2d057
core.rostermanager: Add method for checking if the user is subscribed to a contact
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 09 Dec 2016 15:15:10 +0100 |
parents | 7769:2a7b52437167 |
children | 7778:62e7d6a73c72 |
files | core/rostermanager.lua |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/rostermanager.lua Mon Nov 28 14:27:59 2016 +0100 +++ b/core/rostermanager.lua Fri Dec 09 15:15:10 2016 +0100 @@ -210,6 +210,18 @@ local item = roster[jid]; return item and (item.subscription == "from" or item.subscription == "both"), err; end +function is_user_subscribed(username, host, jid) + do + local selfjid = username.."@"..host; + local user_subscription = _get_online_roster_subscription(selfjid, jid); + if user_subscription then return (user_subscription == "both" or user_subscription == "to"); end + local contact_subscription = _get_online_roster_subscription(jid, selfjid); + if contact_subscription then return (contact_subscription == "both" or contact_subscription == "from"); end + end + local roster, err = load_roster(username, host); + local item = roster[jid]; + return item and (item.subscription == "to" or item.subscription == "both"), err; +end function is_contact_pending_in(username, host, jid) local roster = load_roster(username, host);