comparison plugins/mod_pubsub/pubsub.lib.lua @ 11631:6641ca266d94

mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items' Fixes #1643 API change: The argument to archive_itemstore() changes type to integer
author Kim Alvefur <zash@zash.se>
date Wed, 09 Jun 2021 15:58:49 +0200
parents ef623d719894
children d783716103c1
comparison
equal deleted inserted replaced
11630:855b065d5fd6 11631:6641ca266d94
81 var = "pubsub#type"; 81 var = "pubsub#type";
82 label = "The type of node data, usually specified by the namespace of the payload (if any)"; 82 label = "The type of node data, usually specified by the namespace of the payload (if any)";
83 }; 83 };
84 { 84 {
85 type = "text-single"; 85 type = "text-single";
86 datatype = "xs:integer"; 86 datatype = "pubsub:integer-or-max";
87 name = "max_items"; 87 name = "max_items";
88 var = "pubsub#max_items"; 88 var = "pubsub#max_items";
89 label = "Max # of items to persist"; 89 label = "Max # of items to persist";
90 }; 90 };
91 { 91 {
799 local item = st.stanza("item", { id = id, xmlns = xmlns_pubsub }); 799 local item = st.stanza("item", { id = id, xmlns = xmlns_pubsub });
800 item:add_child(payload); 800 item:add_child(payload);
801 return item; 801 return item;
802 end 802 end
803 803
804 local function archive_itemstore(archive, config, user, node) 804 local function archive_itemstore(archive, max_items, user, node)
805 module:log("debug", "Creation of archive itemstore for node %s with config %q", node, config); 805 module:log("debug", "Creation of archive itemstore for node %s with limit %d", node, max_items);
806 local get_set = {}; 806 local get_set = {};
807 local max_items = config["max_items"];
808 function get_set:items() -- luacheck: ignore 212/self 807 function get_set:items() -- luacheck: ignore 212/self
809 local data, err = archive:find(user, { 808 local data, err = archive:find(user, {
810 limit = tonumber(max_items); 809 limit = tonumber(max_items);
811 reverse = true; 810 reverse = true;
812 }); 811 });