aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-09-25 16:48:25 +0100
committerMatthew Wild <mwild1@gmail.com>2015-09-25 16:48:25 +0100
commita6f64405217d5bd89d60794eca0324844e5e48ef (patch)
treeeb0c521d8f585edf6c59b8919473e3a5c9988358
parent46fa6a1d17e3efbd7ffd77987810a5e1b1d20d09 (diff)
downloadprosody-a6f64405217d5bd89d60794eca0324844e5e48ef.tar.gz
prosody-a6f64405217d5bd89d60794eca0324844e5e48ef.zip
mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
-rw-r--r--plugins/mod_pep.lua12
1 files changed, 12 insertions, 0 deletions
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);