Software /
code /
prosody
Changeset
1430:39169cf8d36f
mod_pep: Broadcast only to available recipients with caps
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 26 Jun 2009 23:58:52 +0500 |
parents | 1429:51cfb152cb38 |
children | 1431:9fe9ba693f4a |
files | plugins/mod_pep.lua |
diffstat | 1 files changed, 14 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pep.lua Fri Jun 26 23:42:59 2009 +0500 +++ b/plugins/mod_pep.lua Fri Jun 26 23:58:52 2009 +0500 @@ -9,6 +9,7 @@ local next = next; local load_roster = require "core.rostermanager".load_roster; +local NULL = {}; local data = {}; local recipients = {}; @@ -35,16 +36,10 @@ 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 @@ 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