Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 10521:cbb2c3f8bb1d
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Dec 2019 20:57:10 +0100 |
parent | 10066:216ae100c04a |
parent | 10520:225fade2ab4d |
child | 10673:1a23a58ac84e |
comparison
equal
deleted
inserted
replaced
10517:6e1163fa2cd2 | 10521:cbb2c3f8bb1d |
---|---|
89 }; | 89 }; |
90 end | 90 end |
91 return data, err; | 91 return data, err; |
92 end | 92 end |
93 function store:set(node, data) | 93 function store:set(node, data) |
94 if data then | |
95 -- Save the data without subscriptions | |
96 local subscribers = {}; | |
97 for jid, sub in pairs(data.subscribers) do | |
98 if type(sub) ~= "table" or not sub.presence then | |
99 subscribers[jid] = sub; | |
100 end | |
101 end | |
102 data = { | |
103 name = data.name; | |
104 config = data.config; | |
105 affiliations = data.affiliations; | |
106 subscribers = subscribers; | |
107 }; | |
108 end | |
109 return node_config:set(username, node, data); | 94 return node_config:set(username, node, data); |
110 end | 95 end |
111 function store:users() | 96 function store:users() |
112 return pairs(known_nodes:get(username) or {}); | 97 return pairs(known_nodes:get(username) or {}); |
113 end | 98 end |
165 end | 150 end |
166 end | 151 end |
167 return simple_broadcast; | 152 return simple_broadcast; |
168 end | 153 end |
169 | 154 |
170 local function on_node_creation(event) | 155 local function get_subscriber_filter(username) |
171 local service = event.service; | 156 return function (jids, node) |
172 local node = event.node; | 157 local broadcast_to = {}; |
173 local username = service.config.pep_username; | 158 for jid, opts in pairs(jids) do |
174 | 159 broadcast_to[jid] = opts; |
175 local service_recipients = recipients[username]; | 160 end |
176 if not service_recipients then return; end | 161 |
177 | 162 local service_recipients = recipients[username]; |
178 for recipient, nodes in pairs(service_recipients) do | 163 if service_recipients then |
179 if nodes:contains(node) then | 164 local service = services[username]; |
180 service:add_subscription(node, recipient, recipient, { presence = true }); | 165 for recipient, nodes in pairs(service_recipients) do |
181 end | 166 if nodes:contains(node) and service:may(node, recipient, "subscribe") then |
167 broadcast_to[recipient] = true; | |
168 end | |
169 end | |
170 end | |
171 return broadcast_to; | |
182 end | 172 end |
183 end | 173 end |
184 | 174 |
185 function get_pep_service(username) | 175 function get_pep_service(username) |
186 local user_bare = jid_join(username, host); | 176 local user_bare = jid_join(username, host); |
201 autocreate_on_subscribe = false; | 191 autocreate_on_subscribe = false; |
202 | 192 |
203 nodestore = nodestore(username); | 193 nodestore = nodestore(username); |
204 itemstore = simple_itemstore(username); | 194 itemstore = simple_itemstore(username); |
205 broadcaster = get_broadcaster(username); | 195 broadcaster = get_broadcaster(username); |
196 subscriber_filter = get_subscriber_filter(username); | |
206 itemcheck = is_item_stanza; | 197 itemcheck = is_item_stanza; |
207 get_affiliation = function (jid) | 198 get_affiliation = function (jid) |
208 if jid_bare(jid) == user_bare then | 199 if jid_bare(jid) == user_bare then |
209 return "owner"; | 200 return "owner"; |
210 end | 201 end |
237 end | 228 end |
238 services[username] = service; | 229 services[username] = service; |
239 module:add_item("pep-service", { service = service, jid = user_bare }); | 230 module:add_item("pep-service", { service = service, jid = user_bare }); |
240 return service; | 231 return service; |
241 end | 232 end |
242 | |
243 module:hook("item-added/pep-service", function (event) | |
244 local service = event.item.service; | |
245 module:hook_object_event(service.events, "node-created", on_node_creation); | |
246 end); | |
247 | 233 |
248 function handle_pubsub_iq(event) | 234 function handle_pubsub_iq(event) |
249 local origin, stanza = event.origin, event.stanza; | 235 local origin, stanza = event.origin, event.stanza; |
250 local service_name = origin.username; | 236 local service_name = origin.username; |
251 if stanza.attr.to ~= nil then | 237 if stanza.attr.to ~= nil then |
306 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then | 292 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then |
307 return; | 293 return; |
308 end | 294 end |
309 | 295 |
310 local service = get_pep_service(service_name); | 296 local service = get_pep_service(service_name); |
311 for node in current - nodes do | |
312 service:remove_subscription(node, recipient, recipient); | |
313 end | |
314 | 297 |
315 for node in nodes - current do | 298 for node in nodes - current do |
316 if service:add_subscription(node, recipient, recipient, { presence = true }) then | 299 if service:may(node, recipient, "subscribe") then |
317 resend_last_item(recipient, node, service); | 300 resend_last_item(recipient, node, service); |
318 end | 301 end |
319 end | 302 end |
320 | 303 |
321 if nodes == empty_set or nodes:empty() then | 304 if nodes == empty_set or nodes:empty() then |