aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2019-12-19 10:03:16 +0000
committerMatthew Wild <mwild1@gmail.com>2019-12-19 10:03:16 +0000
commit173990157fad6d4507e8ce2dc214e7bf35a17822 (patch)
tree1d7cba4384d9413b605b7e06c729b3fb44dfa1fa /core
parentad26a3b047ab0ae2efa0d61553e32f77da2ccac4 (diff)
downloadprosody-173990157fad6d4507e8ce2dc214e7bf35a17822.tar.gz
prosody-173990157fad6d4507e8ce2dc214e7bf35a17822.zip
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Diffstat (limited to 'core')
-rw-r--r--core/rostermanager.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index d551a1b1..7b104339 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -301,6 +301,11 @@ function is_contact_pending_out(username, host, jid)
local item = roster[jid];
return item and item.ask;
end
+local function is_contact_preapproved(username, host, jid)
+ local roster = load_roster(username, host);
+ local item = roster[jid];
+ return item and (item.approved == "true");
+end
local function set_contact_pending_out(username, host, jid) -- subscribe
local roster = load_roster(username, host);
local item = roster[jid];
@@ -331,9 +336,10 @@ local function unsubscribe(username, host, jid)
return save_roster(username, host, roster, jid);
end
local function subscribed(username, host, jid)
+ local roster = load_roster(username, host);
+ local item = roster[jid];
+
if is_contact_pending_in(username, host, jid) then
- local roster = load_roster(username, host);
- local item = roster[jid];
if not item then -- FIXME should roster item be auto-created?
item = {subscription = "none", groups = {}};
roster[jid] = item;
@@ -345,7 +351,17 @@ local function subscribed(username, host, jid)
end
roster[false].pending[jid] = nil;
return save_roster(username, host, roster, jid);
- end -- TODO else implement optional feature pre-approval (ask = subscribed)
+ elseif not item or item.subscription == "none" or item.subscription == "to" then
+ -- Contact is not subscribed and has not sent a subscription request.
+ -- We store a pre-approval as per RFC6121 3.4
+ if not item then
+ item = {subscription = "none", groups = {}};
+ roster[jid] = item;
+ end
+ item.approved = "true";
+ log("debug", "Storing preapproval for %s", jid);
+ return save_roster(username, host, roster, jid);
+ end
end
local function unsubscribed(username, host, jid)
local roster = load_roster(username, host);
@@ -403,6 +419,7 @@ return {
set_contact_pending_in = set_contact_pending_in;
is_contact_pending_out = is_contact_pending_out;
set_contact_pending_out = set_contact_pending_out;
+ is_contact_preapproved = is_contact_preapproved;
unsubscribe = unsubscribe;
subscribed = subscribed;
unsubscribed = unsubscribed;