Comparison

util/pubsub.lua @ 11721:7a77f0c05382

util.pubsub: Fix behavior of persist_items disabled When set to 'false' there is no need for a persistence interface at all, since items are not persisted after being broadcast. Had started wondering if maybe the behavior was wrong, after reading parts of XEP-0060 that pointed in that direction. Some discussion of this can be found in logs of xmpp:xsf@muc.xmpp.org?join from around 2021-07-20 Thanks to Ralph for confirming.
author Kim Alvefur <zash@zash.se>
date Thu, 22 Jul 2021 21:01:11 +0200
parent 11720:72512c0858b3
child 11723:3ead0967e04d
comparison
equal deleted inserted replaced
11720:72512c0858b3 11721:7a77f0c05382
175 }, service_mt); 175 }, service_mt);
176 176
177 -- Load nodes from storage, if we have a store and it supports iterating over stored items 177 -- Load nodes from storage, if we have a store and it supports iterating over stored items
178 if config.nodestore and config.nodestore.users then 178 if config.nodestore and config.nodestore.users then
179 for node_name in config.nodestore:users() do 179 for node_name in config.nodestore:users() do
180 service.nodes[node_name] = load_node_from_store(service, node_name); 180 local node = load_node_from_store(service, node_name);
181 service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name); 181 service.nodes[node_name] = node;
182 if node.config.persist_items then
183 service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name);
184 end
182 185
183 for jid in pairs(service.nodes[node_name].subscribers) do 186 for jid in pairs(service.nodes[node_name].subscribers) do
184 local normal_jid = service.config.normalize_jid(jid); 187 local normal_jid = service.config.normalize_jid(jid);
185 local subs = service.subscriptions[normal_jid]; 188 local subs = service.subscriptions[normal_jid];
186 if subs then 189 if subs then
464 self.nodes[node] = nil; 467 self.nodes[node] = nil;
465 return ok, "internal-server-error"; 468 return ok, "internal-server-error";
466 end 469 end
467 end 470 end
468 471
469 self.data[node] = self.config.itemstore(self.nodes[node].config, node); 472 if config.persist_items then
473 self.data[node] = self.config.itemstore(self.nodes[node].config, node);
474 end
475
470 self.events.fire_event("node-created", { service = self, node = node, actor = actor }); 476 self.events.fire_event("node-created", { service = self, node = node, actor = actor });
471 if actor ~= true then 477 if actor ~= true then
472 local ok, err = self:set_affiliation(node, true, actor, "owner"); 478 local ok, err = self:set_affiliation(node, true, actor, "owner");
473 if not ok then 479 if not ok then
474 self.nodes[node] = nil; 480 self.nodes[node] = nil;
562 end 568 end
563 end 569 end
564 if not self.config.itemcheck(item) then 570 if not self.config.itemcheck(item) then
565 return nil, "invalid-item"; 571 return nil, "invalid-item";
566 end 572 end
567 local node_data = self.data[node]; 573 if node_obj.config.persist_items then
568 if node_data then 574 if not self.data[node] then
569 local ok = node_data:set(id, item); 575 self.data[node] = self.config.itemstore(self.nodes[node].config, node);
576 end
577 local ok = self.data[node]:set(id, item);
570 if not ok then 578 if not ok then
571 return nil, "internal-server-error"; 579 return nil, "internal-server-error";
572 end 580 end
573 if type(ok) == "string" then id = ok; end 581 if type(ok) == "string" then id = ok; end
574 end 582 end
814 end 822 end
815 end 823 end
816 end 824 end
817 825
818 if old_config["persist_items"] ~= node_obj.config["persist_items"] then 826 if old_config["persist_items"] ~= node_obj.config["persist_items"] then
819 self.data[node] = self.config.itemstore(self.nodes[node].config, node); 827 if node_obj.config["persist_items"] then
828 self.data[node] = self.config.itemstore(self.nodes[node].config, node);
829 elseif self.data[node] then
830 if self.data[node].clear then
831 self.data[node]:clear()
832 end
833 self.data[node] = nil;
834 end
820 elseif old_config["max_items"] ~= node_obj.config["max_items"] then 835 elseif old_config["max_items"] ~= node_obj.config["max_items"] then
821 if self.data[node] then 836 if self.data[node] then
822 self.data[node]:resize(self.nodes[node].config["max_items"]); 837 self.data[node]:resize(self.nodes[node].config["max_items"]);
823 end 838 end
824 end 839 end