4 local st = require "util.stanza"; |
4 local st = require "util.stanza"; |
5 local hosts = hosts; |
5 local hosts = hosts; |
6 local user_exists = require "core.usermanager".user_exists; |
6 local user_exists = require "core.usermanager".user_exists; |
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
8 local pairs, ipairs = pairs, ipairs; |
8 local pairs, ipairs = pairs, ipairs; |
|
9 local next = next; |
9 local load_roster = require "core.rostermanager".load_roster; |
10 local load_roster = require "core.rostermanager".load_roster; |
10 |
11 |
11 local data = {}; |
12 local data = {}; |
12 local recipients = {}; |
13 local recipients = {}; |
13 |
14 |
14 module:add_identity("pubsub", "pep"); |
15 module:add_identity("pubsub", "pep"); |
15 module:add_feature("http://jabber.org/protocol/pubsub#publish"); |
16 module:add_feature("http://jabber.org/protocol/pubsub#publish"); |
16 |
17 |
17 local function publish(session, node, item) |
18 local function publish(session, node, item) |
|
19 local disable = #item.tags ~= 1 or #item.tags[1].tags == 0; |
18 local stanza = st.message({from=session.full_jid, type='headline'}) |
20 local stanza = st.message({from=session.full_jid, type='headline'}) |
19 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) |
21 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) |
20 :tag('items', {node=node}) |
22 :tag('items', {node=node}) |
21 :add_child(item) |
23 :add_child(item) |
22 :up() |
24 :up() |
23 :up(); |
25 :up(); |
24 |
26 |
25 local bare = session.username..'@'..session.host; |
27 local bare = session.username..'@'..session.host; |
26 -- store for the future |
28 -- store for the future |
27 local user_data = data[bare]; |
29 local user_data = data[bare]; |
28 if not user_data then user_data = {}; data[bare] = user_data; end |
30 if disable then |
29 user_data[node] = stanza; |
31 if user_data then user_data[node] = nil; end |
|
32 if not next(user_data) then data[bare] = nil; end |
|
33 else |
|
34 if not user_data then user_data = {}; data[bare] = user_data; end |
|
35 user_data[node] = stanza; |
|
36 end |
30 |
37 |
31 -- broadcast to resources |
38 -- broadcast to resources |
32 stanza.attr.to = bare; |
39 stanza.attr.to = bare; |
33 core_route_stanza(session, stanza); |
40 core_route_stanza(session, stanza); |
34 |
41 |