Software /
code /
prosody
Comparison
util/pubsub.lua @ 8950:03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 01 Jul 2018 04:17:36 +0200 |
parent | 8941:f0beba9c2822 |
child | 8951:9baac001fccb |
comparison
equal
deleted
inserted
replaced
8949:9194431b6447 | 8950:03ba5b4f131a |
---|---|
19 }; | 19 }; |
20 local default_node_config_mt = { __index = default_node_config }; | 20 local default_node_config_mt = { __index = default_node_config }; |
21 | 21 |
22 -- Storage helper functions | 22 -- Storage helper functions |
23 | 23 |
24 local function load_node_from_store(nodestore, node_name) | 24 local function load_node_from_store(service, node_name) |
25 local node = nodestore:get(node_name); | 25 local node = service.config.nodestore:get(node_name); |
26 node.config = setmetatable(node.config or {}, default_node_config_mt); | 26 node.config = setmetatable(node.config or {}, {__index=service.node_defaults}); |
27 return node; | 27 return node; |
28 end | 28 end |
29 | 29 |
30 local function save_node_to_store(nodestore, node) | 30 local function save_node_to_store(service, node) |
31 return nodestore:set(node.name, { | 31 return service.config.nodestore:set(node.name, { |
32 name = node.name; | 32 name = node.name; |
33 config = node.config; | 33 config = node.config; |
34 subscribers = node.subscribers; | 34 subscribers = node.subscribers; |
35 affiliations = node.affiliations; | 35 affiliations = node.affiliations; |
36 }); | 36 }); |
51 }, service_mt); | 51 }, service_mt); |
52 | 52 |
53 -- Load nodes from storage, if we have a store and it supports iterating over stored items | 53 -- Load nodes from storage, if we have a store and it supports iterating over stored items |
54 if config.nodestore and config.nodestore.users then | 54 if config.nodestore and config.nodestore.users then |
55 for node_name in config.nodestore:users() do | 55 for node_name in config.nodestore:users() do |
56 service.nodes[node_name] = load_node_from_store(config.nodestore, node_name); | 56 service.nodes[node_name] = load_node_from_store(service, node_name); |
57 service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name); | 57 service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name); |
58 end | 58 end |
59 end | 59 end |
60 | 60 |
61 return service; | 61 return service; |
252 config = setmetatable(options or {}, {__index=self.node_defaults}); | 252 config = setmetatable(options or {}, {__index=self.node_defaults}); |
253 affiliations = {}; | 253 affiliations = {}; |
254 }; | 254 }; |
255 | 255 |
256 if self.config.nodestore then | 256 if self.config.nodestore then |
257 local ok, err = save_node_to_store(self.config.nodestore, self.nodes[node]); | 257 local ok, err = save_node_to_store(self, self.nodes[node]); |
258 if not ok then | 258 if not ok then |
259 self.nodes[node] = nil; | 259 self.nodes[node] = nil; |
260 return ok, err; | 260 return ok, err; |
261 end | 261 end |
262 end | 262 end |