Software /
code /
prosody
Annotate
plugins/mod_pep_plus.lua @ 8215:835bb32c36b4
mod_pep_plus: Add item persistency.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 15 Apr 2017 09:35:33 +0100 |
parent | 8214:da8bc600902a |
child | 8218:2c75a5ba58fc |
rev | line source |
---|---|
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 local pubsub = require "util.pubsub"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 local jid_bare = require "util.jid".bare; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 local jid_split = require "util.jid".split; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 local set_new = require "util.set".new; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 local calculate_hash = require "util.caps".calculate_hash; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 local lib_pubsub = module:require "pubsub"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 local handlers = lib_pubsub.handlers; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
16 local empty_set = set_new(); |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
17 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 local services = {}; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 local recipients = {}; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 local hash_map = {}; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 |
8215
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
22 local archive = module:open_store("pubsub", "archive"); |
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
23 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 function module.save() |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 return { services = services }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 function module.restore(data) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 services = data.services; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 local function subscription_presence(user_bare, recipient) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 local recipient_bare = jid_bare(recipient); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 if (recipient_bare == user_bare) then return true; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 local username, host = jid_split(user_bare); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 return is_contact_subscribed(username, host, recipient_bare); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
37 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
38 |
8215
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
39 local function simple_itemstore(config, node) |
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
40 return lib_pubsub.simple_itemstore(archive, config, node, false); |
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
41 end |
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
42 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 local function get_broadcaster(name) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
44 local function simple_broadcast(kind, node, jids, item) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 if item then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
46 item = st.clone(item); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
47 item.attr.xmlns = nil; -- Clear the pubsub namespace |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
48 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
49 local message = st.message({ from = name, type = "headline" }) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
50 :tag("event", { xmlns = xmlns_pubsub_event }) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
51 :tag(kind, { node = node }) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
52 :add_child(item); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
53 for jid in pairs(jids) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
54 module:log("debug", "Sending notification to %s from %s: %s", jid, name, tostring(item)); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
55 message.attr.to = jid; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
56 module:send(message); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
57 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
58 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
59 return simple_broadcast; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
60 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
61 |
6264
12a083299bb7
mod_pep_plus: Expose get_pep_service()
Kim Alvefur <zash@zash.se>
parents:
5852
diff
changeset
|
62 function get_pep_service(name) |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
63 local service = services[name]; |
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
64 if service then |
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
65 return service; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
66 end |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
67 service = pubsub.new({ |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
68 capabilities = { |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
69 none = { |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
70 create = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
71 publish = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 retract = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
73 get_nodes = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
74 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 subscribe = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 unsubscribe = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
77 get_subscription = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 get_subscriptions = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 get_items = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
80 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
81 subscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
82 unsubscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
83 get_subscription_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
84 get_subscriptions_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
85 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
86 be_subscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
87 be_unsubscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
88 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
89 set_affiliation = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
90 }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
91 subscriber = { |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
92 create = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
93 publish = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
94 retract = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
95 get_nodes = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
96 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
97 subscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
98 unsubscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
99 get_subscription = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
100 get_subscriptions = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
101 get_items = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
102 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
103 subscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
104 unsubscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
105 get_subscription_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
106 get_subscriptions_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
108 be_subscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
109 be_unsubscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
110 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
111 set_affiliation = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
112 }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
113 publisher = { |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
114 create = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
115 publish = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
116 retract = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
117 get_nodes = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
118 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
119 subscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
120 unsubscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
121 get_subscription = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
122 get_subscriptions = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
123 get_items = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
124 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
125 subscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
126 unsubscribe_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
127 get_subscription_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
128 get_subscriptions_other = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
129 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
130 be_subscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
131 be_unsubscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
132 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
133 set_affiliation = false; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
134 }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
135 owner = { |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
136 create = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
137 publish = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 retract = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 delete = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
140 get_nodes = true; |
6443
f4403c270ea2
mod_pep_plus: Add node config form
Kim Alvefur <zash@zash.se>
parents:
6432
diff
changeset
|
141 configure = true; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
142 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
143 subscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 unsubscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
145 get_subscription = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 get_subscriptions = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 get_items = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
150 subscribe_other = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
151 unsubscribe_other = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
152 get_subscription_other = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
153 get_subscriptions_other = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
154 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 be_subscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
156 be_unsubscribed = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
157 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
158 set_affiliation = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
159 }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
160 }; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 |
6444
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
162 node_defaults = { |
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
163 ["pubsub#max_items"] = "1"; |
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
164 }; |
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
165 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
166 autocreate_on_publish = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
167 autocreate_on_subscribe = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
168 |
8215
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
169 itemstore = simple_itemstore; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
170 broadcaster = get_broadcaster(name); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 get_affiliation = function (jid) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
172 if jid_bare(jid) == name then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 return "owner"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
174 elseif subscription_presence(name, jid) then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 return "subscriber"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
176 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
177 end; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
178 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 normalize_jid = jid_bare; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 }); |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
181 services[name] = service; |
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
182 module:add_item("pep-service", { service = service, jid = name }); |
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
183 return service; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
184 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
185 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
186 function handle_pubsub_iq(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
187 local origin, stanza = event.origin, event.stanza; |
8214
da8bc600902a
mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6449
diff
changeset
|
188 local pubsub_tag = stanza.tags[1]; |
da8bc600902a
mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6449
diff
changeset
|
189 local action = pubsub_tag.tags[1]; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
190 if not action then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
191 return origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
192 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
193 local service_name = stanza.attr.to or origin.username.."@"..origin.host |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 local service = get_pep_service(service_name); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
195 local handler = handlers[stanza.attr.type.."_"..action.name]; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
196 if handler then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
197 handler(origin, stanza, action, service); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
198 return true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
199 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
201 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
202 module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
203 module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
204 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody")); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
206 module:add_feature("http://jabber.org/protocol/pubsub#publish"); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
207 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
208 local function get_caps_hash_from_presence(stanza, current) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
209 local t = stanza.attr.type; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
210 if not t then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
211 local child = stanza:get_child("c", "http://jabber.org/protocol/caps"); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
212 if child then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
213 local attr = child.attr; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
214 if attr.hash then -- new caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
215 if attr.hash == 'sha-1' and attr.node and attr.ver then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
216 return attr.ver, attr.node.."#"..attr.ver; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
217 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
218 else -- legacy caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
219 if attr.node and attr.ver then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
220 return attr.node.."#"..attr.ver.."#"..(attr.ext or ""), attr.node.."#"..attr.ver; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
221 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
222 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
224 return; -- no or bad caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 elseif t == "unavailable" or t == "error" then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 return; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
227 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
228 return current; -- no caps, could mean caps optimization, so return current |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
230 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
231 local function resend_last_item(jid, node, service) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
232 local ok, items = service:get_items(node, jid); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
233 if not ok then return; end |
8214
da8bc600902a
mod_pep_plus: Fix all of the warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6449
diff
changeset
|
234 for _, id in ipairs(items) do |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
235 service.config.broadcaster("items", node, { [jid] = true }, items[id]); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
236 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
237 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
238 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
239 local function update_subscriptions(recipient, service_name, nodes) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 local service = get_pep_service(service_name); |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
241 nodes = nodes or empty_set; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
242 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
243 local service_recipients = recipients[service_name]; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
244 if not service_recipients then |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
245 service_recipients = {}; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
246 recipients[service_name] = service_recipients; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
247 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
249 local current = service_recipients[recipient]; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
250 if not current or type(current) ~= "table" then |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
251 current = empty_set; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
252 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
253 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
254 if (current == empty_set or current:empty()) and (nodes == empty_set or nodes:empty()) then |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
255 return; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
256 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
257 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
258 for node in current - nodes do |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
259 service:remove_subscription(node, recipient, recipient); |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
260 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
261 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
262 for node in nodes - current do |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
263 service:add_subscription(node, recipient, recipient); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
264 resend_last_item(recipient, node, service); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
265 end |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
266 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
267 if nodes == empty_set or nodes:empty() then |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
268 nodes = nil; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
269 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
270 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
271 service_recipients[recipient] = nodes; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
272 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
273 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
274 module:hook("presence/bare", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
275 -- inbound presence to bare JID recieved |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
276 local origin, stanza = event.origin, event.stanza; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
277 local user = stanza.attr.to or (origin.username..'@'..origin.host); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
278 local t = stanza.attr.type; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
279 local self = not stanza.attr.to; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
280 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
281 if not t then -- available presence |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
282 if self or subscription_presence(user, stanza.attr.from) then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
283 local recipient = stanza.attr.from; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 local current = recipients[user] and recipients[user][recipient]; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
285 local hash, query_node = get_caps_hash_from_presence(stanza, current); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
286 if current == hash or (current and current == hash_map[hash]) then return; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
287 if not hash then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
288 update_subscriptions(recipient, user); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
289 else |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
290 recipients[user] = recipients[user] or {}; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
291 if hash_map[hash] then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
292 update_subscriptions(recipient, user, hash_map[hash]); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
293 else |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 recipients[user][recipient] = hash; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
296 if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
297 -- COMPAT from ~= stanza.attr.to because OneTeam can't deal with missing from attribute |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
298 origin.send( |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
299 st.stanza("iq", {from=user, to=stanza.attr.from, id="disco", type="get"}) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
300 :tag("query", {xmlns = "http://jabber.org/protocol/disco#info", node = query_node}) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
301 ); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
302 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
303 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
304 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
305 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
306 elseif t == "unavailable" then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
307 update_subscriptions(stanza.attr.from, user); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
308 elseif not self and t == "unsubscribe" then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
309 local from = jid_bare(stanza.attr.from); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
310 local subscriptions = recipients[user]; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
311 if subscriptions then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
312 for subscriber in pairs(subscriptions) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
313 if jid_bare(subscriber) == from then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
314 update_subscriptions(subscriber, user); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
315 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
316 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
317 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
318 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
319 end, 10); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
320 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
321 module:hook("iq-result/bare/disco", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
322 local origin, stanza = event.origin, event.stanza; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
323 local disco = stanza:get_child("query", "http://jabber.org/protocol/disco#info"); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
324 if not disco then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
325 return; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
326 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
327 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
328 -- Process disco response |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
329 local self = not stanza.attr.to; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
330 local user = stanza.attr.to or (origin.username..'@'..origin.host); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
331 local contact = stanza.attr.from; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
332 local current = recipients[user] and recipients[user][contact]; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
333 if type(current) ~= "string" then return; end -- check if waiting for recipient's response |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
334 local ver = current; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
335 if not string.find(current, "#") then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
336 ver = calculate_hash(disco.tags); -- calculate hash |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
337 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
338 local notify = set_new(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
339 for _, feature in pairs(disco.tags) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
340 if feature.name == "feature" and feature.attr.var then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
341 local nfeature = feature.attr.var:match("^(.*)%+notify$"); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
342 if nfeature then notify:add(nfeature); end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
343 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
344 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
345 hash_map[ver] = notify; -- update hash map |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
346 if self then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
347 for jid, item in pairs(origin.roster) do -- for all interested contacts |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
348 if item.subscription == "both" or item.subscription == "from" then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
349 if not recipients[jid] then recipients[jid] = {}; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
350 update_subscriptions(contact, jid, notify); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
351 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
352 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
353 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
354 update_subscriptions(contact, user, notify); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
355 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
356 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
357 module:hook("account-disco-info-node", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
358 local reply, stanza, origin = event.reply, event.stanza, event.origin; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
359 local service_name = stanza.attr.to or origin.username.."@"..origin.host |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
360 local service = get_pep_service(service_name); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
361 local node = event.node; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
362 local ok = service:get_items(node, jid_bare(stanza.attr.from) or true); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
363 if not ok then return; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
364 event.exists = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
365 reply:tag('identity', {category='pubsub', type='leaf'}):up(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
366 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
367 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
368 module:hook("account-disco-info", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
369 local reply = event.reply; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
370 reply:tag('identity', {category='pubsub', type='pep'}):up(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
371 reply:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
372 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
373 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
374 module:hook("account-disco-items-node", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
375 local reply, stanza, origin = event.reply, event.stanza, event.origin; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
376 local node = event.node; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
377 local service_name = stanza.attr.to or origin.username.."@"..origin.host |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
378 local service = get_pep_service(service_name); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
379 local ok, ret = service:get_items(node, jid_bare(stanza.attr.from) or true); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
380 if not ok then return; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
381 event.exists = true; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
382 for _, id in ipairs(ret) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
383 reply:tag("item", { jid = service_name, name = id }):up(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
384 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
385 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
386 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
387 module:hook("account-disco-items", function(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
388 local reply, stanza, origin = event.reply, event.stanza, event.origin; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
389 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
390 local service_name = reply.attr.from or origin.username.."@"..origin.host |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
391 local service = get_pep_service(service_name); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
392 local ok, ret = service:get_nodes(jid_bare(stanza.attr.from)); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
393 if not ok then return; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
394 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
395 for node, node_obj in pairs(ret) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
396 reply:tag("item", { jid = service_name, node = node, name = node_obj.config.name }):up(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
397 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
398 end); |