Mercurial > prosody-hg
comparison core/rostermanager.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 962efe23975d |
| children | 05c250fa335a |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 283 return item and (item.subscription == "to" or item.subscription == "both"), err; | 283 return item and (item.subscription == "to" or item.subscription == "both"), err; |
| 284 end | 284 end |
| 285 | 285 |
| 286 function is_contact_pending_in(username, host, jid) | 286 function is_contact_pending_in(username, host, jid) |
| 287 local roster = load_roster(username, host); | 287 local roster = load_roster(username, host); |
| 288 return roster[false].pending[jid]; | 288 return roster[false].pending[jid] ~= nil; |
| 289 end | 289 end |
| 290 local function set_contact_pending_in(username, host, jid) | 290 local function set_contact_pending_in(username, host, jid, stanza) |
| 291 local roster = load_roster(username, host); | 291 local roster = load_roster(username, host); |
| 292 local item = roster[jid]; | 292 local item = roster[jid]; |
| 293 if item and (item.subscription == "from" or item.subscription == "both") then | 293 if item and (item.subscription == "from" or item.subscription == "both") then |
| 294 return; -- false | 294 return; -- false |
| 295 end | 295 end |
| 296 roster[false].pending[jid] = true; | 296 roster[false].pending[jid] = st.is_stanza(stanza) and st.preserialize(stanza) or true; |
| 297 return save_roster(username, host, roster, jid); | 297 return save_roster(username, host, roster, jid); |
| 298 end | 298 end |
| 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 | |
| 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"); | |
| 303 end | 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 |
| 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 }; |
