aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pep.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-09-25 18:08:25 +0200
committerKim Alvefur <zash@zash.se>2015-09-25 18:08:25 +0200
commit5fb304d7a14207bd63294d4032eb4d304139d7a9 (patch)
tree33843e77275613abfcff2be59f6f89059d59194d /plugins/mod_pep.lua
parent356975370c97c43a3a0f3bb935ad027607d343cb (diff)
parentc241eab4631e190e64b993f803019e612a8c4304 (diff)
downloadprosody-5fb304d7a14207bd63294d4032eb4d304139d7a9.tar.gz
prosody-5fb304d7a14207bd63294d4032eb4d304139d7a9.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r--plugins/mod_pep.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index a6916d1f..896f3e78 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -16,10 +16,15 @@ 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 = {};
+-- 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 @@ 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 +291,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);