Mercurial > prosody-modules
comparison mod_bookmarks/mod_bookmarks.lua @ 3476:4ce945490a24
mod_bookmarks: Actually save node config
| author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
|---|---|
| date | Wed, 06 Mar 2019 17:46:57 +0100 |
| parents | fd889eb16541 |
| children | e60933722248 |
comparison
equal
deleted
inserted
replaced
| 3475:820c891a54cc | 3476:4ce945490a24 |
|---|---|
| 123 local function on_node_created(event) | 123 local function on_node_created(event) |
| 124 local service, node, actor = event.service, event.node, event.actor; | 124 local service, node, actor = event.service, event.node, event.actor; |
| 125 if node ~= "storage:bookmarks" then | 125 if node ~= "storage:bookmarks" then |
| 126 return; | 126 return; |
| 127 end | 127 end |
| 128 local node_config = service.nodes[node].config; | 128 local ok, config = service:get_node_config(node, actor); |
| 129 if not ok then | |
| 130 module:log("error", "Failed to get node config of %s: %s", node, config); | |
| 131 return; | |
| 132 end | |
| 133 local changed = false; | |
| 129 for config_field, value in pairs(default_options) do | 134 for config_field, value in pairs(default_options) do |
| 130 node_config[config_field] = value; | 135 if node_config[config_field] ~= value then |
| 136 node_config[config_field] = value; | |
| 137 changed = true; | |
| 138 end | |
| 139 end | |
| 140 if not changed then | |
| 141 return; | |
| 142 end | |
| 143 local ok, err = service:set_node_config(node, actor, config); | |
| 144 if not ok then | |
| 145 module:log("error", "Failed to set node config of %s: %s", node, err); | |
| 146 return; | |
| 131 end | 147 end |
| 132 end | 148 end |
| 133 | 149 |
| 134 module:hook("iq/bare/jabber:iq:private:query", function (event) | 150 module:hook("iq/bare/jabber:iq:private:query", function (event) |
| 135 if event.stanza.attr.type == "get" then | 151 if event.stanza.attr.type == "get" then |
