comparison mod_http_roster_admin/mod_http_roster_admin.lua @ 2617:7c3a1688e385

Purge the roster from RAM when the user logs off. Also.. the `download` flag was being checked for, but never set, causing the roster to be fetched even if it was cached.
author JC Brand <jc@opkode.com>
date Tue, 14 Mar 2017 12:35:56 +0000
parents 68ebc52222dc
children c4c51e43b788
comparison
equal deleted inserted replaced
2616:c814c667d4d1 2617:7c3a1688e385
19 local it = require "util.iterators"; 19 local it = require "util.iterators";
20 local set = require "util.set"; 20 local set = require "util.set";
21 local rm = require "core.rostermanager"; 21 local rm = require "core.rostermanager";
22 local st = require "util.stanza"; 22 local st = require "util.stanza";
23 local array = require "util.array"; 23 local array = require "util.array";
24
25 local bare_sessions = prosody.bare_sessions;
26 local storagemanager = require "core.storagemanager";
24 27
25 local host = module.host; 28 local host = module.host;
26 local sessions = hosts[host].sessions; 29 local sessions = hosts[host].sessions;
27 30
28 local roster_url = module:get_option_string("http_roster_url", "http://localhost/%s"); 31 local roster_url = module:get_option_string("http_roster_url", "http://localhost/%s");
211 return; 214 return;
212 end 215 end
213 216
214 -- Are we the first callback to handle the downloaded roster? 217 -- Are we the first callback to handle the downloaded roster?
215 local first = roster[false].downloaded == nil; 218 local first = roster[false].downloaded == nil;
216
217 if first then 219 if first then
218 -- Fill out new roster 220 -- Fill out new roster
219 for jid, friend in pairs(friends) do 221 for jid, friend in pairs(friends) do
220 roster[jid] = friend_to_roster_item(friend); 222 roster[jid] = friend_to_roster_item(friend);
221 end 223 end
222 end 224 end
225
226 roster[false].downloaded = true;
223 227
224 -- Send full roster to client 228 -- Send full roster to client
225 session.send(build_roster_reply(stanza, roster)); 229 session.send(build_roster_reply(stanza, roster));
226 230
227 if not first then 231 if not first then
288 end 292 end
289 293
290 return true; 294 return true;
291 end 295 end
292 296
297 module:hook("resource-unbind", function (event)
298 local user_bare_jid = event.session.username.."@"..event.session.host;
299 if not bare_sessions[user_bare_jid] then -- User went offline
300 -- We don't need this user's info cached anymore, clear it.
301 module:log("debug", "Purging the roster for %s", user_bare_jid);
302 storagemanager.open(event.session.host, "roster", "keyval").store[event.session.username] = nil;
303 end
304 end);
293 305
294 module:provides("http", { 306 module:provides("http", {
295 route = { 307 route = {
296 ["POST /refresh"] = handle_refresh_multi; 308 ["POST /refresh"] = handle_refresh_multi;
297 ["GET /refresh/*"] = handle_refresh_single; 309 ["GET /refresh/*"] = handle_refresh_single;