Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 11120:b2331f3dfeea
Merge 0.11->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 09:50:33 +0100 |
parent | 10673:1a23a58ac84e |
child | 11378:b790df8f9448 |
comparison
equal
deleted
inserted
replaced
11119:68df52bf08d5 | 11120:b2331f3dfeea |
---|---|
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"; |
121 end | 122 end |
122 end | 123 end |
123 if kind == "retract" then | 124 if kind == "retract" then |
124 kind = "items"; -- XEP-0060 signals retraction in an <items> container | 125 kind = "items"; -- XEP-0060 signals retraction in an <items> container |
125 end | 126 end |
126 local message = st.message({ from = user_bare, type = "headline" }) | |
127 :tag("event", { xmlns = xmlns_pubsub_event }) | |
128 :tag(kind, { node = node }); | |
129 if item then | 127 if item then |
130 item = st.clone(item); | 128 item = st.clone(item); |
131 item.attr.xmlns = nil; -- Clear the pubsub namespace | 129 item.attr.xmlns = nil; -- Clear the pubsub namespace |
132 if kind == "items" then | 130 if kind == "items" then |
133 if node_obj and node_obj.config.include_payload == false then | 131 if node_obj and node_obj.config.include_payload == false then |
134 item:maptags(function () return nil; end); | 132 item:maptags(function () return nil; end); |
135 end | 133 end |
136 end | 134 end |
135 end | |
136 | |
137 local id = new_id(); | |
138 local message = st.message({ from = user_bare, type = "headline", id = id }) | |
139 :tag("event", { xmlns = xmlns_pubsub_event }) | |
140 :tag(kind, { node = node }); | |
141 | |
142 if item then | |
137 message:add_child(item); | 143 message:add_child(item); |
138 end | 144 end |
145 | |
139 for jid in pairs(jids) do | 146 for jid in pairs(jids) do |
140 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); | 147 module:log("debug", "Sending notification to %s from %s for node %s", jid, user_bare, node); |
141 message.attr.to = jid; | 148 message.attr.to = jid; |
142 module:send(message); | 149 module:send(message); |
143 end | 150 end |
144 end | 151 end |
145 return simple_broadcast; | 152 return simple_broadcast; |
164 return broadcast_to; | 171 return broadcast_to; |
165 end | 172 end |
166 end | 173 end |
167 | 174 |
168 function get_pep_service(username) | 175 function get_pep_service(username) |
169 module:log("debug", "get_pep_service(%q)", username); | |
170 local user_bare = jid_join(username, host); | 176 local user_bare = jid_join(username, host); |
171 local service = services[username]; | 177 local service = services[username]; |
172 if service then | 178 if service then |
173 return service; | 179 return service; |
174 end | 180 end |
181 module:log("debug", "Creating pubsub service for user %q", username); | |
175 service = pubsub.new({ | 182 service = pubsub.new({ |
176 pep_username = username; | 183 pep_username = username; |
177 node_defaults = { | 184 node_defaults = { |
178 ["max_items"] = 1; | 185 ["max_items"] = 1; |
179 ["persist_items"] = true; | 186 ["persist_items"] = true; |
236 end | 243 end |
237 | 244 |
238 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); | 245 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); |
239 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); | 246 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); |
240 | 247 |
241 module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody")); | |
242 module:add_feature("http://jabber.org/protocol/pubsub#publish"); | |
243 | 248 |
244 local function get_caps_hash_from_presence(stanza, current) | 249 local function get_caps_hash_from_presence(stanza, current) |
245 local t = stanza.attr.type; | 250 local t = stanza.attr.type; |
246 if not t then | 251 if not t then |
247 local child = stanza:get_child("c", "http://jabber.org/protocol/caps"); | 252 local child = stanza:get_child("c", "http://jabber.org/protocol/caps"); |