Software /
code /
prosody-modules
Diff
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 |
parent | 2441:68ebc52222dc |
child | 2621:c4c51e43b788 |
line wrap: on
line diff
--- a/mod_http_roster_admin/mod_http_roster_admin.lua Tue Mar 14 04:20:02 2017 +0100 +++ b/mod_http_roster_admin/mod_http_roster_admin.lua Tue Mar 14 12:35:56 2017 +0000 @@ -22,6 +22,9 @@ local st = require "util.stanza"; local array = require "util.array"; +local bare_sessions = prosody.bare_sessions; +local storagemanager = require "core.storagemanager"; + local host = module.host; local sessions = hosts[host].sessions; @@ -213,13 +216,14 @@ -- Are we the first callback to handle the downloaded roster? local first = roster[false].downloaded == nil; - if first then -- Fill out new roster for jid, friend in pairs(friends) do roster[jid] = friend_to_roster_item(friend); end end + + roster[false].downloaded = true; -- Send full roster to client session.send(build_roster_reply(stanza, roster)); @@ -290,6 +294,14 @@ return true; end +module:hook("resource-unbind", function (event) + local user_bare_jid = event.session.username.."@"..event.session.host; + if not bare_sessions[user_bare_jid] then -- User went offline + -- We don't need this user's info cached anymore, clear it. + module:log("debug", "Purging the roster for %s", user_bare_jid); + storagemanager.open(event.session.host, "roster", "keyval").store[event.session.username] = nil; + end +end); module:provides("http", { route = {