Comparison

plugins/mod_pep.lua @ 6866:abff7543b79c

Merge 0.9->0.10
author Matthew Wild <mwild1@gmail.com>
date Fri, 25 Sep 2015 16:51:42 +0100
parent 6544:2f709bc35575
parent 6865:20b0f0b48655
child 7453:b1efeee55972
comparison
equal deleted inserted replaced
6858:d8f8c0b2fda8 6866:abff7543b79c
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 19 local bare_sessions = prosody.bare_sessions;
20
21 -- Used as canonical 'empty table'
20 local NULL = {}; 22 local NULL = {};
23 -- data[user_bare_jid][node] = item_stanza
21 local data = {}; 24 local data = {};
25 --- recipients[user_bare_jid][contact_full_jid][subscribed_node] = true
22 local recipients = {}; 26 local recipients = {};
27 -- hash_map[hash][subscribed_nodes] = true
23 local hash_map = {}; 28 local hash_map = {};
24 29
25 module.save = function() 30 module.save = function()
26 return { data = data, recipients = recipients, hash_map = hash_map }; 31 return { data = data, recipients = recipients, hash_map = hash_map };
27 end 32 end
117 -- inbound presence to bare JID recieved 122 -- inbound presence to bare JID recieved
118 local origin, stanza = event.origin, event.stanza; 123 local origin, stanza = event.origin, event.stanza;
119 local user = stanza.attr.to or (origin.username..'@'..origin.host); 124 local user = stanza.attr.to or (origin.username..'@'..origin.host);
120 local t = stanza.attr.type; 125 local t = stanza.attr.type;
121 local self = not stanza.attr.to; 126 local self = not stanza.attr.to;
127
128 -- Only cache subscriptions if user is online
129 if not bare_sessions[user] then return; end
122 130
123 if not t then -- available presence 131 if not t then -- available presence
124 if self or subscription_presence(user, stanza.attr.from) then 132 if self or subscription_presence(user, stanza.attr.from) then
125 local recipient = stanza.attr.from; 133 local recipient = stanza.attr.from;
126 local current = recipients[user] and recipients[user][recipient]; 134 local current = recipients[user] and recipients[user][recipient];
281 for node, _ in pairs(user_data) do 289 for node, _ in pairs(user_data) do
282 reply:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes 290 reply:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes
283 end 291 end
284 end 292 end
285 end); 293 end);
294
295 module:hook("resource-unbind", function (event)
296 local user_bare_jid = event.session.username.."@"..event.session.host;
297 if not bare_sessions[user_bare_jid] then -- User went offline
298 -- We don't need this info cached anymore, clear it.
299 recipients[user_bare_jid] = nil;
300 end
301 end);