Mercurial > prosody-hg
comparison plugins/mod_pep_plus.lua @ 6305:38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 08 Jul 2014 07:32:45 +0200 |
| parents | 12a083299bb7 |
| children | 388786af0dd2 |
comparison
equal
deleted
inserted
replaced
| 6304:ace08821e4ee | 6305:38d82f8ead25 |
|---|---|
| 11 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; | 11 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
| 12 | 12 |
| 13 local lib_pubsub = module:require "pubsub"; | 13 local lib_pubsub = module:require "pubsub"; |
| 14 local handlers = lib_pubsub.handlers; | 14 local handlers = lib_pubsub.handlers; |
| 15 local pubsub_error_reply = lib_pubsub.pubsub_error_reply; | 15 local pubsub_error_reply = lib_pubsub.pubsub_error_reply; |
| 16 | |
| 17 local empty_set = set_new(); | |
| 16 | 18 |
| 17 local services = {}; | 19 local services = {}; |
| 18 local recipients = {}; | 20 local recipients = {}; |
| 19 local hash_map = {}; | 21 local hash_map = {}; |
| 20 | 22 |
| 220 end | 222 end |
| 221 end | 223 end |
| 222 | 224 |
| 223 local function update_subscriptions(recipient, service_name, nodes) | 225 local function update_subscriptions(recipient, service_name, nodes) |
| 224 local service = get_pep_service(service_name); | 226 local service = get_pep_service(service_name); |
| 225 | 227 nodes = nodes or empty_set; |
| 226 recipients[service_name] = recipients[service_name] or {}; | 228 |
| 227 nodes = nodes or set_new(); | 229 local service_recipients = recipients[service_name]; |
| 228 local old = recipients[service_name][recipient]; | 230 if not service_recipients then |
| 229 | 231 service_recipients = {}; |
| 230 if old and type(old) == table then | 232 recipients[service_name] = service_recipients; |
| 231 for node in pairs((old - nodes):items()) do | 233 end |
| 232 service:remove_subscription(node, recipient, recipient); | 234 |
| 233 end | 235 local current = service_recipients[recipient]; |
| 234 end | 236 if not current or type(current) ~= "table" then |
| 235 | 237 current = empty_set; |
| 236 for node in nodes:items() do | 238 end |
| 239 | |
| 240 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then | |
| 241 return; | |
| 242 end | |
| 243 | |
| 244 for node in current - nodes do | |
| 245 service:remove_subscription(node, recipient, recipient); | |
| 246 end | |
| 247 | |
| 248 for node in nodes - current do | |
| 237 service:add_subscription(node, recipient, recipient); | 249 service:add_subscription(node, recipient, recipient); |
| 238 resend_last_item(recipient, node, service); | 250 resend_last_item(recipient, node, service); |
| 239 end | 251 end |
| 240 recipients[service_name][recipient] = nodes; | 252 |
| 253 if nodes == empty_set or nodes:empty() then | |
| 254 nodes = nil; | |
| 255 end | |
| 256 | |
| 257 service_recipients[recipient] = nodes; | |
| 241 end | 258 end |
| 242 | 259 |
| 243 module:hook("presence/bare", function(event) | 260 module:hook("presence/bare", function(event) |
| 244 -- inbound presence to bare JID recieved | 261 -- inbound presence to bare JID recieved |
| 245 local origin, stanza = event.origin, event.stanza; | 262 local origin, stanza = event.origin, event.stanza; |
