comparison plugins/mod_pep.lua @ 10411:db2a06b9ff98

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 16 Nov 2019 16:52:31 +0100
parents 216ae100c04a
children cbb2c3f8bb1d
comparison
equal deleted inserted replaced
10410:659b577f280c 10411:db2a06b9ff98
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 local cache = require "util.cache";
10 local set = require "util.set"; 10 local set = require "util.set";
11 local new_id = require "util.id".medium;
11 local storagemanager = require "core.storagemanager"; 12 local storagemanager = require "core.storagemanager";
12 13
13 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; 14 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
14 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; 15 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
15 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 16 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
136 end 137 end
137 end 138 end
138 if kind == "retract" then 139 if kind == "retract" then
139 kind = "items"; -- XEP-0060 signals retraction in an <items> container 140 kind = "items"; -- XEP-0060 signals retraction in an <items> container
140 end 141 end
141 local message = st.message({ from = user_bare, type = "headline" })
142 :tag("event", { xmlns = xmlns_pubsub_event })
143 :tag(kind, { node = node });
144 if item then 142 if item then
145 item = st.clone(item); 143 item = st.clone(item);
146 item.attr.xmlns = nil; -- Clear the pubsub namespace 144 item.attr.xmlns = nil; -- Clear the pubsub namespace
147 if kind == "items" then 145 if kind == "items" then
148 if node_obj and node_obj.config.include_payload == false then 146 if node_obj and node_obj.config.include_payload == false then
149 item:maptags(function () return nil; end); 147 item:maptags(function () return nil; end);
150 end 148 end
151 end 149 end
150 end
151
152 local id = new_id();
153 local message = st.message({ from = user_bare, type = "headline", id = id })
154 :tag("event", { xmlns = xmlns_pubsub_event })
155 :tag(kind, { node = node });
156
157 if item then
152 message:add_child(item); 158 message:add_child(item);
153 end 159 end
160
154 for jid in pairs(jids) do 161 for jid in pairs(jids) do
155 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); 162 module:log("debug", "Sending notification to %s from %s for node %s", jid, user_bare, node);
156 message.attr.to = jid; 163 message.attr.to = jid;
157 module:send(message); 164 module:send(message);
158 end 165 end
159 end 166 end
160 return simple_broadcast; 167 return simple_broadcast;
174 end 181 end
175 end 182 end
176 end 183 end
177 184
178 function get_pep_service(username) 185 function get_pep_service(username)
179 module:log("debug", "get_pep_service(%q)", username);
180 local user_bare = jid_join(username, host); 186 local user_bare = jid_join(username, host);
181 local service = services[username]; 187 local service = services[username];
182 if service then 188 if service then
183 return service; 189 return service;
184 end 190 end
191 module:log("debug", "Creating pubsub service for user %q", username);
185 service = pubsub.new({ 192 service = pubsub.new({
186 pep_username = username; 193 pep_username = username;
187 node_defaults = { 194 node_defaults = {
188 ["max_items"] = 1; 195 ["max_items"] = 1;
189 ["persist_items"] = true; 196 ["persist_items"] = true;
250 end 257 end
251 258
252 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); 259 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
253 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); 260 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
254 261
255 module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody"));
256 module:add_feature("http://jabber.org/protocol/pubsub#publish");
257 262
258 local function get_caps_hash_from_presence(stanza, current) 263 local function get_caps_hash_from_presence(stanza, current)
259 local t = stanza.attr.type; 264 local t = stanza.attr.type;
260 if not t then 265 if not t then
261 local child = stanza:get_child("c", "http://jabber.org/protocol/caps"); 266 local child = stanza:get_child("c", "http://jabber.org/protocol/caps");