Comparison

core/rostermanager.lua @ 1898:1ce02e2f5a3f

rostermanager: Fixed: Roster version was not being properly updated in some edge cases.
author Waqas Hussain <waqas20@gmail.com>
date Sun, 04 Oct 2009 21:34:17 +0500
parent 1897:6d81e74310a7
child 1947:ff2b86076e9c
comparison
equal deleted inserted replaced
1897:6d81e74310a7 1898:1ce02e2f5a3f
128 item.subscription = "to"; 128 item.subscription = "to";
129 else -- subscription == from 129 else -- subscription == from
130 item.subscription = "both"; 130 item.subscription = "both";
131 end 131 end
132 item.ask = nil; 132 item.ask = nil;
133 return datamanager.store(username, host, "roster", roster); 133 return save_roster(username, host, roster);
134 end 134 end
135 end 135 end
136 136
137 function process_inbound_subscription_cancellation(username, host, jid) 137 function process_inbound_subscription_cancellation(username, host, jid)
138 local roster = load_roster(username, host); 138 local roster = load_roster(username, host);
150 item.subscription = "from"; 150 item.subscription = "from";
151 changed = true; 151 changed = true;
152 end 152 end
153 end 153 end
154 if changed then 154 if changed then
155 return datamanager.store(username, host, "roster", roster); 155 return save_roster(username, host, roster);
156 end 156 end
157 end 157 end
158 158
159 function process_inbound_unsubscribe(username, host, jid) 159 function process_inbound_unsubscribe(username, host, jid)
160 local roster = load_roster(username, host); 160 local roster = load_roster(username, host);
172 item.subscription = "to"; 172 item.subscription = "to";
173 changed = true; 173 changed = true;
174 end 174 end
175 end 175 end
176 if changed then 176 if changed then
177 return datamanager.store(username, host, "roster", roster); 177 return save_roster(username, host, roster);
178 end 178 end
179 end 179 end
180 180
181 function is_contact_subscribed(username, host, jid) 181 function is_contact_subscribed(username, host, jid)
182 local roster = load_roster(username, host); 182 local roster = load_roster(username, host);
194 if item and (item.subscription == "from" or item.subscription == "both") then 194 if item and (item.subscription == "from" or item.subscription == "both") then
195 return; -- false 195 return; -- false
196 end 196 end
197 if not roster.pending then roster.pending = {}; end 197 if not roster.pending then roster.pending = {}; end
198 roster.pending[jid] = true; 198 roster.pending[jid] = true;
199 return datamanager.store(username, host, "roster", roster); 199 return save_roster(username, host, roster);
200 end 200 end
201 function is_contact_pending_out(username, host, jid) 201 function is_contact_pending_out(username, host, jid)
202 local roster = load_roster(username, host); 202 local roster = load_roster(username, host);
203 local item = roster[jid]; 203 local item = roster[jid];
204 return item and item.ask; 204 return item and item.ask;
213 item = {subscription = "none", groups = {}}; 213 item = {subscription = "none", groups = {}};
214 roster[jid] = item; 214 roster[jid] = item;
215 end 215 end
216 item.ask = "subscribe"; 216 item.ask = "subscribe";
217 log("debug", "set_contact_pending_out: saving roster; set "..username.."@"..host..".roster["..jid.."].ask=subscribe"); 217 log("debug", "set_contact_pending_out: saving roster; set "..username.."@"..host..".roster["..jid.."].ask=subscribe");
218 return datamanager.store(username, host, "roster", roster); 218 return save_roster(username, host, roster);
219 end 219 end
220 function unsubscribe(username, host, jid) 220 function unsubscribe(username, host, jid)
221 local roster = load_roster(username, host); 221 local roster = load_roster(username, host);
222 local item = roster[jid]; 222 local item = roster[jid];
223 if not item then return false; end 223 if not item then return false; end
228 if item.subscription == "both" then 228 if item.subscription == "both" then
229 item.subscription = "from"; 229 item.subscription = "from";
230 elseif item.subscription == "to" then 230 elseif item.subscription == "to" then
231 item.subscription = "none"; 231 item.subscription = "none";
232 end 232 end
233 return datamanager.store(username, host, "roster", roster); 233 return save_roster(username, host, roster);
234 end 234 end
235 function subscribed(username, host, jid) 235 function subscribed(username, host, jid)
236 if is_contact_pending_in(username, host, jid) then 236 if is_contact_pending_in(username, host, jid) then
237 local roster = load_roster(username, host); 237 local roster = load_roster(username, host);
238 local item = roster[jid]; 238 local item = roster[jid];
245 else -- subscription == to 245 else -- subscription == to
246 item.subscription = "both"; 246 item.subscription = "both";
247 end 247 end
248 roster.pending[jid] = nil; 248 roster.pending[jid] = nil;
249 -- TODO maybe remove roster.pending if empty 249 -- TODO maybe remove roster.pending if empty
250 return datamanager.store(username, host, "roster", roster); 250 return save_roster(username, host, roster);
251 end -- TODO else implement optional feature pre-approval (ask = subscribed) 251 end -- TODO else implement optional feature pre-approval (ask = subscribed)
252 end 252 end
253 function unsubscribed(username, host, jid) 253 function unsubscribed(username, host, jid)
254 local roster = load_roster(username, host); 254 local roster = load_roster(username, host);
255 local item = roster[jid]; 255 local item = roster[jid];
267 item.subscription = "to"; 267 item.subscription = "to";
268 changed = true; 268 changed = true;
269 end 269 end
270 end 270 end
271 if changed then 271 if changed then
272 return datamanager.store(username, host, "roster", roster); 272 return save_roster(username, host, roster);
273 end 273 end
274 end 274 end
275 275
276 function process_outbound_subscription_request(username, host, jid) 276 function process_outbound_subscription_request(username, host, jid)
277 local roster = load_roster(username, host); 277 local roster = load_roster(username, host);
278 local item = roster[jid]; 278 local item = roster[jid];
279 if item and (item.subscription == "none" or item.subscription == "from") then 279 if item and (item.subscription == "none" or item.subscription == "from") then
280 item.ask = "subscribe"; 280 item.ask = "subscribe";
281 return datamanager.store(username, host, "roster", roster); 281 return save_roster(username, host, roster);
282 end 282 end
283 end 283 end
284 284
285 --[[function process_outbound_subscription_approval(username, host, jid) 285 --[[function process_outbound_subscription_approval(username, host, jid)
286 local roster = load_roster(username, host); 286 local roster = load_roster(username, host);
287 local item = roster[jid]; 287 local item = roster[jid];
288 if item and (item.subscription == "none" or item.subscription == "from" then 288 if item and (item.subscription == "none" or item.subscription == "from" then
289 item.ask = "subscribe"; 289 item.ask = "subscribe";
290 return datamanager.store(username, host, "roster", roster); 290 return save_roster(username, host, roster);
291 end 291 end
292 end]] 292 end]]
293 293
294 294
295 295