Changeset

6865:20b0f0b48655

mod_pep: Don't store contacts' subscriptions to a user's nodes when that user is offline
author Matthew Wild <mwild1@gmail.com>
date Fri, 25 Sep 2015 16:48:25 +0100
parents 6864:0129ffcaa7ab
children 6866:abff7543b79c 6869:5ce783c37024
files plugins/mod_pep.lua
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pep.lua	Fri Sep 04 11:26:51 2015 +0100
+++ b/plugins/mod_pep.lua	Fri Sep 25 16:48:25 2015 +0100
@@ -16,6 +16,7 @@
 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 @@
 	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 @@
 		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);