Software /
code /
prosody
Annotate
plugins/mod_pep.lua @ 13114:025c38ee885d
util.dependencies: Print tables itself to reduce number of imports
Rationale: See diffstat
When this module is imported, it ends up calling stty via term_width()
in util.human.io.table(). When this happens outside of a terminal, the
following message is sent to stdout:
stty: 'standard input': Inappropriate ioctl for device
Not importing this module avoids that.
Furthermore three is value in this module having minimal dependencies as
they might not be available when it does the checks.
Ref a1fed82c44b9
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 26 May 2023 21:18:27 +0200 |
parent | 12977:74b9e05af71e |
child | 13213:50324f66ca2a |
rev | line source |
---|---|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
1 local pubsub = require "prosody.util.pubsub"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
2 local jid_bare = require "prosody.util.jid".bare; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
3 local jid_split = require "prosody.util.jid".split; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
4 local jid_join = require "prosody.util.jid".join; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
5 local set_new = require "prosody.util.set".new; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
6 local st = require "prosody.util.stanza"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
7 local calculate_hash = require "prosody.util.caps".calculate_hash; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
8 local is_contact_subscribed = require "prosody.core.rostermanager".is_contact_subscribed; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
9 local cache = require "prosody.util.cache"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
10 local set = require "prosody.util.set"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
11 local new_id = require "prosody.util.id".medium; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
12 local storagemanager = require "prosody.core.storagemanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12962
diff
changeset
|
13 local usermanager = require "prosody.core.usermanager"; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 local lib_pubsub = module:require "pubsub"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
21 local empty_set = set_new(); |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
22 |
12086
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
23 -- username -> object passed to module:add_items() |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
24 local pep_service_items = {}; |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
25 |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
26 -- size of caches with full pubsub service objects |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
27 local service_cache_size = module:get_option_number("pep_service_cache_size", 1000); |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
28 |
9113
74639d606a15
mod_pep: Add comments describing root tables used for data
Kim Alvefur <zash@zash.se>
parents:
9103
diff
changeset
|
29 -- username -> util.pubsub service object |
12086
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
30 local services = cache.new(service_cache_size, function (username, _) |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
31 local item = pep_service_items[username]; |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
32 pep_service_items[username] = nil; |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
33 if item then |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
34 module:remove_item("pep-service", item); |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
35 end |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
36 end):table(); |
9113
74639d606a15
mod_pep: Add comments describing root tables used for data
Kim Alvefur <zash@zash.se>
parents:
9103
diff
changeset
|
37 |
12087
19f67d44ec37
mod_pep: Limit possible growth of node subscription info
Kim Alvefur <zash@zash.se>
parents:
12086
diff
changeset
|
38 -- size of caches with smaller objects |
19f67d44ec37
mod_pep: Limit possible growth of node subscription info
Kim Alvefur <zash@zash.se>
parents:
12086
diff
changeset
|
39 local info_cache_size = module:get_option_number("pep_info_cache_size", 10000); |
19f67d44ec37
mod_pep: Limit possible growth of node subscription info
Kim Alvefur <zash@zash.se>
parents:
12086
diff
changeset
|
40 |
9142
85bc624b8685
mod_pep: Correct comment about 'recipients' table
Kim Alvefur <zash@zash.se>
parents:
9141
diff
changeset
|
41 -- username -> recipient -> set of nodes |
12087
19f67d44ec37
mod_pep: Limit possible growth of node subscription info
Kim Alvefur <zash@zash.se>
parents:
12086
diff
changeset
|
42 local recipients = cache.new(info_cache_size):table(); |
9143
817f666d9037
mod_pep: Add comment about 'hash_map' table
Kim Alvefur <zash@zash.se>
parents:
9142
diff
changeset
|
43 |
817f666d9037
mod_pep: Add comment about 'hash_map' table
Kim Alvefur <zash@zash.se>
parents:
9142
diff
changeset
|
44 -- caps hash -> set of nodes |
12087
19f67d44ec37
mod_pep: Limit possible growth of node subscription info
Kim Alvefur <zash@zash.se>
parents:
12086
diff
changeset
|
45 local hash_map = cache.new(info_cache_size):table(); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
46 |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
47 local host = module.host; |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
48 |
8949
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
49 local node_config = module:open_store("pep", "map"); |
8306
202b9951b037
mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents:
8305
diff
changeset
|
50 local known_nodes = module:open_store("pep"); |
202b9951b037
mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents:
8305
diff
changeset
|
51 |
9077
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
52 local max_max_items = module:get_option_number("pep_max_items", 256); |
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
53 |
11631
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
54 local function tonumber_max_items(n) |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
55 if n == "max" then |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
56 return max_max_items; |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
57 end |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
58 return tonumber(n); |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
59 end |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
60 |
11856
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
61 for _, field in ipairs(lib_pubsub.node_config_form) do |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
62 if field.var == "pubsub#max_items" then |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
63 field.range_max = max_max_items; |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
64 break; |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
65 end |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
66 end |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11854
diff
changeset
|
67 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
68 function module.save() |
9141
c1368fb756bf
mod_pep: Pass 'recipients' table across module reloads
Kim Alvefur <zash@zash.se>
parents:
9140
diff
changeset
|
69 return { |
c1368fb756bf
mod_pep: Pass 'recipients' table across module reloads
Kim Alvefur <zash@zash.se>
parents:
9140
diff
changeset
|
70 recipients = recipients; |
c1368fb756bf
mod_pep: Pass 'recipients' table across module reloads
Kim Alvefur <zash@zash.se>
parents:
9140
diff
changeset
|
71 }; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
73 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
74 function module.restore(data) |
9141
c1368fb756bf
mod_pep: Pass 'recipients' table across module reloads
Kim Alvefur <zash@zash.se>
parents:
9140
diff
changeset
|
75 recipients = data.recipients; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
77 |
8696
164da3186511
mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8377
diff
changeset
|
78 function is_item_stanza(item) |
10672
657e61531b33
mod_pubsub, mod_pep: Ensure correct number of children of <item/> (fixes #1496)
Kim Alvefur <zash@zash.se>
parents:
10520
diff
changeset
|
79 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; |
8696
164da3186511
mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8377
diff
changeset
|
80 end |
164da3186511
mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8377
diff
changeset
|
81 |
9080
1b21f8ffaec8
mod_pep: Silence warnings about unused arguments [luacheck]
Kim Alvefur <zash@zash.se>
parents:
9077
diff
changeset
|
82 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor |
11631
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
83 if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then |
9077
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
84 return false; |
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
85 end |
9103
d5a7d2697b19
mod_pep: Restrict access models to 'presence', 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9099
diff
changeset
|
86 if new_config["access_model"] ~= "presence" |
d5a7d2697b19
mod_pep: Restrict access models to 'presence', 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9099
diff
changeset
|
87 and new_config["access_model"] ~= "whitelist" |
d5a7d2697b19
mod_pep: Restrict access models to 'presence', 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9099
diff
changeset
|
88 and new_config["access_model"] ~= "open" then |
d5a7d2697b19
mod_pep: Restrict access models to 'presence', 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9099
diff
changeset
|
89 return false; |
d5a7d2697b19
mod_pep: Restrict access models to 'presence', 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9099
diff
changeset
|
90 end |
9082
297a06074175
mod_pep: Return true if all node config checks passes (fixes configuration)
Kim Alvefur <zash@zash.se>
parents:
9080
diff
changeset
|
91 return true; |
9077
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
92 end |
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
93 |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
94 local function subscription_presence(username, recipient) |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
95 local user_bare = jid_join(username, host); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
96 local recipient_bare = jid_bare(recipient); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
97 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
|
98 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
|
99 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
100 |
8949
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
101 local function nodestore(username) |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
102 -- luacheck: ignore 212/self |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
103 local store = {}; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
104 function store:get(node) |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
105 local data, err = node_config:get(username, node) |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
106 if data == true then |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
107 -- COMPAT Previously stored only a boolean representing 'persist_items' |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
108 data = { |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
109 name = node; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
110 config = {}; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
111 subscribers = {}; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
112 affiliations = {}; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
113 }; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
114 end |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
115 return data, err; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
116 end |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
117 function store:set(node, data) |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
118 return node_config:set(username, node, data); |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
119 end |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
120 function store:users() |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
121 return pairs(known_nodes:get(username) or {}); |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
122 end |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
123 return store; |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
124 end |
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
125 |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
126 local function simple_itemstore(username) |
9827
fd8aaab6669c
mod_pep: Simplify configuration for node data (fixes #1320)
Kim Alvefur <zash@zash.se>
parents:
9597
diff
changeset
|
127 local driver = storagemanager.get_driver(module.host, "pep_data"); |
8218
2c75a5ba58fc
mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents:
8215
diff
changeset
|
128 return function (config, node) |
11631
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
129 local max_items = tonumber_max_items(config["max_items"]); |
11722
bc2d3f110a39
mod_pep: Remove use of RLU cache when persist_items was set to false
Kim Alvefur <zash@zash.se>
parents:
11631
diff
changeset
|
130 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node); |
bc2d3f110a39
mod_pep: Remove use of RLU cache when persist_items was set to false
Kim Alvefur <zash@zash.se>
parents:
11631
diff
changeset
|
131 local archive = driver:open("pep_"..node, "archive"); |
bc2d3f110a39
mod_pep: Remove use of RLU cache when persist_items was set to false
Kim Alvefur <zash@zash.se>
parents:
11631
diff
changeset
|
132 return lib_pubsub.archive_itemstore(archive, max_items, username, node, false); |
8218
2c75a5ba58fc
mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents:
8215
diff
changeset
|
133 end |
8215
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
134 end |
835bb32c36b4
mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8214
diff
changeset
|
135 |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
136 local function get_broadcaster(username) |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
137 local user_bare = jid_join(username, host); |
9189
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
138 local function simple_broadcast(kind, node, jids, item, _, node_obj) |
12960
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
139 local expose_publisher; |
9189
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
140 if node_obj then |
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
141 if node_obj.config["notify_"..kind] == false then |
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
142 return; |
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
143 end |
12960
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
144 if node_obj.config.itemreply == "publisher" then |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
145 expose_publisher = true; |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
146 end |
9189
8fadd3d6c8d3
mod_pep: Respect settings for which kinds of notifications to send
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
147 end |
9179
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9160
diff
changeset
|
148 if kind == "retract" then |
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9160
diff
changeset
|
149 kind = "items"; -- XEP-0060 signals retraction in an <items> container |
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9160
diff
changeset
|
150 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
151 if item then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
152 item = st.clone(item); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
153 item.attr.xmlns = nil; -- Clear the pubsub namespace |
9190
b88f537163da
mod_pep: Respect setting for whether to include payload in notifications
Kim Alvefur <zash@zash.se>
parents:
9189
diff
changeset
|
154 if kind == "items" then |
b88f537163da
mod_pep: Respect setting for whether to include payload in notifications
Kim Alvefur <zash@zash.se>
parents:
9189
diff
changeset
|
155 if node_obj and node_obj.config.include_payload == false then |
b88f537163da
mod_pep: Respect setting for whether to include payload in notifications
Kim Alvefur <zash@zash.se>
parents:
9189
diff
changeset
|
156 item:maptags(function () return nil; end); |
b88f537163da
mod_pep: Respect setting for whether to include payload in notifications
Kim Alvefur <zash@zash.se>
parents:
9189
diff
changeset
|
157 end |
12960
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
158 if not expose_publisher then |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
159 item.attr.publisher = nil; |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12260
diff
changeset
|
160 end |
9190
b88f537163da
mod_pep: Respect setting for whether to include payload in notifications
Kim Alvefur <zash@zash.se>
parents:
9189
diff
changeset
|
161 end |
9721
233305015373
mod_pep: Move broadcaster code around to be more like in mod_pubsub
Kim Alvefur <zash@zash.se>
parents:
9607
diff
changeset
|
162 end |
233305015373
mod_pep: Move broadcaster code around to be more like in mod_pubsub
Kim Alvefur <zash@zash.se>
parents:
9607
diff
changeset
|
163 |
9723
3c6e266391a2
mod_pep: Set an 'id' on notifications
Kim Alvefur <zash@zash.se>
parents:
9722
diff
changeset
|
164 local id = new_id(); |
3c6e266391a2
mod_pep: Set an 'id' on notifications
Kim Alvefur <zash@zash.se>
parents:
9722
diff
changeset
|
165 local message = st.message({ from = user_bare, type = "headline", id = id }) |
9721
233305015373
mod_pep: Move broadcaster code around to be more like in mod_pubsub
Kim Alvefur <zash@zash.se>
parents:
9607
diff
changeset
|
166 :tag("event", { xmlns = xmlns_pubsub_event }) |
233305015373
mod_pep: Move broadcaster code around to be more like in mod_pubsub
Kim Alvefur <zash@zash.se>
parents:
9607
diff
changeset
|
167 :tag(kind, { node = node }); |
9722
695fae2e16b2
mod_pep: Add some spacing between blocks in broadcaster to improve readability
Kim Alvefur <zash@zash.se>
parents:
9721
diff
changeset
|
168 |
9721
233305015373
mod_pep: Move broadcaster code around to be more like in mod_pubsub
Kim Alvefur <zash@zash.se>
parents:
9607
diff
changeset
|
169 if item then |
8895
d00ea07de9a0
mod_pep_plus: Prevent nil from being added as a child on item deletion.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8753
diff
changeset
|
170 message:add_child(item); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 end |
10036
045209b41b3a
mod_pep: Handle presence based subscription outside of util.pubsub (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
9827
diff
changeset
|
172 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 for jid in pairs(jids) do |
10047
177a8b92204b
mod_pep: Log node name instead of payload
Kim Alvefur <zash@zash.se>
parents:
10046
diff
changeset
|
174 module:log("debug", "Sending notification to %s from %s for node %s", jid, user_bare, node); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 message.attr.to = jid; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
176 module:send(message); |
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 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 return simple_broadcast; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
181 |
10520
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
182 local function get_subscriber_filter(username) |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
183 return function (jids, node) |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
184 local broadcast_to = {}; |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
185 for jid, opts in pairs(jids) do |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
186 broadcast_to[jid] = opts; |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
187 end |
10045
6714578cfd6e
mod_pep: Revert 045209b41b3a, caused a regression
Kim Alvefur <zash@zash.se>
parents:
10036
diff
changeset
|
188 |
10520
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
189 local service_recipients = recipients[username]; |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
190 if service_recipients then |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
191 local service = services[username]; |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
192 for recipient, nodes in pairs(service_recipients) do |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
193 if nodes:contains(node) and service:may(node, recipient, "subscribe") then |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
194 broadcast_to[recipient] = true; |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
195 end |
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
196 end |
10045
6714578cfd6e
mod_pep: Revert 045209b41b3a, caused a regression
Kim Alvefur <zash@zash.se>
parents:
10036
diff
changeset
|
197 end |
10520
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
198 return broadcast_to; |
10045
6714578cfd6e
mod_pep: Revert 045209b41b3a, caused a regression
Kim Alvefur <zash@zash.se>
parents:
10036
diff
changeset
|
199 end |
6714578cfd6e
mod_pep: Revert 045209b41b3a, caused a regression
Kim Alvefur <zash@zash.se>
parents:
10036
diff
changeset
|
200 end |
9542
b8bfcfbe5126
mod_pep: Add automatic subscriptions on node creation (fixes #1222)
Kim Alvefur <zash@zash.se>
parents:
9541
diff
changeset
|
201 |
12249
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
202 -- Read-only service with no nodes where nobody is allowed anything to act as a |
12260
e729c994e7c7
mod_pep: Fix typo in comment [codespell]
Kim Alvefur <zash@zash.se>
parents:
12249
diff
changeset
|
203 -- fallback for interactions with non-existent users |
12088
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
204 local nobody_service = pubsub.new({ |
12248
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
205 node_defaults = { |
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
206 ["max_items"] = 1; |
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
207 ["persist_items"] = false; |
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
208 ["access_model"] = "presence"; |
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
209 ["send_last_published_item"] = "on_sub_and_presence"; |
4dbca0858f0b
mod_pep: Correct initialization of fallback service
Kim Alvefur <zash@zash.se>
parents:
12153
diff
changeset
|
210 }; |
12249
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
211 autocreate_on_publish = false; |
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
212 autocreate_on_subscribe = false; |
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
213 get_affiliation = function () |
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
214 return "outcast"; |
5173f8a761a0
mod_pep: Clarify purpose of fallback service
Kim Alvefur <zash@zash.se>
parents:
12248
diff
changeset
|
215 end; |
12088
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
216 }); |
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
217 |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
218 function get_pep_service(username) |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
219 local user_bare = jid_join(username, host); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
220 local service = services[username]; |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
221 if service then |
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
222 return service; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 end |
12088
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
224 if not usermanager.user_exists(username, host) then |
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
225 return nobody_service; |
e5028f6eb599
mod_pep: Prevent creation of services for non-existent users
Kim Alvefur <zash@zash.se>
parents:
12087
diff
changeset
|
226 end |
10066
216ae100c04a
mod_pep: Only log when creating new pubsub services
Kim Alvefur <zash@zash.se>
parents:
10047
diff
changeset
|
227 module:log("debug", "Creating pubsub service for user %q", username); |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
228 service = pubsub.new({ |
9541
742977123168
mod_pep: Add PEP service owners username in configuration to ease identification
Kim Alvefur <zash@zash.se>
parents:
9540
diff
changeset
|
229 pep_username = username; |
6444
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
230 node_defaults = { |
8333
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8332
diff
changeset
|
231 ["max_items"] = 1; |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8332
diff
changeset
|
232 ["persist_items"] = true; |
9097
ce2ba9f91c84
mod_pep: Set default access model to 'presence'
Kim Alvefur <zash@zash.se>
parents:
9082
diff
changeset
|
233 ["access_model"] = "presence"; |
11854
b605cbd5f13b
mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents:
11724
diff
changeset
|
234 ["send_last_published_item"] = "on_sub_and_presence"; |
6444
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
235 }; |
12153
26af75c20163
util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents:
12091
diff
changeset
|
236 max_items = max_max_items; |
6444
aab509a9d0ba
mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents:
6443
diff
changeset
|
237 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
238 autocreate_on_publish = true; |
9542
b8bfcfbe5126
mod_pep: Add automatic subscriptions on node creation (fixes #1222)
Kim Alvefur <zash@zash.se>
parents:
9541
diff
changeset
|
239 autocreate_on_subscribe = false; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 |
8949
9194431b6447
mod_pep_plus: Support persistence of node configuration
Kim Alvefur <zash@zash.se>
parents:
8895
diff
changeset
|
241 nodestore = nodestore(username); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
242 itemstore = simple_itemstore(username); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
243 broadcaster = get_broadcaster(username); |
10520
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
244 subscriber_filter = get_subscriber_filter(username); |
8696
164da3186511
mod_pep_plus: Validate items here too (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8377
diff
changeset
|
245 itemcheck = is_item_stanza; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
246 get_affiliation = function (jid) |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
247 if jid_bare(jid) == user_bare then |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 return "owner"; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
249 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
250 end; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
251 |
9099
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
252 access_models = { |
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
253 presence = function (jid) |
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
254 if subscription_presence(username, jid) then |
9160
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
255 return "member"; |
9099
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
256 end |
9160
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
257 return "outcast"; |
9099
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
258 end; |
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
259 }; |
974b25c27f24
mod_pep: Move subscriber check into 'presence' access model callback
Kim Alvefur <zash@zash.se>
parents:
9097
diff
changeset
|
260 |
12022
eedd3eff0768
mod_pep: Set correct jid attr on node disco items
Kim Alvefur <zash@zash.se>
parents:
11856
diff
changeset
|
261 jid = user_bare; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
262 normalize_jid = jid_bare; |
9077
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
263 |
aefb96a52f5f
mod_pep: Add 'pep_max_items' option to set an upper limit, defaults to 256 (scientifically chosen)
Matthew Wild <mwild1@gmail.com>
parents:
9074
diff
changeset
|
264 check_node_config = check_node_config; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
265 }); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
266 services[username] = service; |
12086
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
267 local item = { service = service, jid = user_bare } |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
268 pep_service_items[username] = item; |
1dc00ca6ee9d
mod_pep: Limit possible growth of number of pubsub services
Kim Alvefur <zash@zash.se>
parents:
12085
diff
changeset
|
269 module:add_item("pep-service", item); |
6432
388786af0dd2
mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents:
6305
diff
changeset
|
270 return service; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
271 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
272 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
273 function handle_pubsub_iq(event) |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
274 local origin, stanza = event.origin, event.stanza; |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
275 local service_name = origin.username; |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
276 if stanza.attr.to ~= nil then |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
277 service_name = jid_split(stanza.attr.to); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
278 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
279 local service = get_pep_service(service_name); |
8335
9db72349095f
mod_pep_plus: Use dispatch function from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
280 |
9db72349095f
mod_pep_plus: Use dispatch function from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
281 return lib_pubsub.handle_pubsub_iq(event, service) |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
282 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
283 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 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
|
285 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
|
286 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
287 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
288 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
|
289 local t = stanza.attr.type; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
290 if not t then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
291 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
|
292 if child then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
293 local attr = child.attr; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 if attr.hash then -- new caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 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
|
296 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
|
297 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
298 else -- legacy caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
299 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
|
300 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
|
301 end |
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 return; -- no or bad caps |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
305 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
|
306 return; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
307 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
308 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
|
309 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
310 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
311 local function resend_last_item(jid, node, service) |
11854
b605cbd5f13b
mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents:
11724
diff
changeset
|
312 local ok, config = service:get_node_config(node, true); |
b605cbd5f13b
mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents:
11724
diff
changeset
|
313 if ok and config.send_last_published_item ~= "on_sub_and_presence" then return end |
8377
58cdbbe3b86a
mod_pep_plus: Broadcast only the last item (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8342
diff
changeset
|
314 local ok, id, item = service:get_last_item(node, jid); |
9205 | 315 if not (ok and id) then return; end |
12962
1b179d14a1dd
mod_pep: Pass node/service objects to broadcaster when resending last item
Matthew Wild <mwild1@gmail.com>
parents:
12960
diff
changeset
|
316 service.config.broadcaster("items", node, { [jid] = true }, item, true, service.nodes[node], service); |
5852
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 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
319 local function update_subscriptions(recipient, service_name, nodes) |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
320 nodes = nodes or empty_set; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
321 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
322 local service_recipients = recipients[service_name]; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
323 if not service_recipients then |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
324 service_recipients = {}; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
325 recipients[service_name] = service_recipients; |
5852
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 |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
328 local current = service_recipients[recipient]; |
9540
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
329 if not current then |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
330 current = empty_set; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
331 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
332 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
333 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
|
334 return; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
335 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
336 |
8753
d6373a378b73
mod_pep_plus: Skip getting PEP service instance for sessions that have not touched PEP
Kim Alvefur <zash@zash.se>
parents:
8728
diff
changeset
|
337 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
|
338 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
339 for node in nodes - current do |
10520
225fade2ab4d
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Kim Alvefur <zash@zash.se>
parents:
10045
diff
changeset
|
340 if service:may(node, recipient, "subscribe") then |
9140
415a6d26709e
mod_pep: Only resend last item on successful subscription
Kim Alvefur <zash@zash.se>
parents:
9139
diff
changeset
|
341 resend_last_item(recipient, node, service); |
415a6d26709e
mod_pep: Only resend last item on successful subscription
Kim Alvefur <zash@zash.se>
parents:
9139
diff
changeset
|
342 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
343 end |
6305
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
344 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
345 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
|
346 nodes = nil; |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
347 end |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
348 |
38d82f8ead25
mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents:
6264
diff
changeset
|
349 service_recipients[recipient] = nodes; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
350 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
351 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
352 module:hook("presence/bare", function(event) |
8728
41c959c5c84b
Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents:
8696
diff
changeset
|
353 -- inbound presence to bare JID received |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
354 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
|
355 local t = stanza.attr.type; |
8303
053cf683c2c7
mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents:
8300
diff
changeset
|
356 local is_self = not stanza.attr.to; |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
357 local username = jid_split(stanza.attr.to); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
358 local user_bare = jid_bare(stanza.attr.to); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
359 if is_self then |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
360 username = origin.username; |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
361 user_bare = jid_join(username, host); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
362 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
363 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
364 if not t then -- available presence |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
365 if is_self or subscription_presence(username, stanza.attr.from) then |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
366 local recipient = stanza.attr.from; |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
367 local current = recipients[username] and recipients[username][recipient]; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
368 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
|
369 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
|
370 if not hash then |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
371 update_subscriptions(recipient, username); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
372 else |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
373 recipients[username] = recipients[username] or {}; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
374 if hash_map[hash] then |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
375 update_subscriptions(recipient, username, hash_map[hash]); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
376 else |
9540
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
377 -- COMPAT from ~= stanza.attr.to because OneTeam can't deal with missing from attribute |
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
378 origin.send( |
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
379 st.stanza("iq", {from=user_bare, to=stanza.attr.from, id="disco", type="get"}) |
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
380 :tag("query", {xmlns = "http://jabber.org/protocol/disco#info", node = query_node}) |
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
381 ); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
382 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
383 end |
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 elseif t == "unavailable" then |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
386 update_subscriptions(stanza.attr.from, username); |
8303
053cf683c2c7
mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents:
8300
diff
changeset
|
387 elseif not is_self and t == "unsubscribe" then |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
388 local from = jid_bare(stanza.attr.from); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
389 local subscriptions = recipients[username]; |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
390 if subscriptions then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
391 for subscriber in pairs(subscriptions) do |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
392 if jid_bare(subscriber) == from then |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
393 update_subscriptions(subscriber, username); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
394 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
395 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
396 end |
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, 10); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
399 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 if not disco then |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
404 return; |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
405 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
406 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
407 -- Process disco response |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
408 local is_self = stanza.attr.to == nil; |
8315
967f04fe7fd4
mod_pep_plus: Add missing variable
Kim Alvefur <zash@zash.se>
parents:
8307
diff
changeset
|
409 local user_bare = jid_bare(stanza.attr.to); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
410 local username = jid_split(stanza.attr.to); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
411 if is_self then |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
412 username = origin.username; |
8315
967f04fe7fd4
mod_pep_plus: Add missing variable
Kim Alvefur <zash@zash.se>
parents:
8307
diff
changeset
|
413 user_bare = jid_join(username, host); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
414 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
415 local contact = stanza.attr.from; |
9540
8cdd7fec6aa7
mod_pep: Remove use of recipients table for signaling pending disco#items
Kim Alvefur <zash@zash.se>
parents:
9538
diff
changeset
|
416 local ver = calculate_hash(disco.tags); -- calculate hash |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
417 local notify = set_new(); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 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
|
422 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
423 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
424 hash_map[ver] = notify; -- update hash map |
8303
053cf683c2c7
mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents:
8300
diff
changeset
|
425 if is_self then |
8307
94860b5733d3
mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents:
8306
diff
changeset
|
426 -- Optimization: Fiddle with other local users |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
427 for jid, item in pairs(origin.roster) do -- for all interested contacts |
8304
9f8476c77fa8
mod_pep_plus: Skip over roster metadata (version, pending) entry
Kim Alvefur <zash@zash.se>
parents:
8303
diff
changeset
|
428 if jid then |
8307
94860b5733d3
mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents:
8306
diff
changeset
|
429 local contact_node, contact_host = jid_split(jid); |
9061
82dd435c942c
mod_pep_plus: Fix boolean logic precedence (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
9030
diff
changeset
|
430 if contact_host == host and (item.subscription == "both" or item.subscription == "from") then |
8307
94860b5733d3
mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents:
8306
diff
changeset
|
431 update_subscriptions(user_bare, contact_node, notify); |
8304
9f8476c77fa8
mod_pep_plus: Skip over roster metadata (version, pending) entry
Kim Alvefur <zash@zash.se>
parents:
8303
diff
changeset
|
432 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
433 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
434 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
435 end |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
436 update_subscriptions(contact, username, notify); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
437 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
438 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
439 module:hook("account-disco-info-node", function(event) |
8982
4a576c39bb2f
mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8949
diff
changeset
|
440 local stanza, origin = event.stanza, event.origin; |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
441 local service_name = origin.username; |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
442 if stanza.attr.to ~= nil then |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
443 service_name = jid_split(stanza.attr.to); |
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
444 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
445 local service = get_pep_service(service_name); |
8982
4a576c39bb2f
mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8949
diff
changeset
|
446 return lib_pubsub.handle_disco_info_node(event, service); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
447 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
448 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
449 module:hook("account-disco-info", function(event) |
8319
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
450 local origin, reply = event.origin, event.reply; |
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
451 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
452 reply:tag('identity', {category='pubsub', type='pep'}):up(); |
8319
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
453 |
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
454 local username = jid_split(reply.attr.from) or origin.username; |
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
455 local service = get_pep_service(username); |
57e3ad11f3f6
mod_pep_plus: Advertise pubsub features in disco#info (code adapted from mod_pubsub)
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
456 |
8342
0c0990a575de
mod_pep_plus: Fix a typo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8341
diff
changeset
|
457 local supported_features = lib_pubsub.get_feature_set(service) + set.new{ |
8341
910d3c3f60a6
mod_pep_plus: Use feature detection from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8339
diff
changeset
|
458 -- Features not covered by the above |
8332
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
459 "auto-subscribe", |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
460 "filtered-notifications", |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
461 "last-published", |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
462 "presence-notifications", |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
463 "presence-subscribe", |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
464 }; |
8341
910d3c3f60a6
mod_pep_plus: Use feature detection from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8339
diff
changeset
|
465 |
11376
774811e2c6ab
mod_pep: Advertise base pubsub feature (fixes #1632)
Kim Alvefur <zash@zash.se>
parents:
10672
diff
changeset
|
466 reply:tag('feature', {var=xmlns_pubsub}):up(); |
8342
0c0990a575de
mod_pep_plus: Fix a typo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8341
diff
changeset
|
467 for feature in supported_features do |
8332
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
468 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); |
e89b57d0d80a
mod_pep_plus: Advertise additional features not covered by inspection of pubsub service methods
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
469 end |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
470 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
471 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
472 module:hook("account-disco-items-node", function(event) |
8982
4a576c39bb2f
mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8949
diff
changeset
|
473 local stanza, origin = event.stanza, event.origin; |
8321
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
474 local is_self = stanza.attr.to == nil; |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
475 local username = jid_split(stanza.attr.to); |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
476 if is_self then |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
477 username = origin.username; |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
478 end |
8321
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
479 local service = get_pep_service(username); |
8982
4a576c39bb2f
mod_pep_plus: Use service discovery helpers from pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8949
diff
changeset
|
480 return lib_pubsub.handle_disco_items_node(event, service); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
481 end); |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
482 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
483 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
|
484 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
|
485 |
8321
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
486 local is_self = stanza.attr.to == nil; |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
487 local user_bare = jid_bare(stanza.attr.to); |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
488 local username = jid_split(stanza.attr.to); |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
489 if is_self then |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
490 username = origin.username; |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
491 user_bare = jid_join(username, host); |
8305
ec605946e597
mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents:
8304
diff
changeset
|
492 end |
8321
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
493 local service = get_pep_service(username); |
73ff49a42ea8
mod_pep_plus: Advertise nodes with the correct JID (missed in ec605946e597) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8320
diff
changeset
|
494 |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
495 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
|
496 if not ok then return; end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
497 |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
498 for node, node_obj in pairs(ret) do |
9597
17d43543f9b6
pubsub: Set pubsub#title as name attribute in disco#items (fixes #1226)
Kim Alvefur <zash@zash.se>
parents:
9542
diff
changeset
|
499 reply:tag("item", { jid = user_bare, node = node, name = node_obj.config.title }):up(); |
5852
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
500 end |
84bdac93910f
mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
501 end); |
12089
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
502 |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
503 module:hook_global("user-deleted", function(event) |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
504 if event.host ~= host then return end |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
505 local username = event.username; |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
506 local service = services[username]; |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
507 if not service then return end |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
508 for node in pairs(service.nodes) do service:delete(node, true); end |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
509 |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
510 local item = pep_service_items[username]; |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
511 pep_service_items[username] = nil; |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
512 if item then module:remove_item("pep-service", item); end |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
513 |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
514 recipients[username] = nil; |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
515 end); |
76b4e3f12b53
mod_pep: Wipe pubsub service on user deletion
Kim Alvefur <zash@zash.se>
parents:
12088
diff
changeset
|
516 |