Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 10045:6714578cfd6e 0.11
mod_pep: Revert 045209b41b3a, caused a regression
Adding in all presence based subscriptions in the broadcaster caused
resend_last_item() to unintentionally send out more notifications than
it should have.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 10 Jun 2019 12:58:00 +0200 |
parent | 10036:045209b41b3a |
child | 10046:0bc291a5734a |
child | 10520:225fade2ab4d |
comparison
equal
deleted
inserted
replaced
10038:7dd0dddd8e02 | 10045:6714578cfd6e |
---|---|
88 }; | 88 }; |
89 end | 89 end |
90 return data, err; | 90 return data, err; |
91 end | 91 end |
92 function store:set(node, data) | 92 function store:set(node, data) |
93 if data then | |
94 -- Save the data without subscriptions | |
95 local subscribers = {}; | |
96 for jid, sub in pairs(data.subscribers) do | |
97 if type(sub) ~= "table" or not sub.presence then | |
98 subscribers[jid] = sub; | |
99 end | |
100 end | |
101 data = { | |
102 name = data.name; | |
103 config = data.config; | |
104 affiliations = data.affiliations; | |
105 subscribers = subscribers; | |
106 }; | |
107 end | |
93 return node_config:set(username, node, data); | 108 return node_config:set(username, node, data); |
94 end | 109 end |
95 function store:users() | 110 function store:users() |
96 return pairs(known_nodes:get(username) or {}); | 111 return pairs(known_nodes:get(username) or {}); |
97 end | 112 end |
134 item:maptags(function () return nil; end); | 149 item:maptags(function () return nil; end); |
135 end | 150 end |
136 end | 151 end |
137 message:add_child(item); | 152 message:add_child(item); |
138 end | 153 end |
139 | |
140 local broadcast_to = {}; | |
141 for jid in pairs(jids) do | 154 for jid in pairs(jids) do |
142 broadcast_to[jid] = true; | |
143 end | |
144 | |
145 local service_recipients = recipients[username]; | |
146 if service_recipients then | |
147 local service = services[username]; | |
148 for recipient, nodes in pairs(service_recipients) do | |
149 if nodes:contains(node) and service:may(node, recipient, "subscribe") then | |
150 broadcast_to[recipient] = true; | |
151 end | |
152 end | |
153 end | |
154 | |
155 for jid in pairs(broadcast_to) do | |
156 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); | 155 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); |
157 message.attr.to = jid; | 156 message.attr.to = jid; |
158 module:send(message); | 157 module:send(message); |
159 end | 158 end |
160 end | 159 end |
161 return simple_broadcast; | 160 return simple_broadcast; |
162 end | 161 end |
163 | 162 |
163 local function on_node_creation(event) | |
164 local service = event.service; | |
165 local node = event.node; | |
166 local username = service.config.pep_username; | |
167 | |
168 local service_recipients = recipients[username]; | |
169 if not service_recipients then return; end | |
170 | |
171 for recipient, nodes in pairs(service_recipients) do | |
172 if nodes:contains(node) then | |
173 service:add_subscription(node, recipient, recipient, { presence = true }); | |
174 end | |
175 end | |
176 end | |
164 | 177 |
165 function get_pep_service(username) | 178 function get_pep_service(username) |
166 module:log("debug", "get_pep_service(%q)", username); | 179 module:log("debug", "get_pep_service(%q)", username); |
167 local user_bare = jid_join(username, host); | 180 local user_bare = jid_join(username, host); |
168 local service = services[username]; | 181 local service = services[username]; |
218 services[username] = service; | 231 services[username] = service; |
219 module:add_item("pep-service", { service = service, jid = user_bare }); | 232 module:add_item("pep-service", { service = service, jid = user_bare }); |
220 return service; | 233 return service; |
221 end | 234 end |
222 | 235 |
236 module:hook("item-added/pep-service", function (event) | |
237 local service = event.item.service; | |
238 module:hook_object_event(service.events, "node-created", on_node_creation); | |
239 end); | |
223 | 240 |
224 function handle_pubsub_iq(event) | 241 function handle_pubsub_iq(event) |
225 local origin, stanza = event.origin, event.stanza; | 242 local origin, stanza = event.origin, event.stanza; |
226 local service_name = origin.username; | 243 local service_name = origin.username; |
227 if stanza.attr.to ~= nil then | 244 if stanza.attr.to ~= nil then |
284 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then | 301 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then |
285 return; | 302 return; |
286 end | 303 end |
287 | 304 |
288 local service = get_pep_service(service_name); | 305 local service = get_pep_service(service_name); |
306 for node in current - nodes do | |
307 service:remove_subscription(node, recipient, recipient); | |
308 end | |
289 | 309 |
290 for node in nodes - current do | 310 for node in nodes - current do |
291 if service:may(node, recipient, "subscribe") then | 311 if service:add_subscription(node, recipient, recipient, { presence = true }) then |
292 resend_last_item(recipient, node, service); | 312 resend_last_item(recipient, node, service); |
293 end | 313 end |
294 end | 314 end |
295 | 315 |
296 if nodes == empty_set or nodes:empty() then | 316 if nodes == empty_set or nodes:empty() then |