Comparison

plugins/mod_pep.lua @ 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
parent 6864:0129ffcaa7ab
child 6866:abff7543b79c
comparison
equal deleted inserted replaced
6864:0129ffcaa7ab 6865:20b0f0b48655
14 local pairs = pairs; 14 local pairs = pairs;
15 local next = next; 15 local next = next;
16 local type = type; 16 local type = type;
17 local calculate_hash = require "util.caps".calculate_hash; 17 local calculate_hash = require "util.caps".calculate_hash;
18 local core_post_stanza = prosody.core_post_stanza; 18 local core_post_stanza = prosody.core_post_stanza;
19 local bare_sessions = prosody.bare_sessions;
19 20
20 -- Used as canonical 'empty table' 21 -- Used as canonical 'empty table'
21 local NULL = {}; 22 local NULL = {};
22 -- data[user_bare_jid][node] = item_stanza 23 -- data[user_bare_jid][node] = item_stanza
23 local data = {}; 24 local data = {};
119 -- inbound presence to bare JID recieved 120 -- inbound presence to bare JID recieved
120 local origin, stanza = event.origin, event.stanza; 121 local origin, stanza = event.origin, event.stanza;
121 local user = stanza.attr.to or (origin.username..'@'..origin.host); 122 local user = stanza.attr.to or (origin.username..'@'..origin.host);
122 local t = stanza.attr.type; 123 local t = stanza.attr.type;
123 local self = not stanza.attr.to; 124 local self = not stanza.attr.to;
125
126 -- Only cache subscriptions if user is online
127 if not bare_sessions[user] then return; end
124 128
125 if not t then -- available presence 129 if not t then -- available presence
126 if self or subscription_presence(user, stanza.attr.from) then 130 if self or subscription_presence(user, stanza.attr.from) then
127 local recipient = stanza.attr.from; 131 local recipient = stanza.attr.from;
128 local current = recipients[user] and recipients[user][recipient]; 132 local current = recipients[user] and recipients[user][recipient];
281 for node, _ in pairs(user_data) do 285 for node, _ in pairs(user_data) do
282 stanza:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes 286 stanza:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes
283 end 287 end
284 end 288 end
285 end); 289 end);
290
291 module:hook("resource-unbind", function (event)
292 local user_bare_jid = event.session.username.."@"..event.session.host;
293 if not bare_sessions[user_bare_jid] then -- User went offline
294 -- We don't need this info cached anymore, clear it.
295 recipients[user_bare_jid] = nil;
296 end
297 end);