aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-06-26 23:58:52 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-06-26 23:58:52 +0500
commit11166044f70a43742af0057a9d89e0d1fc545e8c (patch)
tree7892271a955e8dabcaf1bc0634c46d154127e084 /plugins
parent9f5e655df1e75d39f7a57c9284fa7dbe73a670d5 (diff)
downloadprosody-11166044f70a43742af0057a9d89e0d1fc545e8c.tar.gz
prosody-11166044f70a43742af0057a9d89e0d1fc545e8c.zip
mod_pep: Broadcast only to available recipients with caps
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_pep.lua33
1 files changed, 14 insertions, 19 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index da6e42f0..f3e9f4a0 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -9,6 +9,7 @@ local pairs, ipairs = pairs, ipairs;
local next = next;
local load_roster = require "core.rostermanager".load_roster;
+local NULL = {};
local data = {};
local recipients = {};
@@ -35,16 +36,10 @@ local function publish(session, node, item)
user_data[node] = stanza;
end
- -- broadcast to resources
- stanza.attr.to = bare;
- core_route_stanza(session, stanza);
-
- -- broadcast to contacts
- for jid, item in pairs(session.roster) do
- if jid and jid ~= "pending" and (item.subscription == 'from' or item.subscription == 'both') then
- stanza.attr.to = jid;
- core_route_stanza(session, stanza);
- end
+ -- broadcast
+ for recipient in pairs(recipients[user] or NULL) do
+ stanza.attr.to = recipient;
+ core_post_stanza(session, stanza);
end
end
@@ -76,18 +71,18 @@ module:hook("presence/bare", function(event)
local bare = jid_bare(stanza.attr.from);
local item = load_roster(jid_split(user))[bare];
if not stanza.attr.to or (item and (item.subscription == 'from' or item.subscription == 'both')) then
- local t = stanza.attr.type;
local recipient = stanza.attr.from;
- if t == "unavailable" or t == "error" then
+ local current = recipients[user] and recipients[user][recipient];
+ local hash = get_caps_hash_from_presence(stanza, current);
+ if current == hash then return; end
+ if not hash then
if recipients[user] then recipients[user][recipient] = nil; end
- elseif not t then
+ else
recipients[user] = recipients[user] or {};
- if not recipients[user][recipient] then
- recipients[user][recipient] = true;
- for node, message in pairs(data[user] or {}) do
- message.attr.to = stanza.attr.from;
- origin.send(message);
- end
+ recipients[user][recipient] = hash;
+ for node, message in pairs(data[user] or NULL) do
+ message.attr.to = stanza.attr.from;
+ origin.send(message);
end
end
end