From be63ea9a5779b5cb219aa7f02167568273a2e4c1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 9 Dec 2016 15:15:10 +0100 Subject: core.rostermanager: Add method for checking if the user is subscribed to a contact --- core/rostermanager.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/rostermanager.lua') diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 5e06e3f7..a846fea6 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -210,6 +210,18 @@ function is_contact_subscribed(username, host, jid) 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); -- cgit v1.2.3