From 9b76a57d589c61486f8a412cd40d595c72c7721b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 4 Sep 2015 11:26:51 +0100 Subject: mod_pep: Document data structures, so I don't have to spend time remembering every time I work on this module --- plugins/mod_pep.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins/mod_pep.lua') diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index bdb742e3..7b4c5ddc 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -17,9 +17,13 @@ local type = type; local calculate_hash = require "util.caps".calculate_hash; local core_post_stanza = prosody.core_post_stanza; +-- 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() -- cgit v1.2.3 From 28d21c104a784b2762f2ca23a421f6865c8ee887 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 25 Sep 2015 16:48:25 +0100 Subject: mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline --- plugins/mod_pep.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins/mod_pep.lua') diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index 7b4c5ddc..22790869 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -16,6 +16,7 @@ local next = next; 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 = {}; @@ -122,6 +123,9 @@ module:hook("presence/bare", function(event) 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 +287,11 @@ module:hook("account-disco-items", function(event) 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); -- cgit v1.2.3