diff options
author | Waqas Hussain <waqas20@gmail.com> | 2008-10-25 21:16:08 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2008-10-25 21:16:08 +0500 |
commit | 091e961c40b6d89f548efecea07e641e3f9c4210 (patch) | |
tree | bae9f53850bfc4fbbdf2bccaaa03d6c6fb8708a7 /core/rostermanager.lua | |
parent | 30de4348013dc1f21e916f1b2bb198369ff024bf (diff) | |
download | prosody-091e961c40b6d89f548efecea07e641e3f9c4210.tar.gz prosody-091e961c40b6d89f548efecea07e641e3f9c4210.zip |
Outbound presence subscription
Diffstat (limited to 'core/rostermanager.lua')
-rw-r--r-- | core/rostermanager.lua | 136 |
1 files changed, 128 insertions, 8 deletions
diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 7d7fd061..ffc4f481 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -96,10 +96,10 @@ end function process_inbound_subscription_approval(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; - if item and item.ask and (item.subscription == "none" or item.subscription == "from") then + if item and item.ask then if item.subscription == "none" then item.subscription = "to"; - else + else -- subscription == from item.subscription = "both"; end item.ask = nil; @@ -110,13 +110,21 @@ end function process_inbound_subscription_cancellation(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; - if item and (item.subscription == "to" or item.subscription == "both") then + local changed = nil; + if is_contact_pending_out(username, host, jid) then + item.ask = nil; + changed = true; + end + if item then if item.subscription == "to" then item.subscription = "none"; - else + changed = true; + elseif item.subscription == "both" then item.subscription = "from"; + changed = true; end - -- FIXME do we need to item.ask = nil;? + end + if changed then return datamanager.store(username, host, "roster", roster); end end @@ -124,13 +132,21 @@ end function process_inbound_unsubscribe(username, host, jid) local roster = load_roster(username, host); local item = roster[jid]; - if item and (item.subscription == "from" or item.subscription == "both") then + local changed = nil; + if is_contact_pending_in(username, host, jid) then + roster.pending[jid] = nil; -- TODO maybe delete roster.pending if empty? + changed = true; + end + if item then if item.subscription == "from" then item.subscription = "none"; - else + changed = true; + elseif item.subscription == "both" then item.subscription = "to"; + changed = true; end - item.ask = nil; + end + if changed then return datamanager.store(username, host, "roster", roster); end end @@ -141,4 +157,108 @@ function is_contact_subscribed(username, host, jid) return item and (item.subscription == "from" or item.subscription == "both"); end +function is_contact_pending_in(username, host, jid) + local roster = load_roster(username, host); + return roster.pending or roster.pending[jid]; +end +function set_contact_pending_in(username, host, jid, pending) + local roster = load_roster(username, host); + local item = roster[jid]; + if item and (item.subscription == "from" or item.subscription == "both") then + return; -- false + end + if not roster.pending then roster.pending = {}; end + roster.pending[jid] = true; + return datamanager.store(username, host, "roster", roster); +end +function is_contact_pending_out(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + return item and item.ask; +end +function set_contact_pending_out(username, host, jid) -- subscribe + local roster = load_roster(username, host); + local item = roster[jid]; + if item and (item.ask or item.subscription == "to" or item.subscription == "both") then + return true; + end + if not item then + item = {subscription = "none"}; + roster[jid] = item; + end + item.ask = "subscribe"; + return datamanager.store(username, host, "roster", roster); +end +function unsubscribe(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + if not item then return false; end + if (item.subscription == "from" or item.subscription == "none") and not item.ask then + return true; + end + item.ask = nil; + if item.subscription == "both" then + item.subscription = "from"; + elseif item.subscription == "to" then + item.subscription = "none"; + end + return datamanager.store(username, host, "roster", roster); +end +function subscribed(username, host, jid) + if is_contact_pending_in(username, host, jid) then + local roster = load_roster(username, host); + local item = roster[jid]; + if item.subscription == "none" then + item.subscription = "from"; + else -- subscription == to + item.subsctiption = "both"; + end + roster.pending[jid] = nil; + -- TODO maybe remove roster.pending if empty + return datamanager.store(username, host, "roster", roster); + end -- TODO else implement optional feature pre-approval (ask = subscribed) +end +function unsubscribed(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + local pending = is_contact_pending_in(username, host, jid); + local changed = nil; + if is_contact_pending_in(username, host, jid) then + roster.pending[jid] = nil; -- TODO maybe delete roster.pending if empty? + changed = true; + end + if item then + if item.subscription == "from" then + item.subscription = "none"; + changed = true; + elseif item.subscription == both then + item.subscription = "to"; + changed = true; + end + end + if changed then + return datamanager.store(username, host, "roster", roster); + end +end + +function process_outbound_subscription_request(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + if item and (item.subscription == "none" or item.subscription == "from") then + item.ask = "subscribe"; + return datamanager.store(username, host, "roster", roster); + end +end + +--[[function process_outbound_subscription_approval(username, host, jid) + local roster = load_roster(username, host); + local item = roster[jid]; + if item and (item.subscription == "none" or item.subscription == "from" then + item.ask = "subscribe"; + return datamanager.store(username, host, "roster", roster); + end +end]] + + + return _M;
\ No newline at end of file |