Annotate

plugins/mod_roster.lua @ 7059:7ec52755622f 0.9.9

Backout 88d54bec26b7 prior to release, as it certainly requires more testing
author Matthew Wild <mwild1@gmail.com>
date Fri, 08 Jan 2016 13:01:27 +0000
parent 5372:676e3cf0e565
child 5776:bd0ff8ae98a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1355
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2227
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2227
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
9
30
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local st = require "util.stanza"
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
12 local jid_split = require "util.jid".split;
928
92288c13d7bc Fixed: mod_roster: Prep JIDs being added to roster (part of issue #57)
Waqas Hussain <waqas20@gmail.com>
parents: 916
diff changeset
13 local jid_prep = require "util.jid".prep;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
14 local t_concat = table.concat;
3526
69a8c7e635c5 mod_roster: Cleaned up some unused variables and global accesses.
Waqas Hussain <waqas20@gmail.com>
parents: 3525
diff changeset
15 local tonumber = tonumber;
69a8c7e635c5 mod_roster: Cleaned up some unused variables and global accesses.
Waqas Hussain <waqas20@gmail.com>
parents: 3525
diff changeset
16 local pairs, ipairs = pairs, ipairs;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
17
5099
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
18 local rm_load_roster = require "core.rostermanager".load_roster;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
19 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster;
110
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 108
diff changeset
20 local rm_add_to_roster = require "core.rostermanager".add_to_roster;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
21 local rm_roster_push = require "core.rostermanager".roster_push;
5013
ab693eea0869 mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents: 4265
diff changeset
22 local core_post_stanza = prosody.core_post_stanza;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
23
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
24 module:add_feature("jabber:iq:roster");
421
63be85693710 Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents: 326
diff changeset
25
4265
d56c26c258e4 mod_roster: Remove <optional/> from roster version stream feature, as per latest specs.
Waqas Hussain <waqas20@gmail.com>
parents: 3540
diff changeset
26 local rosterver_stream_feature = st.stanza("ver", {xmlns="urn:xmpp:features:rosterver"});
2611
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
27 module:hook("stream-features", function(event)
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
28 local origin, features = event.origin, event.features;
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
29 if origin.username then
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
30 features:add_child(rosterver_stream_feature);
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
31 end
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
32 end);
1133
b293d7dc6a45 mod_roster: Advertize roster versioning support
Waqas Hussain <waqas20@gmail.com>
parents: 928
diff changeset
33
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
34 module:hook("iq/self/jabber:iq:roster:query", function(event)
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
35 local session, stanza = event.origin, event.stanza;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
36
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
37 if stanza.attr.type == "get" then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
38 local roster = st.reply(stanza);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
39
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
40 local client_ver = tonumber(stanza.tags[1].attr.ver);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
41 local server_ver = tonumber(session.roster[false].version or 1);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
42
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
43 if not (client_ver and server_ver) or client_ver ~= server_ver then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
44 roster:query("jabber:iq:roster");
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
45 -- Client does not support versioning, or has stale roster
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
46 for jid, item in pairs(session.roster) do
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
47 if jid ~= "pending" and jid then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
48 roster:tag("item", {
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
49 jid = jid,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
50 subscription = item.subscription,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
51 ask = item.ask,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
52 name = item.name,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
53 });
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
54 for group in pairs(item.groups) do
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
55 roster:tag("group"):text(group):up();
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
56 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
57 roster:up(); -- move out from item
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
58 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
59 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
60 roster.tags[1].attr.ver = server_ver;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
61 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
62 session.send(roster);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
63 session.interested = true; -- resource is interested in roster updates
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
64 else -- stanza.attr.type == "set"
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
65 local query = stanza.tags[1];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
66 if #query.tags == 1 and query.tags[1].name == "item"
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 3526
diff changeset
67 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
68 -- Protection against overwriting roster.pending, until we move it
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
69 and query.tags[1].attr.jid ~= "pending" then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
70 local item = query.tags[1];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
71 local from_node, from_host = jid_split(stanza.attr.from);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
72 local jid = jid_prep(item.attr.jid);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
73 local node, host, resource = jid_split(jid);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
74 if not resource and host then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
75 if jid ~= from_node.."@"..from_host then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
76 if item.attr.subscription == "remove" then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
77 local roster = session.roster;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
78 local r_item = roster[jid];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
79 if r_item then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
80 local to_bare = node and (node.."@"..host) or host; -- bare JID
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
81 if r_item.subscription == "both" or r_item.subscription == "from" or (roster.pending and roster.pending[jid]) then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
82 core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=to_bare}));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
83 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
84 if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
85 core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=to_bare}));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
86 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
87 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, jid);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
88 if success then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
89 session.send(st.reply(stanza));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
90 rm_roster_push(from_node, from_host, jid);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
91 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
92 session.send(st.error_reply(stanza, err_type, err_cond, err_msg));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
93 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
94 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
95 session.send(st.error_reply(stanza, "modify", "item-not-found"));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
96 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
97 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
98 local r_item = {name = item.attr.name, groups = {}};
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
99 if r_item.name == "" then r_item.name = nil; end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
100 if session.roster[jid] then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
101 r_item.subscription = session.roster[jid].subscription;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
102 r_item.ask = session.roster[jid].ask;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
103 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
104 r_item.subscription = "none";
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
105 end
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 3526
diff changeset
106 for _, child in ipairs(item) do
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
107 if child.name == "group" then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
108 local text = t_concat(child);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
109 if text and text ~= "" then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
110 r_item.groups[text] = true;
916
f0743928ef7e core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
111 end
177
606c433955e7 Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
112 end
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
113 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
114 local success, err_type, err_cond, err_msg = rm_add_to_roster(session, jid, r_item);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
115 if success then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
116 -- Ok, send success
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
117 session.send(st.reply(stanza));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
118 -- and push change to all resources
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
119 rm_roster_push(from_node, from_host, jid);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
120 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
121 -- Adding to roster failed
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
122 session.send(st.error_reply(stanza, err_type, err_cond, err_msg));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
123 end
102
a5b914370db5 Fixed: mod_roster now outputs all roster data (instead of just the JIDs)
Waqas Hussain <waqas20@gmail.com>
parents: 79
diff changeset
124 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
125 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
126 -- Trying to add self to roster
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
127 session.send(st.error_reply(stanza, "cancel", "not-allowed"));
30
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
129 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
130 -- Invalid JID added to roster
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
131 session.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error?
30
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
133 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
134 -- Roster set didn't include a single item, or its name wasn't 'item'
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
135 session.send(st.error_reply(stanza, "modify", "bad-request"));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
136 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
137 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
138 return true;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
139 end);
5099
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
140
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
141 module:hook_global("user-deleted", function(event)
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
142 local username, host = event.username, event.host;
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
143 if host ~= module.host then return end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
144 local bare = username .. "@" .. host;
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
145 local roster = rm_load_roster(username, host);
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
146 for jid, item in pairs(roster) do
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
147 if jid and jid ~= "pending" then
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
148 if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
149 module:send(st.presence({type="unsubscribed", from=bare, to=jid}));
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
150 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
151 if item.subscription == "both" or item.subscription == "to" or item.ask then
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
152 module:send(st.presence({type="unsubscribe", from=bare, to=jid}));
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
153 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
154 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
155 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
156 end, 300);