Annotate

plugins/mod_roster.lua @ 13262:9a86e7cbdd79

mod_storage_internal: Fix fast trimming of archive with exactly one item This method would previously never delete the first (and only) item since it works out which item should become the first item after the trim operation, which doesn't make sense when all should be removed. This also works as an optimization for when all the last item should be trimmed, thus items should be removed.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Sep 2023 13:41:54 +0200
parent 12977:74b9e05af71e
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
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5372
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
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
10 local st = require "prosody.util.stanza"
30
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
12 local jid_split = require "prosody.util.jid".split;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
13 local jid_resource = require "prosody.util.jid".resource;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
14 local jid_prep = require "prosody.util.jid".prep;
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;
8644
3b28c7728e3f mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents: 7783
diff changeset
16 local pairs = pairs;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
17
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
18 local rm_load_roster = require "prosody.core.rostermanager".load_roster;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
19 local rm_remove_from_roster = require "prosody.core.rostermanager".remove_from_roster;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
20 local rm_add_to_roster = require "prosody.core.rostermanager".add_to_roster;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12101
diff changeset
21 local rm_roster_push = require "prosody.core.rostermanager".roster_push;
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
22
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
23 module:add_feature("jabber:iq:roster");
421
63be85693710 Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents: 326
diff changeset
24
4265
d56c26c258e4 mod_roster: Remove <optional/> from roster version stream feature, as per latest specs.
Waqas Hussain <waqas20@gmail.com>
parents: 3540
diff changeset
25 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
26 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
27 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
28 if origin.username then
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
29 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
30 end
c3ea4d3f857f mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2227
diff changeset
31 end);
1133
b293d7dc6a45 mod_roster: Advertize roster versioning support
Waqas Hussain <waqas20@gmail.com>
parents: 928
diff changeset
32
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
33 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
34 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
35
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
36 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
37 local roster = st.reply(stanza);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5372
diff changeset
38
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
39 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
40 local server_ver = tonumber(session.roster[false].version or 1);
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5372
diff changeset
41
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
42 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
43 roster:query("jabber:iq:roster");
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
44 -- 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
45 for jid, item in pairs(session.roster) do
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 5776
diff changeset
46 if jid then
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
47 roster:tag("item", {
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
48 jid = jid,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
49 subscription = item.subscription,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
50 ask = item.ask,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
51 name = item.name,
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
52 });
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
53 for group in pairs(item.groups) do
8646
a267dfa9d81d mod_roster: Use new :text_tag()
Kim Alvefur <zash@zash.se>
parents: 8644
diff changeset
54 roster:text_tag("group", group);
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
55 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
56 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
57 end
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 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
60 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
61 session.send(roster);
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
62 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
63 else -- stanza.attr.type == "set"
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
64 local query = stanza.tags[1];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
65 if #query.tags == 1 and query.tags[1].name == "item"
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 5776
diff changeset
66 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid then
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
67 local item = query.tags[1];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
68 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
69 local jid = jid_prep(item.attr.jid);
12101
7cd94469d15f mod_roster: Improve readability of bare-JID check
Kim Alvefur <zash@zash.se>
parents: 12100
diff changeset
70 if jid and not jid_resource(jid) then
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
71 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
72 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
73 local roster = session.roster;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
74 local r_item = roster[jid];
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
75 if r_item then
7331
c8ad387aab1c mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents: 6613
diff changeset
76 module:fire_event("roster-item-removed", {
12100
0b14b541fd27 mod_roster: pass correct username to roster-item-removed
Jonas Schäfer <jonas@wielicki.name>
parents: 8646
diff changeset
77 username = from_node, jid = jid, item = r_item, origin = session, roster = roster,
7331
c8ad387aab1c mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents: 6613
diff changeset
78 });
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
79 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
80 if success then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
81 session.send(st.reply(stanza));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
82 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
83 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
84 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
85 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
86 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
87 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
88 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
89 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
90 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
91 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
92 if session.roster[jid] then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
93 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
94 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
95 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
96 r_item.subscription = "none";
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
97 end
8644
3b28c7728e3f mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents: 7783
diff changeset
98 for group in item:childtags("group") do
3b28c7728e3f mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents: 7783
diff changeset
99 local text = group:get_text();
3b28c7728e3f mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents: 7783
diff changeset
100 if text then
3b28c7728e3f mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents: 7783
diff changeset
101 r_item.groups[text] = true;
177
606c433955e7 Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
102 end
108
1d79da482c5d Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents: 102
diff changeset
103 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
104 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
105 if success then
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
106 -- Ok, send success
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
107 session.send(st.reply(stanza));
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
108 -- 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
109 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
110 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
111 -- Adding to roster failed
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
112 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
113 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
114 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
115 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
116 -- 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
117 session.send(st.error_reply(stanza, "cancel", "not-allowed"));
30
bcf539295f2d Huge commit to:
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
119 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
120 -- Invalid JID added to roster
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
121 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
122 end
3525
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
123 else
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
124 -- 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
125 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
126 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
127 end
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
128 return true;
1e44e7e8e79c mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 3323
diff changeset
129 end);
5099
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
130
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
131 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
132 local username, host = event.username, event.host;
7333
9d0e65d919e8 mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents: 7331
diff changeset
133 local origin = event.origin or prosody.hosts[host];
5099
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
134 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
135 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
136 for jid, item in pairs(roster) do
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 5776
diff changeset
137 if jid then
7333
9d0e65d919e8 mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents: 7331
diff changeset
138 module:fire_event("roster-item-removed", {
9d0e65d919e8 mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents: 7331
diff changeset
139 username = username, jid = jid, item = item, roster = roster, origin = origin,
9d0e65d919e8 mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents: 7331
diff changeset
140 });
7334
566d0a56b37f mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents: 7333
diff changeset
141 else
7783
f54c960240da mod_roster: Rename variable to silence shadowing warning [luacheck]
Kim Alvefur <zash@zash.se>
parents: 7782
diff changeset
142 for pending_jid in pairs(item.pending) do
7334
566d0a56b37f mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents: 7333
diff changeset
143 module:fire_event("roster-item-removed", {
7783
f54c960240da mod_roster: Rename variable to silence shadowing warning [luacheck]
Kim Alvefur <zash@zash.se>
parents: 7782
diff changeset
144 username = username, jid = pending_jid, roster = roster, origin = origin,
7334
566d0a56b37f mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents: 7333
diff changeset
145 });
566d0a56b37f mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents: 7333
diff changeset
146 end
5099
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
147 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
148 end
39eb688e106a mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents: 5013
diff changeset
149 end, 300);