Comparison

plugins/mod_pep.lua @ 10046:0bc291a5734a

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 10 Jun 2019 13:22:22 +0200
parent 10045:6714578cfd6e
parent 10037:e01f38acde74
child 10047:177a8b92204b
comparison
equal deleted inserted replaced
10045:6714578cfd6e 10046:0bc291a5734a
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: %s", jid, user_bare, tostring(item));
156 message.attr.to = jid; 163 message.attr.to = jid;
157 module:send(message); 164 module:send(message);
158 end 165 end
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");