Software /
code /
prosody
Comparison
core/rostermanager.lua @ 10514:f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 19 Dec 2019 10:03:16 +0000 |
parent | 9705:42a3e3a28248 |
child | 10570:962efe23975d |
comparison
equal
deleted
inserted
replaced
10513:7a82f7ecf0ce | 10514:f0e9e5bda415 |
---|---|
299 function is_contact_pending_out(username, host, jid) | 299 function is_contact_pending_out(username, host, jid) |
300 local roster = load_roster(username, host); | 300 local roster = load_roster(username, host); |
301 local item = roster[jid]; | 301 local item = roster[jid]; |
302 return item and item.ask; | 302 return item and item.ask; |
303 end | 303 end |
304 local function is_contact_preapproved(username, host, jid) | |
305 local roster = load_roster(username, host); | |
306 local item = roster[jid]; | |
307 return item and (item.approved == "true"); | |
308 end | |
304 local function set_contact_pending_out(username, host, jid) -- subscribe | 309 local function set_contact_pending_out(username, host, jid) -- subscribe |
305 local roster = load_roster(username, host); | 310 local roster = load_roster(username, host); |
306 local item = roster[jid]; | 311 local item = roster[jid]; |
307 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then | 312 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then |
308 return true; | 313 return true; |
329 item.subscription = "none"; | 334 item.subscription = "none"; |
330 end | 335 end |
331 return save_roster(username, host, roster, jid); | 336 return save_roster(username, host, roster, jid); |
332 end | 337 end |
333 local function subscribed(username, host, jid) | 338 local function subscribed(username, host, jid) |
339 local roster = load_roster(username, host); | |
340 local item = roster[jid]; | |
341 | |
334 if is_contact_pending_in(username, host, jid) then | 342 if is_contact_pending_in(username, host, jid) then |
335 local roster = load_roster(username, host); | |
336 local item = roster[jid]; | |
337 if not item then -- FIXME should roster item be auto-created? | 343 if not item then -- FIXME should roster item be auto-created? |
338 item = {subscription = "none", groups = {}}; | 344 item = {subscription = "none", groups = {}}; |
339 roster[jid] = item; | 345 roster[jid] = item; |
340 end | 346 end |
341 if item.subscription == "none" then | 347 if item.subscription == "none" then |
343 else -- subscription == to | 349 else -- subscription == to |
344 item.subscription = "both"; | 350 item.subscription = "both"; |
345 end | 351 end |
346 roster[false].pending[jid] = nil; | 352 roster[false].pending[jid] = nil; |
347 return save_roster(username, host, roster, jid); | 353 return save_roster(username, host, roster, jid); |
348 end -- TODO else implement optional feature pre-approval (ask = subscribed) | 354 elseif not item or item.subscription == "none" or item.subscription == "to" then |
355 -- Contact is not subscribed and has not sent a subscription request. | |
356 -- We store a pre-approval as per RFC6121 3.4 | |
357 if not item then | |
358 item = {subscription = "none", groups = {}}; | |
359 roster[jid] = item; | |
360 end | |
361 item.approved = "true"; | |
362 log("debug", "Storing preapproval for %s", jid); | |
363 return save_roster(username, host, roster, jid); | |
364 end | |
349 end | 365 end |
350 local function unsubscribed(username, host, jid) | 366 local function unsubscribed(username, host, jid) |
351 local roster = load_roster(username, host); | 367 local roster = load_roster(username, host); |
352 local item = roster[jid]; | 368 local item = roster[jid]; |
353 local pending = is_contact_pending_in(username, host, jid); | 369 local pending = is_contact_pending_in(username, host, jid); |
401 is_user_subscribed = is_user_subscribed; | 417 is_user_subscribed = is_user_subscribed; |
402 is_contact_pending_in = is_contact_pending_in; | 418 is_contact_pending_in = is_contact_pending_in; |
403 set_contact_pending_in = set_contact_pending_in; | 419 set_contact_pending_in = set_contact_pending_in; |
404 is_contact_pending_out = is_contact_pending_out; | 420 is_contact_pending_out = is_contact_pending_out; |
405 set_contact_pending_out = set_contact_pending_out; | 421 set_contact_pending_out = set_contact_pending_out; |
422 is_contact_preapproved = is_contact_preapproved; | |
406 unsubscribe = unsubscribe; | 423 unsubscribe = unsubscribe; |
407 subscribed = subscribed; | 424 subscribed = subscribed; |
408 unsubscribed = unsubscribed; | 425 unsubscribed = unsubscribed; |
409 process_outbound_subscription_request = process_outbound_subscription_request; | 426 process_outbound_subscription_request = process_outbound_subscription_request; |
410 }; | 427 }; |