Software /
code /
prosody
Diff
plugins/mod_pep.lua @ 6866:abff7543b79c
Merge 0.9->0.10
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 16:51:42 +0100 |
parent | 6544:2f709bc35575 |
parent | 6865:20b0f0b48655 |
child | 7453:b1efeee55972 |
line wrap: on
line diff
--- a/plugins/mod_pep.lua Fri Sep 25 17:43:21 2015 +0200 +++ b/plugins/mod_pep.lua Fri Sep 25 16:51:42 2015 +0100 @@ -16,10 +16,15 @@ local type = type; local calculate_hash = require "util.caps".calculate_hash; local core_post_stanza = prosody.core_post_stanza; +local bare_sessions = prosody.bare_sessions; +-- Used as canonical 'empty table' local NULL = {}; +-- data[user_bare_jid][node] = item_stanza local data = {}; +--- recipients[user_bare_jid][contact_full_jid][subscribed_node] = true local recipients = {}; +-- hash_map[hash][subscribed_nodes] = true local hash_map = {}; module.save = function() @@ -120,6 +125,9 @@ local t = stanza.attr.type; local self = not stanza.attr.to; + -- Only cache subscriptions if user is online + if not bare_sessions[user] then return; end + if not t then -- available presence if self or subscription_presence(user, stanza.attr.from) then local recipient = stanza.attr.from; @@ -283,3 +291,11 @@ end end 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 info cached anymore, clear it. + recipients[user_bare_jid] = nil; + end +end);