Software /
code /
prosody
Comparison
core/rostermanager.lua @ 177:606c433955e7
Bug fixes and checks for presence subscriptions, etc
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 26 Oct 2008 00:22:18 +0500 |
parent | 176:e5cd2a03891d |
child | 183:403db3b5c3c2 |
comparison
equal
deleted
inserted
replaced
176:e5cd2a03891d | 177:606c433955e7 |
---|---|
47 return nil, "auth", "not-authorized", "Session's roster not loaded"; | 47 return nil, "auth", "not-authorized", "Session's roster not loaded"; |
48 end | 48 end |
49 end | 49 end |
50 | 50 |
51 function roster_push(username, host, jid) | 51 function roster_push(username, host, jid) |
52 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 52 if jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
53 local item = hosts[host].sessions[username].roster[jid]; | 53 local item = hosts[host].sessions[username].roster[jid]; |
54 local stanza = st.iq({type="set"}); | 54 local stanza = st.iq({type="set"}); |
55 stanza:tag("query", {xmlns = "jabber:iq:roster"}); | 55 stanza:tag("query", {xmlns = "jabber:iq:roster"}); |
56 if item then | 56 if item then |
57 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); | 57 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); |
72 end | 72 end |
73 end | 73 end |
74 end | 74 end |
75 | 75 |
76 function load_roster(username, host) | 76 function load_roster(username, host) |
77 log("debug", "load_roster: asked for: "..username.."@"..host); | |
77 if hosts[host] and hosts[host].sessions[username] then | 78 if hosts[host] and hosts[host].sessions[username] then |
78 local roster = hosts[host].sessions[username].roster; | 79 local roster = hosts[host].sessions[username].roster; |
79 if not roster then | 80 if not roster then |
81 log("debug", "load_roster: loading for new user: "..username.."@"..host); | |
80 roster = datamanager.load(username, host, "roster") or {}; | 82 roster = datamanager.load(username, host, "roster") or {}; |
81 hosts[host].sessions[username].roster = roster; | 83 hosts[host].sessions[username].roster = roster; |
82 end | 84 end |
83 return roster; | 85 return roster; |
84 end | 86 end |
85 -- Attempt to load roster for non-loaded user | 87 -- Attempt to load roster for non-loaded user |
88 log("debug", "load_roster: loading for offline user: "..username.."@"..host); | |
86 return datamanager.load(username, host, "roster") or {}; | 89 return datamanager.load(username, host, "roster") or {}; |
87 end | 90 end |
88 | 91 |
89 function save_roster(username, host) | 92 function save_roster(username, host) |
93 log("debug", "save_roster: saving roster for "..username.."@"..host); | |
90 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 94 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
91 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); | 95 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); |
92 end | 96 end |
93 return nil; | 97 return nil; |
94 end | 98 end |
157 return item and (item.subscription == "from" or item.subscription == "both"); | 161 return item and (item.subscription == "from" or item.subscription == "both"); |
158 end | 162 end |
159 | 163 |
160 function is_contact_pending_in(username, host, jid) | 164 function is_contact_pending_in(username, host, jid) |
161 local roster = load_roster(username, host); | 165 local roster = load_roster(username, host); |
162 return roster.pending or roster.pending[jid]; | 166 return roster.pending and roster.pending[jid]; |
163 end | 167 end |
164 function set_contact_pending_in(username, host, jid, pending) | 168 function set_contact_pending_in(username, host, jid, pending) |
165 local roster = load_roster(username, host); | 169 local roster = load_roster(username, host); |
166 local item = roster[jid]; | 170 local item = roster[jid]; |
167 if item and (item.subscription == "from" or item.subscription == "both") then | 171 if item and (item.subscription == "from" or item.subscription == "both") then |
181 local item = roster[jid]; | 185 local item = roster[jid]; |
182 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then | 186 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then |
183 return true; | 187 return true; |
184 end | 188 end |
185 if not item then | 189 if not item then |
186 item = {subscription = "none"}; | 190 item = {subscription = "none", groups = {}}; |
187 roster[jid] = item; | 191 roster[jid] = item; |
188 end | 192 end |
189 item.ask = "subscribe"; | 193 item.ask = "subscribe"; |
194 log("debug", "set_contact_pending_out: saving roster; set "..username.."@"..host..".roster["..jid.."].ask=subscribe"); | |
190 return datamanager.store(username, host, "roster", roster); | 195 return datamanager.store(username, host, "roster", roster); |
191 end | 196 end |
192 function unsubscribe(username, host, jid) | 197 function unsubscribe(username, host, jid) |
193 local roster = load_roster(username, host); | 198 local roster = load_roster(username, host); |
194 local item = roster[jid]; | 199 local item = roster[jid]; |
209 local roster = load_roster(username, host); | 214 local roster = load_roster(username, host); |
210 local item = roster[jid]; | 215 local item = roster[jid]; |
211 if item.subscription == "none" then | 216 if item.subscription == "none" then |
212 item.subscription = "from"; | 217 item.subscription = "from"; |
213 else -- subscription == to | 218 else -- subscription == to |
214 item.subsctiption = "both"; | 219 item.subscription = "both"; |
215 end | 220 end |
216 roster.pending[jid] = nil; | 221 roster.pending[jid] = nil; |
217 -- TODO maybe remove roster.pending if empty | 222 -- TODO maybe remove roster.pending if empty |
218 return datamanager.store(username, host, "roster", roster); | 223 return datamanager.store(username, host, "roster", roster); |
219 end -- TODO else implement optional feature pre-approval (ask = subscribed) | 224 end -- TODO else implement optional feature pre-approval (ask = subscribed) |