Software /
code /
prosody
Comparison
plugins/mod_pubsub/pubsub.lib.lua @ 8333:2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 17 Oct 2017 05:47:06 +0200 |
parent | 8327:0b561f8bc790 |
child | 8334:036e46d12b78 |
comparison
equal
deleted
inserted
replaced
8332:e89b57d0d80a | 8333:2abbb01cd756 |
---|---|
280 if not node_obj then | 280 if not node_obj then |
281 origin.send(pubsub_error_reply(stanza, "item-not-found")); | 281 origin.send(pubsub_error_reply(stanza, "item-not-found")); |
282 return true; | 282 return true; |
283 end | 283 end |
284 | 284 |
285 local node_config = node_obj.config; | |
286 local pubsub_form_data = { | |
287 ["pubsub#max_items"] = tostring(node_config["max_items"]); | |
288 ["pubsub#persist_items"] = node_config["persist_items"] | |
289 } | |
285 local reply = st.reply(stanza) | 290 local reply = st.reply(stanza) |
286 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) | 291 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
287 :tag("configure", { node = node }) | 292 :tag("configure", { node = node }) |
288 :add_child(node_config_form:form(node_obj.config)); | 293 :add_child(node_config_form:form(pubsub_form_data)); |
289 origin.send(reply); | 294 origin.send(reply); |
290 return true; | 295 return true; |
291 end | 296 end |
292 | 297 |
293 function handlers.set_configure(origin, stanza, config, service) | 298 function handlers.set_configure(origin, stanza, config, service) |
303 local config_form = config:get_child("x", "jabber:x:data"); | 308 local config_form = config:get_child("x", "jabber:x:data"); |
304 if not config_form then | 309 if not config_form then |
305 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); | 310 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); |
306 return true; | 311 return true; |
307 end | 312 end |
308 local new_config, err = node_config_form:data(config_form); | 313 local form_data, err = node_config_form:data(config_form); |
309 if not new_config then | 314 if not form_data then |
310 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); | 315 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
311 return true; | 316 return true; |
312 end | 317 end |
318 local new_config = { | |
319 ["max_items"] = tonumber(form_data["pubsub#max_items"]); | |
320 ["persist_items"] = form_data["pubsub#persist_items"]; | |
321 }; | |
313 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); | 322 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); |
314 if not ok then | 323 if not ok then |
315 origin.send(pubsub_error_reply(stanza, err)); | 324 origin.send(pubsub_error_reply(stanza, err)); |
316 return true; | 325 return true; |
317 end | 326 end |
318 origin.send(st.reply(stanza)); | 327 origin.send(st.reply(stanza)); |
319 return true; | 328 return true; |
320 end | 329 end |
321 | 330 |
322 function handlers.get_default(origin, stanza, default, service) | 331 function handlers.get_default(origin, stanza, default, service) |
332 local pubsub_form_data = { | |
333 ["pubsub#max_items"] = tostring(service.node_defaults["max_items"]); | |
334 ["pubsub#persist_items"] = service.node_defaults["persist_items"] | |
335 } | |
323 local reply = st.reply(stanza) | 336 local reply = st.reply(stanza) |
324 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) | 337 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
325 :tag("default") | 338 :tag("default") |
326 :add_child(node_config_form:form(service.node_defaults)); | 339 :add_child(node_config_form:form(pubsub_form_data)); |
327 origin.send(reply); | 340 origin.send(reply); |
328 return true; | 341 return true; |
329 end | 342 end |
330 | 343 |
331 local function create_encapsulating_item(id, payload) | 344 local function create_encapsulating_item(id, payload) |