comparison plugins/mod_pep_plus.lua @ 8320:fe5eaf4ed631

mod_pep_plus: Make node persistence configurable via pubsub#persist_items
author Kim Alvefur <zash@zash.se>
date Thu, 12 Oct 2017 01:37:35 +0200
parents 57e3ad11f3f6
children 73ff49a42ea8
comparison
equal deleted inserted replaced
8319:57e3ad11f3f6 8320:fe5eaf4ed631
4 local jid_join = require "util.jid".join; 4 local jid_join = require "util.jid".join;
5 local set_new = require "util.set".new; 5 local set_new = require "util.set".new;
6 local st = require "util.stanza"; 6 local st = require "util.stanza";
7 local calculate_hash = require "util.caps".calculate_hash; 7 local calculate_hash = require "util.caps".calculate_hash;
8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; 8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
9 local cache = require "util.cache";
9 10
10 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; 11 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
11 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; 12 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
12 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 13 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
13 14
40 return is_contact_subscribed(username, host, recipient_bare); 41 return is_contact_subscribed(username, host, recipient_bare);
41 end 42 end
42 43
43 local function simple_itemstore(username) 44 local function simple_itemstore(username)
44 return function (config, node) 45 return function (config, node)
45 module:log("debug", "new simple_itemstore(%q, %q)", username, node); 46 if config["pubsub#persist_items"] then
46 known_nodes_map:set(username, node, true); 47 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
47 local archive = module:open_store("pep_"..node, "archive"); 48 known_nodes_map:set(username, node, true);
48 return lib_pubsub.archive_itemstore(archive, config, username, node, false); 49 local archive = module:open_store("pep_"..node, "archive");
50 return lib_pubsub.archive_itemstore(archive, config, username, node, false);
51 else
52 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
53 known_nodes_map:set(username, node, nil);
54 return cache.new(tonumber(config["pubsub#max_items"]));
55 end
49 end 56 end
50 end 57 end
51 58
52 local function get_broadcaster(username) 59 local function get_broadcaster(username)
53 local user_bare = jid_join(username, host); 60 local user_bare = jid_join(username, host);
171 }; 178 };
172 }; 179 };
173 180
174 node_defaults = { 181 node_defaults = {
175 ["pubsub#max_items"] = "1"; 182 ["pubsub#max_items"] = "1";
183 ["pubsub#persist_items"] = true;
176 }; 184 };
177 185
178 autocreate_on_publish = true; 186 autocreate_on_publish = true;
179 autocreate_on_subscribe = true; 187 autocreate_on_subscribe = true;
180 188