Software /
code /
prosody
Annotate
plugins/muc/members_only.lib.lua @ 13229:bb7177efbf41
plugins: Use boolean config method in some places
Because it makes sense and improves feedback via logging
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 Jul 2023 12:38:16 +0200 |
parent | 12977:74b9e05af71e |
rev | line source |
---|---|
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
1 -- Prosody IM |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
4 -- Copyright (C) 2014 Daurnimator |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
5 -- |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
8 -- |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
9 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12029
diff
changeset
|
10 local st = require "prosody.util.stanza"; |
6329
6b3eb1611587
mod_muc: Import util.stanza into the config handler modules that need it. Fixes #432.
Matthew Wild <mwild1@gmail.com>
parents:
6230
diff
changeset
|
11 |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
12 local muc_util = module:require "muc/util"; |
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6991
diff
changeset
|
13 local valid_affiliations = muc_util.valid_affiliations; |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
14 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
15 local function get_members_only(room) |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
16 return room._data.members_only; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
17 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
18 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
19 local function set_members_only(room, members_only) |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
20 members_only = members_only and true or nil; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
21 if room._data.members_only == members_only then return false; end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
22 room._data.members_only = members_only; |
6477
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
23 if members_only then |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
24 --[[ |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
25 If as a result of a change in the room configuration the room type is |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
26 changed to members-only but there are non-members in the room, |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
27 the service MUST remove any non-members from the room and include a |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
28 status code of 322 in the presence unavailable stanzas sent to those users |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
29 as well as any remaining occupants. |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
30 ]] |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
31 local occupants_changed = {}; |
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6991
diff
changeset
|
32 for _, occupant in room:each_occupant() do |
6477
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
33 local affiliation = room:get_affiliation(occupant.bare_jid); |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
34 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
35 occupant.role = nil; |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
36 room:save_occupant(occupant); |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
37 occupants_changed[occupant] = true; |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
38 end |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
39 end |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
40 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
41 :tag("status", {code="322"}):up(); |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
42 for occupant in pairs(occupants_changed) do |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
43 room:publicise_occupant_status(occupant, x); |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
44 module:fire_event("muc-occupant-left", {room = room; nick = occupant.nick; occupant = occupant;}); |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
45 end |
29f979f554d3
plugins/muc/members_only: Kick non-members when members-only is turned on
daurnimator <quae@daurnimator.com>
parents:
6329
diff
changeset
|
46 end |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
47 return true; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
48 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
49 |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
50 local function get_allow_member_invites(room) |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
51 return room._data.allow_member_invites; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
52 end |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
53 |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
54 -- Allows members to invite new members into a members-only room, |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
55 -- effectively creating an invite-only room |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
56 local function set_allow_member_invites(room, allow_member_invites) |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
57 allow_member_invites = allow_member_invites and true or nil; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
58 if room._data.allow_member_invites == allow_member_invites then return false; end |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
59 room._data.allow_member_invites = allow_member_invites; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
60 return true; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
61 end |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
62 |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
63 module:hook("muc-disco#info", function(event) |
11545
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
64 local members_only_room = not not get_members_only(event.room); |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
65 local members_can_invite = not not get_allow_member_invites(event.room); |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
66 event.reply:tag("feature", {var = members_only_room and "muc_membersonly" or "muc_open"}):up(); |
8985
4101bcf9639a
MUC: Add allowmemberinvites to disco#info so clients know whether to allow users to invite others in a members-only room
Matthew Wild <mwild1@gmail.com>
parents:
8976
diff
changeset
|
67 table.insert(event.form, { |
4101bcf9639a
MUC: Add allowmemberinvites to disco#info so clients know whether to allow users to invite others in a members-only room
Matthew Wild <mwild1@gmail.com>
parents:
8976
diff
changeset
|
68 name = "{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites"; |
9034
1c709e3d2e5e
MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents:
8987
diff
changeset
|
69 label = "Allow members to invite new members"; |
8985
4101bcf9639a
MUC: Add allowmemberinvites to disco#info so clients know whether to allow users to invite others in a members-only room
Matthew Wild <mwild1@gmail.com>
parents:
8976
diff
changeset
|
70 type = "boolean"; |
11545
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
71 value = members_can_invite; |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
72 }); |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
73 table.insert(event.form, { |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
74 name = "muc#roomconfig_allowinvites"; |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
75 label = "Allow users to invite other users"; |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
76 type = "boolean"; |
7b8a482f4efd
MUC: Add support for advertising muc#roomconfig_allowinvites in room disco#info
Matthew Wild <mwild1@gmail.com>
parents:
9716
diff
changeset
|
77 value = not members_only_room or members_can_invite; |
8985
4101bcf9639a
MUC: Add allowmemberinvites to disco#info so clients know whether to allow users to invite others in a members-only room
Matthew Wild <mwild1@gmail.com>
parents:
8976
diff
changeset
|
78 }); |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
79 end); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
80 |
8985
4101bcf9639a
MUC: Add allowmemberinvites to disco#info so clients know whether to allow users to invite others in a members-only room
Matthew Wild <mwild1@gmail.com>
parents:
8976
diff
changeset
|
81 |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
82 module:hook("muc-config-form", function(event) |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
83 table.insert(event.form, { |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
84 name = "muc#roomconfig_membersonly"; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
85 type = "boolean"; |
9034
1c709e3d2e5e
MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents:
8987
diff
changeset
|
86 label = "Only allow members to join"; |
1c709e3d2e5e
MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents:
8987
diff
changeset
|
87 desc = "Enable this to only allow access for room owners, admins and members"; |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
88 value = get_members_only(event.room); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
89 }); |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
90 table.insert(event.form, { |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
91 name = "{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites"; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
92 type = "boolean"; |
9034
1c709e3d2e5e
MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents:
8987
diff
changeset
|
93 label = "Allow members to invite new members"; |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
94 value = get_allow_member_invites(event.room); |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
95 }); |
9035
173c0e16e704
MUC: Add sections in room config form
Matthew Wild <mwild1@gmail.com>
parents:
9034
diff
changeset
|
96 end, 90-3); |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
97 |
6991
84e01dbb739e
MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents:
6477
diff
changeset
|
98 module:hook("muc-config-submitted/muc#roomconfig_membersonly", function(event) |
84e01dbb739e
MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents:
6477
diff
changeset
|
99 if set_members_only(event.room, event.value) then |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
100 event.status_codes["104"] = true; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
101 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
102 end); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
103 |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
104 module:hook("muc-config-submitted/{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites", function(event) |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
105 if set_allow_member_invites(event.room, event.value) then |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
106 event.status_codes["104"] = true; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
107 end |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
108 end); |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
109 |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
110 -- No affiliation => role of "none" |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
111 module:hook("muc-get-default-role", function(event) |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
112 if not event.affiliation and get_members_only(event.room) then |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
113 return false; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
114 end |
9716
5281a795d6df
MUC: Adjust priorities of muc-get-default-role handlers (fixes #1272)
Matthew Wild <mwild1@gmail.com>
parents:
9035
diff
changeset
|
115 end, 2); |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
116 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
117 -- registration required for entering members-only room |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
118 module:hook("muc-occupant-pre-join", function(event) |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
119 local room = event.room; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
120 if get_members_only(room) then |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
121 local stanza = event.stanza; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
122 local affiliation = room:get_affiliation(stanza.attr.from); |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
123 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then |
10449
2e36a54906e4
MUC: Indicate that the room is the origin of various errors where 'from' is an occupant JID
Kim Alvefur <zash@zash.se>
parents:
9716
diff
changeset
|
124 local reply = st.error_reply(stanza, "auth", "registration-required", nil, room.jid):up(); |
12029
631b2afa7bc1
MUC: Remove <{muc}x> tags in some errors
Kim Alvefur <zash@zash.se>
parents:
12027
diff
changeset
|
125 event.origin.send(reply); |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
126 return true; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
127 end |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
128 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
129 end, -5); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
130 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
131 -- Invitation privileges in members-only rooms SHOULD be restricted to room admins; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
132 -- if a member without privileges to edit the member list attempts to invite another user |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
133 -- the service SHOULD return a <forbidden/> error to the occupant |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
134 module:hook("muc-pre-invite", function(event) |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
135 local room = event.room; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
136 if get_members_only(room) then |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
137 local stanza = event.stanza; |
8987
596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
Matthew Wild <mwild1@gmail.com>
parents:
8985
diff
changeset
|
138 local inviter_affiliation = room:get_affiliation(stanza.attr.from) or "none"; |
596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
Matthew Wild <mwild1@gmail.com>
parents:
8985
diff
changeset
|
139 local required_affiliation = room._data.allow_member_invites and "member" or "admin"; |
596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
Matthew Wild <mwild1@gmail.com>
parents:
8985
diff
changeset
|
140 if valid_affiliations[inviter_affiliation] < valid_affiliations[required_affiliation] then |
10449
2e36a54906e4
MUC: Indicate that the room is the origin of various errors where 'from' is an occupant JID
Kim Alvefur <zash@zash.se>
parents:
9716
diff
changeset
|
141 event.origin.send(st.error_reply(stanza, "auth", "forbidden", nil, room.jid)); |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
142 return true; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
143 end |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
144 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
145 end); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
146 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
147 -- When an invite is sent; add an affiliation for the invitee |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
148 module:hook("muc-invite", function(event) |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
149 local room = event.room; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
150 if get_members_only(room) then |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
151 local stanza = event.stanza; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
152 local invitee = stanza.attr.to; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
153 local affiliation = room:get_affiliation(invitee); |
8987
596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
Matthew Wild <mwild1@gmail.com>
parents:
8985
diff
changeset
|
154 local invited_unaffiliated = valid_affiliations[affiliation or "none"] <= valid_affiliations.none; |
596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
Matthew Wild <mwild1@gmail.com>
parents:
8985
diff
changeset
|
155 if invited_unaffiliated then |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
156 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user") |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
157 :get_child("invite").attr.from; |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
158 module:log("debug", "%s invited %s into members only room %s, granting membership", |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
159 from, invitee, room.jid); |
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
160 -- This might fail; ignore for now |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
161 room:set_affiliation(true, invitee, "member", "Invited by " .. from); |
7353
ca31d3271cf8
MUC: Save room to storage once after form processing, not in each individual setter
Kim Alvefur <zash@zash.se>
parents:
7352
diff
changeset
|
162 room:save(); |
6230
97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
163 end |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
164 end |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
165 end); |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
166 |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
167 return { |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
168 get = get_members_only; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
169 set = set_members_only; |
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
170 get_allow_member_invites = get_allow_member_invites; |
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
7401
diff
changeset
|
171 set_allow_member_invites = set_allow_member_invites; |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
172 }; |