Comparison

plugins/mod_pubsub/mod_pubsub.lua @ 11200:bf8f2da84007

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 05 Nov 2020 22:31:25 +0100
parent 11188:8a29e7206917
parent 11199:6c7c50a4de32
child 11202:58492b4b85ea
comparison
equal deleted inserted replaced
11199:6c7c50a4de32 11200:bf8f2da84007
40 -- users(): iterator over (node_name) 40 -- users(): iterator over (node_name)
41 41
42 42
43 local node_store = module:open_store(module.name.."_nodes"); 43 local node_store = module:open_store(module.name.."_nodes");
44 44
45 local function create_simple_itemstore(node_config, node_name) 45 local function create_simple_itemstore(node_config, node_name) --> util.cache like object
46 local driver = storagemanager.get_driver(module.host, "pubsub_data"); 46 local driver = storagemanager.get_driver(module.host, "pubsub_data");
47 local archive = driver:open("pubsub_"..node_name, "archive"); 47 local archive = driver:open("pubsub_"..node_name, "archive");
48 return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name); 48 return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name);
49 end 49 end
50 50
73 73
74 local id = new_id(); 74 local id = new_id();
75 local msg_type = node_obj and node_obj.config.message_type or "headline"; 75 local msg_type = node_obj and node_obj.config.message_type or "headline";
76 local message = st.message({ from = module.host, type = msg_type, id = id }) 76 local message = st.message({ from = module.host, type = msg_type, id = id })
77 :tag("event", { xmlns = xmlns_pubsub_event }) 77 :tag("event", { xmlns = xmlns_pubsub_event })
78 :tag(kind, { node = node }) 78 :tag(kind, { node = node });
79 79
80 if item then 80 if item then
81 message:add_child(item); 81 message:add_child(item);
82 end 82 end
83 83
84 local summary; 84 local summary;
85 -- Compose a sensible textual representation of at least Atom payloads
86 if item and item.tags[1] then 85 if item and item.tags[1] then
87 local payload = item.tags[1]; 86 local payload = item.tags[1];
88 summary = module:fire_event("pubsub-summary/"..payload.attr.xmlns, { 87 summary = module:fire_event("pubsub-summary/"..payload.attr.xmlns, {
89 kind = kind, node = node, jids = jids, actor = actor, item = item, payload = payload, 88 kind = kind, node = node, jids = jids, actor = actor, item = item, payload = payload,
90 }); 89 });
99 module:send(new_stanza); 98 module:send(new_stanza);
100 end 99 end
101 end 100 end
102 101
103 local max_max_items = module:get_option_number("pubsub_max_items", 256); 102 local max_max_items = module:get_option_number("pubsub_max_items", 256);
104 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/actor 212/node 103 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor
105 if (new_config["max_items"] or 1) > max_max_items then 104 if (new_config["max_items"] or 1) > max_max_items then
106 return false; 105 return false;
107 end 106 end
108 if new_config["access_model"] ~= "whitelist" and new_config["access_model"] ~= "open" then 107 if new_config["access_model"] ~= "whitelist"
108 and new_config["access_model"] ~= "open" then
109 return false; 109 return false;
110 end 110 end
111 return true; 111 return true;
112 end 112 end
113 113
114 function is_item_stanza(item) 114 function is_item_stanza(item)
115 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; 115 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1;
116 end 116 end
117 117
118 -- Compose a textual representation of Atom payloads
118 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event) 119 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event)
119 local payload = event.payload; 120 local payload = event.payload;
120 local title = payload:get_child_text("title"); 121 local title = payload:get_child_text("title");
121 local summary = payload:get_child_text("summary"); 122 local summary = payload:get_child_text("summary");
122 if not summary and title then 123 if not summary and title then