Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 9542:b8bfcfbe5126
mod_pep: Add automatic subscriptions on node creation (fixes #1222)
Replaces automatic node creation on subscription, since this casues
problems when trying to keep nodes private or other specific settings.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Oct 2018 20:22:55 +0200 |
parent | 9541:742977123168 |
child | 9597:17d43543f9b6 |
comparison
equal
deleted
inserted
replaced
9541:742977123168 | 9542:b8bfcfbe5126 |
---|---|
156 end | 156 end |
157 end | 157 end |
158 return simple_broadcast; | 158 return simple_broadcast; |
159 end | 159 end |
160 | 160 |
161 local function on_node_creation(event) | |
162 local service = event.service; | |
163 local node = event.node; | |
164 local username = service.config.pep_username; | |
165 | |
166 local service_recipients = recipients[username]; | |
167 if not service_recipients then return; end | |
168 | |
169 for recipient, nodes in pairs(service_recipients) do | |
170 if nodes:contains(node) then | |
171 service:add_subscription(node, recipient, recipient, { presence = true }); | |
172 end | |
173 end | |
174 end | |
175 | |
161 function get_pep_service(username) | 176 function get_pep_service(username) |
162 module:log("debug", "get_pep_service(%q)", username); | 177 module:log("debug", "get_pep_service(%q)", username); |
163 local user_bare = jid_join(username, host); | 178 local user_bare = jid_join(username, host); |
164 local service = services[username]; | 179 local service = services[username]; |
165 if service then | 180 if service then |
172 ["persist_items"] = true; | 187 ["persist_items"] = true; |
173 ["access_model"] = "presence"; | 188 ["access_model"] = "presence"; |
174 }; | 189 }; |
175 | 190 |
176 autocreate_on_publish = true; | 191 autocreate_on_publish = true; |
177 autocreate_on_subscribe = true; | 192 autocreate_on_subscribe = false; |
178 | 193 |
179 nodestore = nodestore(username); | 194 nodestore = nodestore(username); |
180 itemstore = simple_itemstore(username); | 195 itemstore = simple_itemstore(username); |
181 broadcaster = get_broadcaster(username); | 196 broadcaster = get_broadcaster(username); |
182 itemcheck = is_item_stanza; | 197 itemcheck = is_item_stanza; |
213 end | 228 end |
214 services[username] = service; | 229 services[username] = service; |
215 module:add_item("pep-service", { service = service, jid = user_bare }); | 230 module:add_item("pep-service", { service = service, jid = user_bare }); |
216 return service; | 231 return service; |
217 end | 232 end |
233 | |
234 module:hook("item-added/pep-service", function (event) | |
235 local service = event.item.service; | |
236 module:hook_object_event(service.events, "node-created", on_node_creation); | |
237 end); | |
218 | 238 |
219 function handle_pubsub_iq(event) | 239 function handle_pubsub_iq(event) |
220 local origin, stanza = event.origin, event.stanza; | 240 local origin, stanza = event.origin, event.stanza; |
221 local service_name = origin.username; | 241 local service_name = origin.username; |
222 if stanza.attr.to ~= nil then | 242 if stanza.attr.to ~= nil then |