Annotate

plugins/mod_pep_plus.lua @ 8307:94860b5733d3

mod_pep_plus: Update subscriptions for other local users only
author Kim Alvefur <zash@zash.se>
date Mon, 09 Oct 2017 00:11:11 +0200
parent 8306:202b9951b037
child 8315:967f04fe7fd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
4 local jid_join = require "util.jid".join;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 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
6 local st = require "util.stanza";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 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
8 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
9
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10 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
11 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
12 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
13
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local lib_pubsub = module:require "pubsub";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 local handlers = lib_pubsub.handlers;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
17 local empty_set = set_new();
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
18
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 local services = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 local recipients = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 local hash_map = {};
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
23 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
24
8306
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
25 local known_nodes_map = module:open_store("pep", "map");
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
26 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
27
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 function module.save()
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 return { services = 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 function module.restore(data)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33 services = data.services;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
36 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
37 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
38 local recipient_bare = jid_bare(recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 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
40 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
41 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
43 local function simple_itemstore(username)
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
44 return function (config, node)
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
45 module:log("debug", "new simple_itemstore(%q, %q)", username, node);
8306
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
46 known_nodes_map:set(username, node, true);
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8218
diff changeset
47 local archive = module:open_store("pep_"..node, "archive");
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
48 return lib_pubsub.simple_itemstore(archive, config, username, node, false);
8218
2c75a5ba58fc mod_pubsub: Pass 'user' to simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8215
diff changeset
49 end
8215
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
50 end
835bb32c36b4 mod_pep_plus: Add item persistency.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8214
diff changeset
51
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
52 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
53 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
54 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
55 if item then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 item = st.clone(item);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 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
58 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
59 local message = st.message({ from = user_bare, type = "headline" })
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 :tag("event", { xmlns = xmlns_pubsub_event })
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
61 :tag(kind, { node = node })
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 :add_child(item);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63 for jid in pairs(jids) do
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
64 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item));
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65 message.attr.to = jid;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 module:send(message);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
67 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
68 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 return simple_broadcast;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
72 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
73 module:log("debug", "get_pep_service(%q)", username);
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
74 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
75 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
76 if service then
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
77 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 end
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
79 service = pubsub.new({
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 capabilities = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 none = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 get_nodes = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 subscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 unsubscribe = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89 get_subscription = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 get_subscriptions = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 get_items = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 set_affiliation = false;
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 subscriber = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105 publish = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106 retract = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 set_affiliation = false;
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 publisher = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 create = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 get_nodes = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135 get_items = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 subscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 unsubscribe_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 get_subscription_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140 get_subscriptions_other = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
143 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
144
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
145 set_affiliation = false;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
147 owner = {
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 create = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 retract = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
151 delete = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
152 get_nodes = true;
6443
f4403c270ea2 mod_pep_plus: Add node config form
Kim Alvefur <zash@zash.se>
parents: 6432
diff changeset
153 configure = true;
5852
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 subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
156 unsubscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
157 get_subscription = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
158 get_subscriptions = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
159 get_items = true;
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
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162 subscribe_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
163 unsubscribe_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
164 get_subscription_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
165 get_subscriptions_other = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
166
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
167 be_subscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
168 be_unsubscribed = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
169
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
170 set_affiliation = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
171 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
172 };
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
173
6444
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
174 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
175 ["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
176 };
aab509a9d0ba mod_pep_plus: Default to max one item per node (Recomended for PEP)
Kim Alvefur <zash@zash.se>
parents: 6443
diff changeset
177
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 autocreate_on_publish = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179 autocreate_on_subscribe = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
180
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
181 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
182 broadcaster = get_broadcaster(username);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183 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
184 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
185 return "owner";
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
186 elseif subscription_presence(username, jid) then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187 return "subscriber";
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
188 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
189 end;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
190
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
191 normalize_jid = jid_bare;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
192 });
8306
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
193 local nodes, err = known_nodes:get(username);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
194 if nodes then
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
195 module:log("debug", "Restoring nodes for user %s", username);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
196 for node in pairs(nodes) do
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
197 module:log("debug", "Restoring node %q", node);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
198 service:create(node, true);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
199 end
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
200 elseif err then
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
201 module:log("error", "Could not restore nodes for %s: %s", username, err);
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
202 else
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
203 module:log("debug", "No known nodes");
202b9951b037 mod_pep_plus: Keep track of nodes, and restore them when later
Kim Alvefur <zash@zash.se>
parents: 8305
diff changeset
204 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
205 services[username] = service;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
206 module:add_item("pep-service", { service = service, jid = user_bare });
6432
388786af0dd2 mod_pep_plus: Add pubsub service objects to an item list
Kim Alvefur <zash@zash.se>
parents: 6305
diff changeset
207 return service;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
208 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
209
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
210 function handle_pubsub_iq(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
211 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
212 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
213 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
214 if not action then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
215 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
216 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
217 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
218 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
219 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
220 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
221 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
222 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
223 if handler then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
224 handler(origin, stanza, action, service);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
225 return true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
226 end
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
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
229 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
230 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
231
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
232 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
233 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
234
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
235 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
236 local t = stanza.attr.type;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
237 if not t then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
238 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
239 if child then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
240 local attr = child.attr;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
241 if attr.hash then -- new caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
242 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
243 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
244 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
245 else -- legacy caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
246 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
247 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
248 end
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 return; -- no or bad caps
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
252 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
253 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
254 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
255 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
256 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
257
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
258 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
259 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
260 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
261 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
262 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
263 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
264 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
265
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
266 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
267 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
268 nodes = nodes or empty_set;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
269
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
270 local service_recipients = recipients[service_name];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
271 if not service_recipients then
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
272 service_recipients = {};
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
273 recipients[service_name] = service_recipients;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
274 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
276 local current = service_recipients[recipient];
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
277 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
278 current = empty_set;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
279 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
280
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
281 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
282 return;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
283 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
284
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
285 for node in current - nodes do
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
286 service:remove_subscription(node, recipient, recipient);
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
287 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
288
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
289 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
290 service:add_subscription(node, recipient, recipient);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
291 resend_last_item(recipient, node, service);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
292 end
6305
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
293
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
294 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
295 nodes = nil;
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
296 end
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
297
38d82f8ead25 mod_pep_plus: Only broadcast newly added subscriptions
Kim Alvefur <zash@zash.se>
parents: 6264
diff changeset
298 service_recipients[recipient] = nodes;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
299 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
300
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
301 module:hook("presence/bare", function(event)
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
302 -- inbound presence to bare JID recieved
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
303 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
304 local t = stanza.attr.type;
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
305 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
306 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
307 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
308 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
309 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
310 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
311 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
312
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 update_subscriptions(recipient, username);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
321 else
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
322 recipients[username] = recipients[username] or {};
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
323 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
324 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
325 else
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
326 recipients[username][recipient] = hash;
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
327 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
328 if is_self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
329 -- 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
330 origin.send(
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
331 st.stanza("iq", {from=user_bare, to=stanza.attr.from, id="disco", type="get"})
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
332 :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
333 );
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
334 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
335 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
336 end
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 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
339 update_subscriptions(stanza.attr.from, username);
8303
053cf683c2c7 mod_pep_plus: Rename variable for clarity
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
340 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
341 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
342 local subscriptions = recipients[username];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
343 if subscriptions then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
344 for subscriber in pairs(subscriptions) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
345 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
346 update_subscriptions(subscriber, username);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
347 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
348 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
349 end
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 end, 10);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
352
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
353 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
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 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
356 if not disco then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
357 return;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
358 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
359
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
360 -- 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
361 local is_self = stanza.attr.to == nil;
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
362 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
363 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
364 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
365 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
366 local contact = 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][contact];
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
368 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
369 local ver = current;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
370 if not string.find(current, "#") then
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
371 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
372 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
373 local notify = set_new();
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
374 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
375 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
376 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
377 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
378 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
379 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
380 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
381 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
382 -- 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
383 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
384 if jid then
8307
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
385 local contact_node, contact_host = jid_split(jid);
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
386 if contact_host == host and item.subscription == "both" or item.subscription == "from" then
94860b5733d3 mod_pep_plus: Update subscriptions for other local users only
Kim Alvefur <zash@zash.se>
parents: 8306
diff changeset
387 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
388 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
389 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
390 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
391 end
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
392 update_subscriptions(contact, username, notify);
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
393 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 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
396 local reply, stanza, origin = event.reply, 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
397 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
398 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
399 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
400 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
401 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
402 local node = event.node;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
403 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
404 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
405 event.exists = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
406 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
407 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
408
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
409 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
410 local reply = event.reply;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
411 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
412 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
413 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
414
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
415 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
416 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
417 local node = event.node;
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
418 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
419 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
420 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
421 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
422 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
423 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
424 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
425 event.exists = true;
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
426 for _, id in ipairs(ret) do
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
427 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
428 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
429 end);
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
430
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
431 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
432 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
433
8305
ec605946e597 mod_pep_plus: Use local username instead of bare JID for references
Kim Alvefur <zash@zash.se>
parents: 8304
diff changeset
434 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
435 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
436 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
437 end
5852
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
438 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
439 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
440 if not ok then return; end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
441
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
442 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
443 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
444 end
84bdac93910f mod_pep_plus: An util.pubsub based PEP module
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
445 end);