annotate mod_pep_plus/mod_pep_plus.lua @ 2806:93a4b13ca9f6

mod_firewall/test: Use session passed as argument instead of upvalue
author Kim Alvefur <zash@zash.se>
date Fri, 20 Oct 2017 02:51:38 +0200
parents cb2342cf3f3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
1 local pubsub = module:require "util_pubsub";
2668
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;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
4 local jid_join = require "util.jid".join;
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local set_new = require "util.set".new;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local st = require "util.stanza";
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 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
8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
9 local cache = require "util.cache";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
10 local set = require "util.set";
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 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
13 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
14 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
15
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local lib_pubsub = module:require "pubsub";
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local empty_set = set_new();
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local services = {};
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local recipients = {};
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local hash_map = {};
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
24 local host = module.host;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
25
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
26 local known_nodes_map = module:open_store("pep", "map");
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
27 local known_nodes = module:open_store("pep");
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
28
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 function module.save()
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 return { services = services };
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 function module.restore(data)
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 services = data.services;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
37 local function subscription_presence(username, recipient)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
38 local user_bare = jid_join(username, host);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local recipient_bare = jid_bare(recipient);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 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
41 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
42 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
44 local function simple_itemstore(username)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
45 return function (config, node)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
46 if config["persist_items"] then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
47 module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
48 known_nodes_map:set(username, node, true);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
49 local archive = module:open_store("pep_"..node, "archive");
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
50 return lib_pubsub.archive_itemstore(archive, config, username, node, false);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
51 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
52 module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
53 known_nodes_map:set(username, node, nil);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
54 return cache.new(tonumber(config["max_items"]));
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
55 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
56 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
57 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
58
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
59 local function get_broadcaster(username)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
60 local user_bare = jid_join(username, host);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 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
62 if item then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 item = st.clone(item);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 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
65 end
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
66 local message = st.message({ from = user_bare, type = "headline" })
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 :tag("event", { xmlns = xmlns_pubsub_event })
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 :tag(kind, { node = node })
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 :add_child(item);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 for jid in pairs(jids) do
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
71 module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item));
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 message.attr.to = jid;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 module:send(message);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 return simple_broadcast;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
79 function get_pep_service(username)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
80 module:log("debug", "get_pep_service(%q)", username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
81 local user_bare = jid_join(username, host);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
82 local service = services[username];
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 if service then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 return service;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 service = pubsub.new({
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 capabilities = {
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 none = {
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 create = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 publish = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 retract = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 get_nodes = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 subscribe = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 unsubscribe = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 get_subscription = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 get_subscriptions = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 get_items = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 subscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 unsubscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 get_subscription_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 get_subscriptions_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 be_subscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 be_unsubscribed = true;
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 set_affiliation = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 };
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 subscriber = {
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 create = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 publish = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 retract = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 get_nodes = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 subscribe = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 unsubscribe = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 get_subscription = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 get_subscriptions = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 get_items = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 subscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 unsubscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 get_subscription_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 get_subscriptions_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 be_subscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 be_unsubscribed = true;
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 set_affiliation = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 };
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 publisher = {
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 create = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 publish = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 retract = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 get_nodes = 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 subscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 unsubscribe_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 get_subscription_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 get_subscriptions_other = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 be_subscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 be_unsubscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 set_affiliation = false;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 };
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 owner = {
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 create = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 publish = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 retract = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 delete = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 get_nodes = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 configure = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 subscribe = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 unsubscribe = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 get_subscription = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 get_subscriptions = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 get_items = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 subscribe_other = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 unsubscribe_other = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 get_subscription_other = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 get_subscriptions_other = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 be_subscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 be_unsubscribed = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 set_affiliation = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 };
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
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 node_defaults = {
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
182 ["max_items"] = 1;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
183 ["persist_items"] = true;
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 };
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 autocreate_on_publish = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 autocreate_on_subscribe = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
189 itemstore = simple_itemstore(username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
190 broadcaster = get_broadcaster(username);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 get_affiliation = function (jid)
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
192 if jid_bare(jid) == user_bare then
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 return "owner";
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
194 elseif subscription_presence(username, jid) then
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 return "subscriber";
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 end;
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 normalize_jid = jid_bare;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 });
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
201 local nodes, err = known_nodes:get(username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
202 if nodes then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
203 module:log("debug", "Restoring nodes for user %s", username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
204 for node in pairs(nodes) do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
205 module:log("debug", "Restoring node %q", node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
206 service:create(node, true);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
207 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
208 elseif err then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
209 module:log("error", "Could not restore nodes for %s: %s", username, err);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
210 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
211 module:log("debug", "No known nodes");
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
212 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
213 services[username] = service;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
214 module:add_item("pep-service", { service = service, jid = user_bare });
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 return service;
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
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 function handle_pubsub_iq(event)
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 local origin, stanza = event.origin, event.stanza;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
220 local service_name = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
221 if stanza.attr.to ~= nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
222 service_name = jid_split(stanza.attr.to);
2668
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 local service = get_pep_service(service_name);
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
225
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
226 return lib_pubsub.handle_pubsub_iq(event, service)
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 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
230 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
231
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 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
233 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
234
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 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
236 local t = stanza.attr.type;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 if not t then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 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
239 if child then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 local attr = child.attr;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 if attr.hash then -- new caps
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 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
243 return attr.ver, attr.node.."#"..attr.ver;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 else -- legacy caps
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 if attr.node and attr.ver then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 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
248 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 end
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 return; -- no or bad caps
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 elseif t == "unavailable" or t == "error" then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 return;
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 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
256 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 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
259 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
260 if not ok then return; end
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
261 for _, id in ipairs(items) do
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 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
263 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 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
267 local service = get_pep_service(service_name);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268 nodes = nodes or empty_set;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 local service_recipients = recipients[service_name];
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 if not service_recipients then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272 service_recipients = {};
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 recipients[service_name] = service_recipients;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 end
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 local current = service_recipients[recipient];
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277 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
278 current = empty_set;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 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
282 return;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 for node in current - nodes do
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 service:remove_subscription(node, recipient, recipient);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289 for node in nodes - current do
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 service:add_subscription(node, recipient, recipient);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 resend_last_item(recipient, node, service);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 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
295 nodes = nil;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298 service_recipients[recipient] = nodes;
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
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301 module:hook("presence/bare", function(event)
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 -- inbound presence to bare JID recieved
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 local origin, stanza = event.origin, event.stanza;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 local t = stanza.attr.type;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
305 local is_self = not stanza.attr.to;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
306 local username = jid_split(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
307 local user_bare = jid_bare(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
308 if is_self then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
309 username = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
310 user_bare = jid_join(username, host);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
311 end
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 if not t then -- available presence
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
314 if is_self or subscription_presence(username, stanza.attr.from) then
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 local recipient = stanza.attr.from;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
316 local current = recipients[username] and recipients[username][recipient];
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317 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
318 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
319 if not hash then
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
320 update_subscriptions(recipient, username);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 else
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
322 recipients[username] = recipients[username] or {};
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 if hash_map[hash] then
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
324 update_subscriptions(recipient, username, hash_map[hash]);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 else
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
326 recipients[username][recipient] = hash;
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
328 if is_self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 -- 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
330 origin.send(
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
331 st.stanza("iq", {from=user_bare, to=stanza.attr.from, id="disco", type="get"})
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 :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
333 );
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 elseif t == "unavailable" then
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
339 update_subscriptions(stanza.attr.from, username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
340 elseif not is_self and t == "unsubscribe" then
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 local from = jid_bare(stanza.attr.from);
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
342 local subscriptions = recipients[username];
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 if subscriptions then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 for subscriber in pairs(subscriptions) do
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 if jid_bare(subscriber) == from then
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
346 update_subscriptions(subscriber, username);
2668
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 end
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 end, 10);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353 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
354 local origin, stanza = event.origin, event.stanza;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 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
356 if not disco then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 return;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360 -- Process disco response
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
361 local is_self = stanza.attr.to == nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
362 local user_bare = jid_bare(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
363 local username = jid_split(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
364 if is_self then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
365 username = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
366 user_bare = jid_join(username, host);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
367 end
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 local contact = stanza.attr.from;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
369 local current = recipients[username] and recipients[username][contact];
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 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
371 local ver = current;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
372 if not string.find(current, "#") then
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373 ver = calculate_hash(disco.tags); -- calculate hash
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
374 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
375 local notify = set_new();
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
376 for _, feature in pairs(disco.tags) do
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
377 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
378 local nfeature = feature.attr.var:match("^(.*)%+notify$");
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
379 if nfeature then notify:add(nfeature); 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 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382 hash_map[ver] = notify; -- update hash map
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
383 if is_self then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
384 -- Optimization: Fiddle with other local users
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
385 for jid, item in pairs(origin.roster) do -- for all interested contacts
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
386 if jid then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
387 local contact_node, contact_host = jid_split(jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
388 if contact_host == host and item.subscription == "both" or item.subscription == "from" then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
389 update_subscriptions(user_bare, contact_node, notify);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
390 end
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
391 end
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
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
394 update_subscriptions(contact, username, notify);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
395 end);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
396
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
397 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
398 local reply, stanza, origin = event.reply, event.stanza, event.origin;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
399 local service_name = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
400 if stanza.attr.to ~= nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
401 service_name = jid_split(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
402 end
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
403 local service = get_pep_service(service_name);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
404 local node = event.node;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
405 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
406 if not ok then return; end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
407 event.exists = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
408 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
409 end);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
410
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
411 module:hook("account-disco-info", function(event)
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
412 local origin, reply = event.origin, event.reply;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
413
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
414 reply:tag('identity', {category='pubsub', type='pep'}):up();
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
415
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
416 local username = jid_split(reply.attr.from) or origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
417 local service = get_pep_service(username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
418
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
419 local suppored_features = lib_pubsub.get_feature_set(service) + set.new{
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
420 -- Features not covered by the above
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
421 "access-presence",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
422 "auto-subscribe",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
423 "filtered-notifications",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
424 "last-published",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
425 "persistent-items",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
426 "presence-notifications",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
427 "presence-subscribe",
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
428 };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
429
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
430 for feature in suppored_features do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
431 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up();
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
432 end
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
433 end);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
434
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
435 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
436 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
437 local node = event.node;
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
438 local is_self = stanza.attr.to == nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
439 local user_bare = jid_bare(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
440 local username = jid_split(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
441 if is_self then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
442 username = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
443 user_bare = jid_join(username, host);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
444 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
445 local service = get_pep_service(username);
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
446 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
447 if not ok then return; end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
448 event.exists = true;
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
449 for _, id in ipairs(ret) do
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
450 reply:tag("item", { jid = user_bare, name = id }):up();
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
451 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
452 end);
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
453
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
454 module:hook("account-disco-items", function(event)
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
455 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
456
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
457 local is_self = stanza.attr.to == nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
458 local user_bare = jid_bare(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
459 local username = jid_split(stanza.attr.to);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
460 if is_self then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
461 username = origin.username;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
462 user_bare = jid_join(username, host);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
463 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
464 local service = get_pep_service(username);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
465
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
466 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
467 if not ok then return; end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
468
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
469 for node, node_obj in pairs(ret) do
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents: 2668
diff changeset
470 reply:tag("item", { jid = user_bare, node = node, name = node_obj.config.name }):up();
2668
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
471 end
f8fc79b3051a mod_pep_plus: Import from Prosody trunk ae3c5abb3336
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
472 end);