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