Software /
code /
prosody
Annotate
plugins/mod_roster.lua @ 13599:54803fb5b4d4
prosodyctl: passwd: Use user:password() shell command for implementation
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 07 Jan 2025 19:25:35 +0000 |
parent | 13584:0f265142117a |
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 | 5 -- This project is MIT/X11 licensed. Please see the |
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 | 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 |
13584
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
18 local rostermanager = require "prosody.core.rostermanager"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
19 local rm_load_roster = rostermanager.load_roster; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
20 local rm_remove_from_roster = rostermanager.remove_from_roster; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
21 local rm_add_to_roster = rostermanager.add_to_roster; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
22 local rm_roster_push = rostermanager.roster_push; |
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); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5372
diff
changeset
|
39 |
3525
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); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5372
diff
changeset
|
42 |
3525
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 |
6613
2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
47 if jid then |
3525
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 |
8646
a267dfa9d81d
mod_roster: Use new :text_tag()
Kim Alvefur <zash@zash.se>
parents:
8644
diff
changeset
|
55 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
|
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 |
13566
2fb4ce131131
mod_roster: do not store number in attribute
Jonas Schäfer <jonas@wielicki.name>
parents:
12977
diff
changeset
|
60 roster.tags[1].attr.ver = tostring(server_ver); |
3525
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" |
6613
2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
67 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
|
68 local item = query.tags[1]; |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 local roster = session.roster; |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
75 local r_item = roster[jid]; |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 }); |
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
80 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
|
81 if success then |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
82 session.send(st.reply(stanza)); |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
83 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
|
84 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
85 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
|
86 end |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
87 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
88 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
|
89 end |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
90 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
91 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
|
92 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
|
93 if session.roster[jid] then |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
94 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
|
95 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
|
96 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
97 r_item.subscription = "none"; |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
98 end |
8644
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
99 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
|
100 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
|
101 if text then |
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
102 r_item.groups[text] = true; |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
103 end |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
104 end |
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
105 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
|
106 if success then |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
107 -- Ok, send success |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
108 session.send(st.reply(stanza)); |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
109 -- 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
|
110 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
|
111 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
112 -- Adding to roster failed |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
113 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
|
114 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
|
115 end |
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
116 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
117 -- 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
|
118 session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
30 | 119 end |
3525
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 -- Invalid JID added to roster |
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, "modify", "bad-request")); -- FIXME what's the correct error? |
30 | 123 end |
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
124 else |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
125 -- 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
|
126 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
|
127 end |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
128 end |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
129 return true; |
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
130 end); |
5099
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
131 |
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 }); |
7334
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
142 else |
7783
f54c960240da
mod_roster: Rename variable to silence shadowing warning [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7782
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 }); |
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
147 end |
5099
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 |
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
150 end, 300); |
13584
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
151 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
152 -- API/commands |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
153 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
154 -- Make a *one-way* subscription. User will see when contact is online, |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
155 -- contact will not see when user is online. |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
156 function subscribe(user_jid, contact_jid) |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
157 local user_username, user_host = jid_split(user_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
158 local contact_username, contact_host = jid_split(contact_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
159 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
160 -- Update user's roster to say subscription request is pending. Bare hosts (e.g. components) don't have rosters. |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
161 if user_username ~= nil then |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
162 rostermanager.set_contact_pending_out(user_username, user_host, contact_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
163 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
164 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
165 if prosody.hosts[contact_host] then -- Sending to a local host? |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
166 -- Update contact's roster to say subscription request is pending... |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
167 rostermanager.set_contact_pending_in(contact_username, contact_host, user_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
168 -- Update contact's roster to say subscription request approved... |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
169 rostermanager.subscribed(contact_username, contact_host, user_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
170 -- Update user's roster to say subscription request approved. Bare hosts (e.g. components) don't have rosters. |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
171 if user_username ~= nil then |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
172 rostermanager.process_inbound_subscription_approval(user_username, user_host, contact_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
173 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
174 else |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
175 -- Send a subscription request |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
176 local sub_request = st.presence({ from = user_jid, to = contact_jid, type = "subscribe" }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
177 module:send(sub_request); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
178 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
179 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
180 return true; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
181 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
182 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
183 -- Make a mutual subscription between jid1 and jid2. Each JID will see |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
184 -- when the other one is online. |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
185 function subscribe_both(jid1, jid2) |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
186 local ok1, err1 = subscribe(jid1, jid2); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
187 local ok2, err2 = subscribe(jid2, jid1); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
188 return ok1 and ok2, err1 or err2; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
189 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
190 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
191 -- Unsubscribes user from contact (not contact from user, if subscribed). |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
192 function unsubscribe(user_jid, contact_jid) |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
193 local user_username, user_host = jid_split(user_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
194 local contact_username, contact_host = jid_split(contact_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
195 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
196 -- Update user's roster to say subscription is cancelled... |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
197 rostermanager.unsubscribe(user_username, user_host, contact_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
198 if prosody.hosts[contact_host] then -- Local host? |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
199 -- Update contact's roster to say subscription is cancelled... |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
200 rostermanager.unsubscribed(contact_username, contact_host, user_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
201 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
202 return true; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
203 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
204 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
205 -- Cancel any subscription in either direction. |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
206 function unsubscribe_both(jid1, jid2) |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
207 local ok1 = unsubscribe(jid1, jid2); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
208 local ok2 = unsubscribe(jid2, jid1); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
209 return ok1 and ok2; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
210 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
211 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
212 module:add_item("shell-command", { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
213 section = "roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
214 section_desc = "View and manage user rosters (contact lists)"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
215 name = "show"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
216 desc = "Show a user's current roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
217 args = { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
218 { name = "jid", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
219 { name = "sub", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
220 }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
221 host_selector = "jid"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
222 handler = function(self, jid, sub) --luacheck: ignore 212/self |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
223 local print = self.session.print; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
224 local it = require "prosody.util.iterators"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
225 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
226 local roster = assert(rm_load_roster(jid_split(jid))); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
227 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
228 local function sort_func(a, b) |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
229 if type(a) == "string" and type(b) == "string" then |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
230 return a < b; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
231 else |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
232 return a == false; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
233 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
234 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
235 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
236 local count = 0; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
237 if sub == "pending" then |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
238 local pending_subs = roster[false].pending or {}; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
239 for pending_jid in it.sorted_pairs(pending_subs) do |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
240 print(pending_jid); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
241 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
242 else |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
243 for contact, item in it.sorted_pairs(roster, sort_func) do |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
244 if contact and (not sub or sub == item.subscription) then |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
245 count = count + 1; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
246 print(contact, ("sub=%s\task=%s"):format(item.subscription or "none", item.ask or "none")); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
247 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
248 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
249 end |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
250 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
251 return true, ("Showing %d entries"):format(count); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
252 end; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
253 }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
254 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
255 module:add_item("shell-command", { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
256 section = "roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
257 section_desc = "View and manage user rosters (contact lists)"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
258 name = "subscribe"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
259 desc = "Subscribe a user to another JID"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
260 args = { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
261 { name = "jid", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
262 { name = "contact", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
263 }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
264 host_selector = "jid"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
265 handler = function(self, jid, contact) --luacheck: ignore 212/self |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
266 return subscribe(jid, contact); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
267 end; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
268 }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
269 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
270 module:add_item("shell-command", { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
271 section = "roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
272 section_desc = "View and manage user rosters (contact lists)"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
273 name = "subscribe_both"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
274 desc = "Subscribe a user and a contact JID to each other"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
275 args = { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
276 { name = "jid", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
277 { name = "contact", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
278 }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
279 host_selector = "jid"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
280 handler = function(self, jid, contact) --luacheck: ignore 212/self |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
281 return subscribe_both(jid, contact); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
282 end; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
283 }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
284 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
285 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
286 module:add_item("shell-command", { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
287 section = "roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
288 section_desc = "View and manage user rosters (contact lists)"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
289 name = "unsubscribe"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
290 desc = "Unsubscribe a user from another JID"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
291 args = { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
292 { name = "jid", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
293 { name = "contact", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
294 }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
295 host_selector = "jid"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
296 handler = function(self, jid, contact) --luacheck: ignore 212/self |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
297 return unsubscribe(jid, contact); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
298 end; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
299 }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
300 |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
301 module:add_item("shell-command", { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
302 section = "roster"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
303 section_desc = "View and manage user rosters (contact lists)"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
304 name = "unsubscribe_both"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
305 desc = "Unubscribe a user and a contact JID from each other"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
306 args = { |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
307 { name = "jid", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
308 { name = "contact", type = "string" }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
309 }; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
310 host_selector = "jid"; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
311 handler = function(self, jid, contact) --luacheck: ignore 212/self |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
312 return unsubscribe_both(jid, contact); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
313 end; |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
314 }); |
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
315 |