Software /
code /
prosody
Annotate
plugins/muc/muc.lib.lua @ 7405:5a65750d959a
MUC: Be more careful with deserialization of rooms, fix case where a bare jid has joined as multiple participants
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 27 Apr 2016 18:55:49 +0200 |
parent | 7402:ef7ea3bad7a1 |
child | 7406:92755ca737c3 |
rev | line source |
---|---|
1734 | 1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2864
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2864
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
6102
385772166289
plugins/muc/muc: Add copyright for daurnimator
daurnimator <quae@daurnimator.com>
parents:
6101
diff
changeset
|
4 -- Copyright (C) 2014 Daurnimator |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
5 -- |
1734 | 6 -- This project is MIT/X11 licensed. Please see the |
7 -- COPYING file in the source package for more information. | |
8 -- | |
9 | |
3281
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
10 local select = select; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
11 local pairs = pairs; |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
12 local next = next; |
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
13 local setmetatable = setmetatable; |
1734 | 14 |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
15 local dataform = require "util.dataforms"; |
6217
657c707d9229
plugins/muc/muc.lib: Use util.iterators to count occupants
daurnimator <quae@daurnimator.com>
parents:
6216
diff
changeset
|
16 local iterators = require "util.iterators"; |
1734 | 17 local jid_split = require "util.jid".split; |
18 local jid_bare = require "util.jid".bare; | |
1862
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
19 local jid_prep = require "util.jid".prep; |
6476
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
20 local jid_join = require "util.jid".join; |
1734 | 21 local st = require "util.stanza"; |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
22 local base64 = require "util.encodings".base64; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
23 local md5 = require "util.hashes".md5; |
1734 | 24 |
7270
df22e314946c
MUC: Use already initialized logger
Kim Alvefur <zash@zash.se>
parents:
7120
diff
changeset
|
25 local log = module._log; |
5612
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
26 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
27 local occupant_lib = module:require "muc/occupant" |
6218
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
28 local muc_util = module:require "muc/util"; |
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
29 local is_kickable_error = muc_util.is_kickable_error; |
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
30 local valid_roles, valid_affiliations = muc_util.valid_roles, muc_util.valid_affiliations; |
1734 | 31 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
32 local room_mt = {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
33 room_mt.__index = room_mt; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
34 |
5519
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
35 function room_mt:__tostring() |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
36 return "MUC room ("..self.jid..")"; |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
37 end |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
38 |
7352
50b24b3476e6
MUC: Provide a noop stub room:save() method
Kim Alvefur <zash@zash.se>
parents:
7347
diff
changeset
|
39 function room_mt.save() |
50b24b3476e6
MUC: Provide a noop stub room:save() method
Kim Alvefur <zash@zash.se>
parents:
7347
diff
changeset
|
40 -- overriden by mod_muc.lua |
50b24b3476e6
MUC: Provide a noop stub room:save() method
Kim Alvefur <zash@zash.se>
parents:
7347
diff
changeset
|
41 end |
50b24b3476e6
MUC: Provide a noop stub room:save() method
Kim Alvefur <zash@zash.se>
parents:
7347
diff
changeset
|
42 |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
43 function room_mt:get_occupant_jid(real_jid) |
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
44 return self._jid_nick[real_jid] |
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
45 end |
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
46 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
47 function room_mt:get_default_role(affiliation) |
6220
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
48 local role = module:fire_event("muc-get-default-role", { |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
49 room = self; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
50 affiliation = affiliation; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
51 affiliation_rank = valid_affiliations[affiliation or "none"]; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
52 }); |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
53 return role, valid_roles[role or "none"]; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
54 end |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
55 module:hook("muc-get-default-role", function(event) |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
56 if event.affiliation_rank >= valid_affiliations.admin then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
57 return "moderator"; |
6226
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
58 elseif event.affiliation_rank >= valid_affiliations.none then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
59 return "participant"; |
6220
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
60 end |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
61 end); |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
62 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
63 --- Occupant functions |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
64 function room_mt:new_occupant(bare_real_jid, nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
65 local occupant = occupant_lib.new(bare_real_jid, nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
66 local affiliation = self:get_affiliation(bare_real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
67 occupant.role = self:get_default_role(affiliation); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
68 return occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
69 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
70 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
71 function room_mt:get_occupant_by_nick(nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
72 local occupant = self._occupants[nick]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
73 if occupant == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
74 return occupant_lib.copy(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
75 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
76 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
77 do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
78 local function next_copied_occupant(occupants, occupant_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
79 local next_occupant_jid, raw_occupant = next(occupants, occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
80 if next_occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
81 return next_occupant_jid, occupant_lib.copy(raw_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
82 end |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
83 -- FIXME Explain what 'read_only' is supposed to be |
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
84 function room_mt:each_occupant(read_only) -- luacheck: ignore 212 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
85 return next_copied_occupant, self._occupants, nil; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
86 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
87 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
88 |
6237
a58685df9d16
plugins/muc: Add room:has_occupant() method
daurnimator <quae@daurnimator.com>
parents:
6231
diff
changeset
|
89 function room_mt:has_occupant() |
a58685df9d16
plugins/muc: Add room:has_occupant() method
daurnimator <quae@daurnimator.com>
parents:
6231
diff
changeset
|
90 return next(self._occupants, nil) ~= nil |
a58685df9d16
plugins/muc: Add room:has_occupant() method
daurnimator <quae@daurnimator.com>
parents:
6231
diff
changeset
|
91 end |
a58685df9d16
plugins/muc: Add room:has_occupant() method
daurnimator <quae@daurnimator.com>
parents:
6231
diff
changeset
|
92 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
93 function room_mt:get_occupant_by_real_jid(real_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
94 local occupant_jid = self:get_occupant_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
95 if occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
96 return self:get_occupant_by_nick(occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
97 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
98 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
99 function room_mt:save_occupant(occupant) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
100 occupant = occupant_lib.copy(occupant); -- So that occupant can be modified more |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
101 local id = occupant.nick |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
102 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
103 -- Need to maintain _jid_nick secondary index |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
104 local old_occupant = self._occupants[id]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
105 if old_occupant then |
6451
385932a83013
plugins/muc/muc.lib: Use occupants iterator instead of assuming pairs
daurnimator <quae@daurnimator.com>
parents:
6431
diff
changeset
|
106 for real_jid in old_occupant:each_session() do |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
107 self._jid_nick[real_jid] = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
108 end |
1734 | 109 end |
6250
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
110 |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
111 local has_live_session = false |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
112 if occupant.role ~= nil then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
113 for real_jid, presence in occupant:each_session() do |
6250
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
114 if presence.attr.type == nil then |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
115 has_live_session = true |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
116 self._jid_nick[real_jid] = occupant.nick; |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
117 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
118 end |
6250
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
119 if not has_live_session then |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
120 -- Has no live sessions left; they have left the room. |
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
121 occupant.role = nil |
1734 | 122 end |
123 end | |
6250
454ef19e7925
plugins/muc/muc: Better check for live sessions
daurnimator <quae@daurnimator.com>
parents:
6249
diff
changeset
|
124 if not has_live_session then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
125 occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
126 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
127 self._occupants[id] = occupant |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
128 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
129 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
130 function room_mt:route_to_occupant(occupant, stanza) |
6130
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
131 local to = stanza.attr.to; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
132 for jid in occupant:each_session() do |
6253
2df9e7a67e56
plugins/muc/muc.lib: Even unavailable session need to be routed to sometimes (e.g. their own leave)
daurnimator <quae@daurnimator.com>
parents:
6252
diff
changeset
|
133 stanza.attr.to = jid; |
2df9e7a67e56
plugins/muc/muc.lib: Even unavailable session need to be routed to sometimes (e.g. their own leave)
daurnimator <quae@daurnimator.com>
parents:
6252
diff
changeset
|
134 self:route_stanza(stanza); |
6130
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
135 end |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
136 stanza.attr.to = to; |
6130
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
137 end |
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
138 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
139 -- actor is the attribute table |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
140 local function add_item(x, affiliation, role, jid, nick, actor_nick, actor_jid, reason) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
141 x:tag("item", {affiliation = affiliation; role = role; jid = jid; nick = nick;}) |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
142 if actor_nick or actor_jid then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
143 x:tag("actor", {nick = actor_nick; jid = actor_jid;}):up() |
1734 | 144 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
145 if reason then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
146 x:tag("reason"):text(reason):up() |
1734 | 147 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
148 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
149 return x |
1734 | 150 end |
6213
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
151 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
152 -- actor is (real) jid |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
153 function room_mt:build_item_list(occupant, x, is_anonymous, nick, actor_nick, actor_jid, reason) |
6213
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
154 local affiliation = self:get_affiliation(occupant.bare_jid) or "none"; |
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
155 local role = occupant.role or "none"; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
156 if is_anonymous then |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
157 add_item(x, affiliation, role, nil, nick, actor_nick, actor_jid, reason); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
158 else |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
159 for real_jid in occupant:each_session() do |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
160 add_item(x, affiliation, role, real_jid, nick, actor_nick, actor_jid, reason); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
161 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
162 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
163 return x |
5982
2d5685c6262f
MUC: Split saving to history into a separate method
Kim Alvefur <zash@zash.se>
parents:
5854
diff
changeset
|
164 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
165 |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
166 function room_mt:broadcast_message(stanza) |
6410
d782cbb46c2a
plugins/muc/muc.lib: Allow plugins to reject broadcasts in the muc-broadcast-message event.
daurnimator <quae@daurnimator.com>
parents:
6394
diff
changeset
|
167 if module:fire_event("muc-broadcast-message", {room = self, stanza = stanza}) then |
d782cbb46c2a
plugins/muc/muc.lib: Allow plugins to reject broadcasts in the muc-broadcast-message event.
daurnimator <quae@daurnimator.com>
parents:
6394
diff
changeset
|
168 return true; |
d782cbb46c2a
plugins/muc/muc.lib: Allow plugins to reject broadcasts in the muc-broadcast-message event.
daurnimator <quae@daurnimator.com>
parents:
6394
diff
changeset
|
169 end |
6140
e4cdb3e5d7d0
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
daurnimator <quae@daurnimator.com>
parents:
6139
diff
changeset
|
170 self:broadcast(stanza); |
6410
d782cbb46c2a
plugins/muc/muc.lib: Allow plugins to reject broadcasts in the muc-broadcast-message event.
daurnimator <quae@daurnimator.com>
parents:
6394
diff
changeset
|
171 return true; |
6137
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
172 end |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
173 |
6140
e4cdb3e5d7d0
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
daurnimator <quae@daurnimator.com>
parents:
6139
diff
changeset
|
174 -- Broadcast a stanza to all occupants in the room. |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
175 -- optionally checks conditional called with (nick, occupant) |
6140
e4cdb3e5d7d0
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
daurnimator <quae@daurnimator.com>
parents:
6139
diff
changeset
|
176 function room_mt:broadcast(stanza, cond_func) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
177 for nick, occupant in self:each_occupant() do |
6140
e4cdb3e5d7d0
plugins/muc/muc.lib: Add :broadcast method; use it from :broadcast_except_nick and :broadcast_message
daurnimator <quae@daurnimator.com>
parents:
6139
diff
changeset
|
178 if cond_func == nil or cond_func(nick, occupant) then |
6133
5d8949bb15b0
plugins/muc/muc.lib: Additional `route_to_occupant` usage
daurnimator <quae@daurnimator.com>
parents:
6132
diff
changeset
|
179 self:route_to_occupant(occupant, stanza) |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
180 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
181 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
182 end |
1734 | 183 |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
184 local function can_see_real_jids(whois, occupant) |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
185 if whois == "anyone" then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
186 return true; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
187 elseif whois == "moderators" then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
188 return valid_roles[occupant.role or "none"] >= valid_roles.moderator; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
189 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
190 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
191 |
6278
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
192 -- Broadcasts an occupant's presence to the whole room |
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
193 -- Takes the x element that goes into the stanzas |
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
194 function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason) |
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
195 -- Build real jid and (optionally) occupant jid template presences |
6801
5032d4817a30
plugins/muc/muc.lib: Fix issue #505 where unavailable presences were never used
daurnimator <quae@daurnimator.com>
parents:
6776
diff
changeset
|
196 local base_presence do |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
197 -- Try to use main jid's presence |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
198 local pr = occupant:get_presence(); |
7397
e49737de9872
MUC: Fix logic for when to broadcast unavailable presence (actual fix for 14170d161b39)
Kim Alvefur <zash@zash.se>
parents:
7396
diff
changeset
|
199 if pr and (pr.attr.type ~= "unavailable" and occupant.role ~= nil) then |
6278
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
200 base_presence = st.clone(pr); |
6801
5032d4817a30
plugins/muc/muc.lib: Fix issue #505 where unavailable presences were never used
daurnimator <quae@daurnimator.com>
parents:
6776
diff
changeset
|
201 else -- user is leaving but didn't send a leave presence. make one for them |
5032d4817a30
plugins/muc/muc.lib: Fix issue #505 where unavailable presences were never used
daurnimator <quae@daurnimator.com>
parents:
6776
diff
changeset
|
202 base_presence = st.presence {from = occupant.nick; type = "unavailable";}; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
203 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
204 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
205 |
6278
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
206 -- Fire event (before full_p and anon_p are created) |
6513
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
207 local event = { |
6317
ec57067c1e0d
mod_muc/muc.lib: Pass all info to muc-broadcast-presence handlers that would be required to use room:build_item_list() - useful for plugins
Matthew Wild <mwild1@gmail.com>
parents:
6278
diff
changeset
|
208 room = self; stanza = base_presence; x = base_x; |
6318
e5e7a789ef55
mod_muc/muc.lib: Remove is_anonymous from event (fix for ec57067c1e0d)
Matthew Wild <mwild1@gmail.com>
parents:
6317
diff
changeset
|
209 occupant = occupant; nick = nick; actor = actor; |
e5e7a789ef55
mod_muc/muc.lib: Remove is_anonymous from event (fix for ec57067c1e0d)
Matthew Wild <mwild1@gmail.com>
parents:
6317
diff
changeset
|
210 reason = reason; |
6513
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
211 } |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
212 module:fire_event("muc-broadcast-presence", event); |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
213 |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
214 -- Allow muc-broadcast-presence listeners to change things |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
215 nick = event.nick; |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
216 actor = event.actor; |
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
217 reason = event.reason; |
6278
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
218 |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
219 local whois = self:get_whois(); |
6513
3bbd59c03aeb
plugins/muc/muc.lib: Allow muc-broadcast-presence event listeners to modify nick, actor, reason
daurnimator <quae@daurnimator.com>
parents:
6512
diff
changeset
|
220 |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
221 local actor_nick; |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
222 if actor then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
223 actor_nick = select(3, jid_split(self:get_occupant_jid(actor))); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
224 end |
6278
fcc3ef191293
plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
daurnimator <quae@daurnimator.com>
parents:
6277
diff
changeset
|
225 |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
226 local full_p, full_x; |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
227 local function get_full_p() |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
228 if full_p == nil then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
229 full_x = st.clone(base_x); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
230 self:build_item_list(occupant, full_x, false, nick, actor_nick, actor, reason); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
231 full_p = st.clone(base_presence):add_child(full_x); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
232 end |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
233 return full_p, full_x; |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
234 end |
6266
cabeff5fc687
plugins/muc/muc.lib: Fire event for presence broadcast
daurnimator <quae@daurnimator.com>
parents:
6253
diff
changeset
|
235 |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
236 local anon_p, anon_x; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
237 local function get_anon_p() |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
238 if anon_p == nil then |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
239 anon_x = st.clone(base_x); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
240 self:build_item_list(occupant, anon_x, true, nick, actor_nick, nil, reason); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
241 anon_p = st.clone(base_presence):add_child(anon_x); |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
242 end |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
243 return anon_p, anon_x; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
244 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
245 |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
246 local self_p, self_x; |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
247 if can_see_real_jids(whois, occupant) then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
248 self_p, self_x = get_full_p(); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
249 else |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
250 -- Can always see your own full jids |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
251 -- But not allowed to see actor's |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
252 self_x = st.clone(base_x); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
253 self:build_item_list(occupant, self_x, false, nick, actor_nick, nil, reason); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
254 self_p = st.clone(base_presence):add_child(self_x); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
255 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
256 |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
257 -- General populance |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
258 for occupant_nick, n_occupant in self:each_occupant() do |
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
259 if occupant_nick ~= occupant.nick then |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
260 local pr; |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
261 if can_see_real_jids(whois, n_occupant) then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
262 pr = get_full_p(); |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
263 elseif occupant.bare_jid == n_occupant.bare_jid then |
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
264 pr = self_p; |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
265 else |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
266 pr = get_anon_p(); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
267 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
268 self:route_to_occupant(n_occupant, pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
269 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
270 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
271 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
272 -- Presences for occupant itself |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
273 self_x:tag("status", {code = "110";}):up(); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
274 if occupant.role == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
275 -- They get an unavailable |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
276 self:route_to_occupant(occupant, self_p); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
277 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
278 -- use their own presences as templates |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
279 for full_jid, pr in occupant:each_session() do |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
280 pr = st.clone(pr); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
281 pr.attr.to = full_jid; |
6512
ad159be9e9d7
plugins/muc/muc.lib: Don't expose actor jids to users when anonymous
daurnimator <quae@daurnimator.com>
parents:
6478
diff
changeset
|
282 pr:add_child(self_x); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
283 self:route_stanza(pr); |
1734 | 284 end |
285 end | |
286 end | |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
287 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
288 function room_mt:send_occupant_list(to, filter) |
6185
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
289 local to_bare = jid_bare(to); |
6269
f89d2dec2977
plugins/muc/muc.lib: Fix incorrect whois logic (thanks mva)
daurnimator <quae@daurnimator.com>
parents:
6268
diff
changeset
|
290 local is_anonymous = false; |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
291 local whois = self:get_whois(); |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
292 if whois ~= "anyone" then |
6185
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
293 local affiliation = self:get_affiliation(to); |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
294 if affiliation ~= "admin" and affiliation ~= "owner" then |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
295 local occupant = self:get_occupant_by_real_jid(to); |
6269
f89d2dec2977
plugins/muc/muc.lib: Fix incorrect whois logic (thanks mva)
daurnimator <quae@daurnimator.com>
parents:
6268
diff
changeset
|
296 if not (occupant and can_see_real_jids(whois, occupant)) then |
f89d2dec2977
plugins/muc/muc.lib: Fix incorrect whois logic (thanks mva)
daurnimator <quae@daurnimator.com>
parents:
6268
diff
changeset
|
297 is_anonymous = true; |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
298 end |
1734 | 299 end |
300 end | |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
301 for occupant_jid, occupant in self:each_occupant() do |
6184
2bfc4b12ec8f
plugins/muc/muc.lib: Allow `:send_occupant_list` to have no filter
daurnimator <quae@daurnimator.com>
parents:
6183
diff
changeset
|
302 if filter == nil or filter(occupant_jid, occupant) then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
303 local x = st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); |
6185
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
304 self:build_item_list(occupant, x, is_anonymous and to_bare ~= occupant.bare_jid); -- can always see your own jids |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
305 local pres = st.clone(occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
306 pres.attr.to = to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
307 pres:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
308 self:route_stanza(pres); |
1734 | 309 end |
310 end | |
311 end | |
312 | |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
313 function room_mt:get_disco_info(stanza) |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
314 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
315 local form = dataform.new { |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
316 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" }; |
7118
dacc07833b86
MUC: Fire a muc-disco#info event like in trunk so modules can extend the reply
Kim Alvefur <zash@zash.se>
parents:
7012
diff
changeset
|
317 }; |
7119
50b9a7e86de9
MUC: Separate form data from form in disco#info event
Kim Alvefur <zash@zash.se>
parents:
7089
diff
changeset
|
318 local formdata = {}; |
50b9a7e86de9
MUC: Separate form data from form in disco#info event
Kim Alvefur <zash@zash.se>
parents:
7089
diff
changeset
|
319 module:fire_event("muc-disco#info", {room = self; reply = reply; form = form, formdata = formdata ;}); |
50b9a7e86de9
MUC: Separate form data from form in disco#info event
Kim Alvefur <zash@zash.se>
parents:
7089
diff
changeset
|
320 reply:add_child(form:form(formdata, "result")); |
7118
dacc07833b86
MUC: Fire a muc-disco#info event like in trunk so modules can extend the reply
Kim Alvefur <zash@zash.se>
parents:
7012
diff
changeset
|
321 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
322 end |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
323 module:hook("muc-disco#info", function(event) |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
324 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up(); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
325 end); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
326 module:hook("muc-disco#info", function(event) |
7119
50b9a7e86de9
MUC: Separate form data from form in disco#info event
Kim Alvefur <zash@zash.se>
parents:
7089
diff
changeset
|
327 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants" }); |
50b9a7e86de9
MUC: Separate form data from form in disco#info event
Kim Alvefur <zash@zash.se>
parents:
7089
diff
changeset
|
328 event.formdata["muc#roominfo_occupants"] = tostring(iterators.count(event.room:each_occupant())); |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
329 end); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
330 |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
331 function room_mt:get_disco_items(stanza) |
2035
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
332 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
333 for room_jid in self:each_occupant() do |
2035
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
334 reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up(); |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
335 end |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
336 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
337 end |
1734 | 338 |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
339 function room_mt:handle_kickable(origin, stanza) -- luacheck: ignore 212 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
340 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
341 local occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
342 if occupant == nil then return nil; end |
2529
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
343 local type, condition, text = stanza:get_error(); |
3506
0f46acca11cc
MUC: Fixed traceback on presence errors lacking a condition.
Waqas Hussain <waqas20@gmail.com>
parents:
3446
diff
changeset
|
344 local error_message = "Kicked: "..(condition and condition:gsub("%-", " ") or "presence error"); |
2529
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
345 if text then |
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
346 error_message = error_message..": "..text; |
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
347 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
348 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
349 :tag('status'):text(error_message)); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
350 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
351 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
352 :tag("status", {code = "307"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
353 self:publicise_occupant_status(occupant, x); |
6454
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
354 if occupant.jid == real_jid then -- Was last session |
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
355 module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); |
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
356 end |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
357 return true; |
2529
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
358 end |
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
359 |
7366
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
360 if not module:get_option_boolean("muc_compat_create", true) then |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
361 module:hook("muc-room-pre-create", function(event) |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
362 local origin, stanza = event.origin, event.stanza; |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
363 if not stanza:get_child("x", "http://jabber.org/protocol/muc") then |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
364 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
365 return true; |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
366 end |
eb3928903009
MUC: Wrap "support" for the groupchat 1.0 join protocol in a config option to allow disabling
Kim Alvefur <zash@zash.se>
parents:
7364
diff
changeset
|
367 end, -1); |
2529
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
368 end |
7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents:
2528
diff
changeset
|
369 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
370 -- Give the room creator owner affiliation |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
371 module:hook("muc-room-pre-create", function(event) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
372 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
373 end, -1); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
374 |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
375 -- check if user is banned |
6193
b9074126639f
plugins/muc/muc.lib: Remove top level pre-join event. Assign event priorities for other handlers
daurnimator <quae@daurnimator.com>
parents:
6192
diff
changeset
|
376 module:hook("muc-occupant-pre-join", function(event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
377 local room, stanza = event.room, event.stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
378 local affiliation = room:get_affiliation(stanza.attr.from); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
379 if affiliation == "outcast" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
380 local reply = st.error_reply(stanza, "auth", "forbidden"):up(); |
6135
6b061f8c6e11
plugins/muc/muc.lib: Add muc-occupant-prejoin events; Use it for banned, members-only, password, nick-conflict and lock checks
daurnimator <quae@daurnimator.com>
parents:
6134
diff
changeset
|
381 reply.tags[1].attr.code = "403"; |
6b061f8c6e11
plugins/muc/muc.lib: Add muc-occupant-prejoin events; Use it for banned, members-only, password, nick-conflict and lock checks
daurnimator <quae@daurnimator.com>
parents:
6134
diff
changeset
|
382 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
6b061f8c6e11
plugins/muc/muc.lib: Add muc-occupant-prejoin events; Use it for banned, members-only, password, nick-conflict and lock checks
daurnimator <quae@daurnimator.com>
parents:
6134
diff
changeset
|
383 return true; |
3254
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
384 end |
6193
b9074126639f
plugins/muc/muc.lib: Remove top level pre-join event. Assign event priorities for other handlers
daurnimator <quae@daurnimator.com>
parents:
6192
diff
changeset
|
385 end, -10); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
386 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
387 function room_mt:handle_presence_to_occupant(origin, stanza) |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
388 local type = stanza.attr.type; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
389 if type == "error" then -- error, kick em out! |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
390 return self:handle_kickable(origin, stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
391 elseif type == nil or type == "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
392 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
393 local bare_jid = jid_bare(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
394 local orig_occupant, dest_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
395 local is_new_room = next(self._affiliations) == nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
396 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
397 if type == "unavailable" then return true; end -- Unavailable from someone not in the room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
398 if module:fire_event("muc-room-pre-create", { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
399 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
400 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
401 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
402 }) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
403 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
404 orig_occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
405 if type == "unavailable" and orig_occupant == nil then return true; end -- Unavailable from someone not in the room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
406 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
407 local is_first_dest_session; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
408 if type == "unavailable" then -- luacheck: ignore 542 |
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
409 -- FIXME Why the empty if branch? |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
410 -- dest_occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
411 elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
412 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
413 dest_occupant = orig_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
414 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
415 local dest_jid = stanza.attr.to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
416 dest_occupant = self:get_occupant_by_nick(dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
417 if dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
418 log("debug", "no occupant found for %s; creating new occupant object for %s", dest_jid, real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
419 is_first_dest_session = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
420 dest_occupant = self:new_occupant(bare_jid, dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
421 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
422 is_first_dest_session = false; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
423 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
424 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
425 local is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
426 if orig_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
427 -- Is there are least 2 sessions? |
6192
f97aa1f4b1f1
plugins/muc/muc.lib: Use occupant methods where possible
daurnimator <quae@daurnimator.com>
parents:
6191
diff
changeset
|
428 local iter, ob, last = orig_occupant:each_session(); |
f97aa1f4b1f1
plugins/muc/muc.lib: Use occupant methods where possible
daurnimator <quae@daurnimator.com>
parents:
6191
diff
changeset
|
429 is_last_orig_session = iter(ob, iter(ob, last)) == nil; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
430 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
431 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
432 local event, event_name = { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
433 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
434 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
435 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
436 is_first_session = is_first_dest_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
437 is_last_session = is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
438 }; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
439 if orig_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
440 event_name = "muc-occupant-pre-join"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
441 event.is_new_room = is_new_room; |
6431
540f4e33394a
muc: Add 'occupant' to muc-occupant-{joined,left,session-new} events (thanks daurnimator/fippo)
Matthew Wild <mwild1@gmail.com>
parents:
6429
diff
changeset
|
442 event.occupant = dest_occupant; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
443 elseif dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
444 event_name = "muc-occupant-pre-leave"; |
6431
540f4e33394a
muc: Add 'occupant' to muc-occupant-{joined,left,session-new} events (thanks daurnimator/fippo)
Matthew Wild <mwild1@gmail.com>
parents:
6429
diff
changeset
|
445 event.occupant = orig_occupant; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
446 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
447 event_name = "muc-occupant-pre-change"; |
6431
540f4e33394a
muc: Add 'occupant' to muc-occupant-{joined,left,session-new} events (thanks daurnimator/fippo)
Matthew Wild <mwild1@gmail.com>
parents:
6429
diff
changeset
|
448 event.orig_occupant = orig_occupant; |
540f4e33394a
muc: Add 'occupant' to muc-occupant-{joined,left,session-new} events (thanks daurnimator/fippo)
Matthew Wild <mwild1@gmail.com>
parents:
6429
diff
changeset
|
449 event.dest_occupant = dest_occupant; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
450 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
451 if module:fire_event(event_name, event) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
452 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
453 -- Check for nick conflicts |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
454 if dest_occupant ~= nil and not is_first_dest_session and bare_jid ~= jid_bare(dest_occupant.bare_jid) then -- new nick or has different bare real jid |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
455 log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
456 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
457 reply.tags[1].attr.code = "409"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
458 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
459 return true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
460 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
461 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
462 -- Send presence stanza about original occupant |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
463 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
464 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
465 local dest_nick; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
466 if dest_occupant == nil then -- Session is leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
467 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); |
6252
10b27981ea3f
plugins/muc/muc: Only set role to nil if it's the last session to leave
daurnimator <quae@daurnimator.com>
parents:
6250
diff
changeset
|
468 if is_last_orig_session then |
10b27981ea3f
plugins/muc/muc: Only set role to nil if it's the last session to leave
daurnimator <quae@daurnimator.com>
parents:
6250
diff
changeset
|
469 orig_occupant.role = nil; |
10b27981ea3f
plugins/muc/muc: Only set role to nil if it's the last session to leave
daurnimator <quae@daurnimator.com>
parents:
6250
diff
changeset
|
470 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
471 orig_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
472 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
473 log("debug", "session %s is changing from occupant %s to %s", real_jid, orig_occupant.nick, dest_occupant.nick); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
474 local generated_unavail = st.presence {from = orig_occupant.nick, to = real_jid, type = "unavailable"}; |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
475 orig_occupant:set_session(real_jid, generated_unavail); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
476 dest_nick = select(3, jid_split(dest_occupant.nick)); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
477 if not is_first_dest_session then -- User is swapping into another pre-existing session |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
478 log("debug", "session %s is swapping into multisession %s, showing it leave.", real_jid, dest_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
479 -- Show the other session leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
480 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
481 :tag("status"):text("you are joining pre-existing session " .. dest_nick):up(); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
482 add_item(x, self:get_affiliation(bare_jid), "none"); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
483 local pr = st.presence{from = dest_occupant.nick, to = real_jid, type = "unavailable"} |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
484 :add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
485 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
486 end |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
487 if is_first_dest_session and is_last_orig_session then -- Normal nick change |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
488 log("debug", "no sessions in %s left; publically marking as nick change", orig_occupant.nick); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
489 orig_x:tag("status", {code = "303";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
490 else -- The session itself always needs to see a nick change |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
491 -- don't want to get our old nick's available presence, |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
492 -- so remove our session from there, and manually generate an unavailable |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
493 orig_occupant:remove_session(real_jid); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
494 log("debug", "generating nick change for %s", real_jid); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
495 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
496 -- self:build_item_list(orig_occupant, x, false, dest_nick); -- COMPAT: clients get confused if they see other items besides their own |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
497 add_item(x, self:get_affiliation(bare_jid), orig_occupant.role, real_jid, dest_nick); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
498 x:tag("status", {code = "303";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
499 x:tag("status", {code = "110";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
500 self:route_stanza(generated_unavail:add_child(x)); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
501 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
502 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
503 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
504 self:save_occupant(orig_occupant); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
505 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
506 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
507 if is_last_orig_session then |
7346
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
508 module:fire_event("muc-occupant-left", { |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
509 room = self; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
510 nick = orig_occupant.nick; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
511 occupant = orig_occupant; |
7347
795a95258292
MUC: Include originating session and stanza in events
Kim Alvefur <zash@zash.se>
parents:
7346
diff
changeset
|
512 origin = origin; |
795a95258292
MUC: Include originating session and stanza in events
Kim Alvefur <zash@zash.se>
parents:
7346
diff
changeset
|
513 stanza = stanza; |
7346
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
514 }); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
515 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
516 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
517 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
518 if dest_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
519 dest_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
520 local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
521 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
522 dest_x:tag("status", {code = "201"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
523 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
524 if orig_occupant == nil and self:get_whois() == "anyone" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
525 dest_x:tag("status", {code = "100"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
526 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
527 self:save_occupant(dest_occupant); |
6231
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
528 |
6249
2420e308f64a
plugins/muc/muc: Always send occupant list to joining sessions
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
529 if orig_occupant == nil then |
6231
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
530 -- Send occupant list to newly joined user |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
531 self:send_occupant_list(real_jid, function(nick, occupant) -- luacheck: ignore 212 |
6231
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
532 -- Don't include self |
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
533 return occupant:get_presence(real_jid) == nil; |
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
534 end) |
bc12a8253f94
plugins/muc/muc.lib: Move sending of occupant list to joining user out of hook, and into main flow: It has to occur before publication of their status
daurnimator <quae@daurnimator.com>
parents:
6229
diff
changeset
|
535 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
536 self:publicise_occupant_status(dest_occupant, dest_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
537 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
538 if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then -- If user is swapping and wasn't last original session |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
539 log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
540 -- Show the original nick joining again |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
541 local pr = st.clone(orig_occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
542 pr.attr.to = real_jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
543 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
544 self:build_item_list(orig_occupant, x, false); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
545 -- TODO: new status code to inform client this was the multi-session it left? |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
546 pr:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
547 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
548 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
549 |
6277
f2c9c36979b3
plugins/muc: Fix use of incorrect event on occupant join
daurnimator <quae@daurnimator.com>
parents:
6275
diff
changeset
|
550 if orig_occupant == nil then |
f2c9c36979b3
plugins/muc: Fix use of incorrect event on occupant join
daurnimator <quae@daurnimator.com>
parents:
6275
diff
changeset
|
551 if is_first_dest_session then |
7346
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
552 module:fire_event("muc-occupant-joined", { |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
553 room = self; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
554 nick = dest_occupant.nick; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
555 occupant = dest_occupant; |
7347
795a95258292
MUC: Include originating session and stanza in events
Kim Alvefur <zash@zash.se>
parents:
7346
diff
changeset
|
556 stanza = stanza; |
795a95258292
MUC: Include originating session and stanza in events
Kim Alvefur <zash@zash.se>
parents:
7346
diff
changeset
|
557 origin = origin; |
7346
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
558 }); |
6277
f2c9c36979b3
plugins/muc: Fix use of incorrect event on occupant join
daurnimator <quae@daurnimator.com>
parents:
6275
diff
changeset
|
559 end |
7346
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
560 module:fire_event("muc-occupant-session-new", { |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
561 room = self; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
562 nick = dest_occupant.nick; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
563 occupant = dest_occupant; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
564 stanza = stanza; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
565 origin = origin; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
566 jid = real_jid; |
4ea5ce5efff8
MUC: Spread event tables over multiple lines
Kim Alvefur <zash@zash.se>
parents:
7270
diff
changeset
|
567 }); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
568 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
569 end |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
570 elseif type ~= 'result' then -- bad type |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
571 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
572 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
573 end |
3261
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
574 end |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
575 return true; |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
576 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
577 |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
578 function room_mt:handle_iq_to_occupant(origin, stanza) |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
579 local from, to = stanza.attr.from, stanza.attr.to; |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
580 local type = stanza.attr.type; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
581 local id = stanza.attr.id; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
582 local occupant = self:get_occupant_by_nick(to); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
583 if (type == "error" or type == "result") then |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
584 do -- deconstruct_stanza_id |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
585 if not occupant then return nil; end |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
586 local from_jid, orig_id, to_jid_hash = (base64.decode(id) or ""):match("^(%Z+)%z(%Z*)%z(.+)$"); |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
587 if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
588 local from_occupant_jid = self:get_occupant_jid(from_jid); |
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
589 if from_occupant_jid == nil then return nil; end |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
590 local session_jid |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
591 for to_jid in occupant:each_session() do |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
592 if md5(to_jid) == to_jid_hash then |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
593 session_jid = to_jid; |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
594 break; |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
595 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
596 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
597 if session_jid == nil then return nil; end |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
598 stanza.attr.from, stanza.attr.to, stanza.attr.id = from_occupant_jid, session_jid, orig_id; |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
599 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
600 log("debug", "%s sent private iq stanza to %s (%s)", from, to, stanza.attr.to); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
601 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
602 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
603 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
604 else -- Type is "get" or "set" |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
605 local current_nick = self:get_occupant_jid(from); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
606 if not current_nick then |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
607 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
608 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
609 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
610 if not occupant then -- recipient not in room |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
611 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
612 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
613 end |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
614 do -- construct_stanza_id |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
615 stanza.attr.id = base64.encode(occupant.jid.."\0"..stanza.attr.id.."\0"..md5(from)); |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
616 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
617 stanza.attr.from, stanza.attr.to = current_nick, occupant.jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
618 log("debug", "%s sent private iq stanza to %s (%s)", from, to, occupant.jid); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
619 if stanza.tags[1].attr.xmlns == 'vcard-temp' then |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
620 stanza.attr.to = jid_bare(stanza.attr.to); |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
621 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
622 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
623 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
624 return true; |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
625 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
626 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
627 |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
628 function room_mt:handle_message_to_occupant(origin, stanza) |
1734 | 629 local from, to = stanza.attr.from, stanza.attr.to; |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
630 local current_nick = self:get_occupant_jid(from); |
1734 | 631 local type = stanza.attr.type; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
632 if not current_nick then -- not in room |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
633 if type ~= "error" then |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
634 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
635 end |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
636 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
637 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
638 if type == "groupchat" then -- groupchat messages not allowed in PM |
1734 | 639 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
640 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
641 elseif type == "error" and is_kickable_error(stanza) then |
1996
3e6b36c6d7b7
MUC: Kick occupants on sending error messages to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1989
diff
changeset
|
642 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
643 return self:handle_kickable(origin, stanza); -- send unavailable |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
644 end |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
645 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
646 local o_data = self:get_occupant_by_nick(to); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
647 if not o_data then |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
648 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
649 return true; |
1734 | 650 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
651 log("debug", "%s sent private message stanza to %s (%s)", from, to, o_data.jid); |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
652 stanza:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }):up(); |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
653 stanza.attr.from = current_nick; |
6130
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
654 self:route_to_occupant(o_data, stanza) |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
655 -- TODO: Remove x tag? |
6130
c95d9132592a
plugins/muc/muc.lib: Add route_to_occupant function to send a stanza to all occupant sessions
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
656 stanza.attr.from = from; |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
657 return true; |
1734 | 658 end |
659 | |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
660 function room_mt:send_form(origin, stanza) |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
661 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") |
5601
f55ab5fa939f
mod_muc: Pass actor (requesting JID) when generating the config form, and to the muc-config-form event handler
Matthew Wild <mwild1@gmail.com>
parents:
5600
diff
changeset
|
662 :add_child(self:get_form_layout(stanza.attr.from):form()) |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
663 ); |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
664 end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
665 |
5601
f55ab5fa939f
mod_muc: Pass actor (requesting JID) when generating the config form, and to the muc-config-form event handler
Matthew Wild <mwild1@gmail.com>
parents:
5600
diff
changeset
|
666 function room_mt:get_form_layout(actor) |
5541
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
667 local form = dataform.new({ |
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
668 title = "Configuration for "..self.jid, |
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
669 instructions = "Complete and submit this form to configure the room.", |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
670 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
671 name = 'FORM_TYPE', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
672 type = 'hidden', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
673 value = 'http://jabber.org/protocol/muc#roomconfig' |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
674 } |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
675 }); |
5601
f55ab5fa939f
mod_muc: Pass actor (requesting JID) when generating the config form, and to the muc-config-form event handler
Matthew Wild <mwild1@gmail.com>
parents:
5600
diff
changeset
|
676 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
677 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
678 |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
679 function room_mt:process_form(origin, stanza) |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
680 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
681 if form.attr.type == "cancel" then |
7383
69827ee1f951
MUC: Accept missing form as "instant room" request (fixes #377)
Kim Alvefur <zash@zash.se>
parents:
7011
diff
changeset
|
682 origin.send(st.reply(stanza)); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
683 elseif form.attr.type == "submit" then |
6990
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
684 local fields, errors, present; |
6391
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
685 if form.tags[1] == nil then -- Instant room |
6990
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
686 fields, present = {}, {}; |
6391
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
687 else |
6990
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
688 fields, errors, present = self:get_form_layout(stanza.attr.from):data(form); |
6391
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
689 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then |
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
690 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); |
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
691 return true; |
4d334d00c635
plugins/muc/muc.lib: Add instant room support
daurnimator <quae@daurnimator.com>
parents:
6318
diff
changeset
|
692 end |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
693 end |
7383
69827ee1f951
MUC: Accept missing form as "instant room" request (fixes #377)
Kim Alvefur <zash@zash.se>
parents:
7011
diff
changeset
|
694 |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
695 local event = {room = self; origin = origin; stanza = stanza; fields = fields; status_codes = {};}; |
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
696 function event.update_option(name, field, allowed) |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
697 local new = fields[field]; |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
698 if new == nil then return; end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
699 if allowed and not allowed[new] then return; end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
700 if new == self["get_"..name](self) then return; end |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
701 event.status_codes["104"] = true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
702 self["set_"..name](self, new); |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
703 return true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
704 end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
705 module:fire_event("muc-config-submitted", event); |
6990
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
706 for submitted_field in pairs(present) do |
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
707 event.field, event.value = submitted_field, fields[submitted_field]; |
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
708 module:fire_event("muc-config-submitted/"..submitted_field, event); |
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
709 end |
f476e2497568
MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
Matthew Wild <mwild1@gmail.com>
parents:
6988
diff
changeset
|
710 event.field, event.value = nil, nil; |
3508
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
711 |
7402
ef7ea3bad7a1
MUC: Don't force-save rooms where not needed
Kim Alvefur <zash@zash.se>
parents:
7397
diff
changeset
|
712 self:save(); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
713 origin.send(st.reply(stanza)); |
3248
f8d14ea3ad0e
MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents:
3247
diff
changeset
|
714 |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
715 if next(event.status_codes) then |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
716 local msg = st.message({type='groupchat', from=self.jid}) |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
717 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
718 for code in pairs(event.status_codes) do |
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
719 msg:tag("status", {code = code;}):up(); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
720 end |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
721 msg:up(); |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
722 self:broadcast_message(msg); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
723 end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
724 else |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
725 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
5808
026367992a0f
mod_muc: Support for locking newly-created rooms until they are configured (enabled with muc_room_locking = true)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
726 end |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
727 return true; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
728 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
729 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
730 -- Removes everyone from the room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
731 function room_mt:clear(x) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
732 x = x or st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
733 local occupants_updated = {}; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
734 for nick, occupant in self:each_occupant() do -- luacheck: ignore 213 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
735 occupant.role = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
736 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
737 occupants_updated[occupant] = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
738 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
739 for occupant in pairs(occupants_updated) do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
740 self:publicise_occupant_status(occupant, x); |
6431
540f4e33394a
muc: Add 'occupant' to muc-occupant-{joined,left,session-new} events (thanks daurnimator/fippo)
Matthew Wild <mwild1@gmail.com>
parents:
6429
diff
changeset
|
741 module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;}); |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
742 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
743 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
744 |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
745 function room_mt:destroy(newjid, reason, password) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
746 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
747 :tag("item", { affiliation='none', role='none' }):up() |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
748 :tag("destroy", {jid=newjid}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
749 if reason then x:tag("reason"):text(reason):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
750 if password then x:tag("password"):text(password):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
751 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
752 self:clear(x); |
5577
8b09b0d068d4
mod_muc: Fire muc-room-created and muc-room-destroyed events (thanks nik)
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
753 module:fire_event("muc-room-destroyed", { room = self }); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
754 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
755 |
6101
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
756 function room_mt:handle_disco_info_get_query(origin, stanza) |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
757 origin.send(self:get_disco_info(stanza)); |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
758 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
759 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
760 |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
761 function room_mt:handle_disco_items_get_query(origin, stanza) |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
762 origin.send(self:get_disco_items(stanza)); |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
763 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
764 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
765 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
766 function room_mt:handle_admin_query_set_command(origin, stanza) |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
767 local item = stanza.tags[1].tags[1]; |
6909
494938dec5d8
MUC: Reject muc:admin query with missing <item> child
Kim Alvefur <zash@zash.se>
parents:
6835
diff
changeset
|
768 if not item then |
494938dec5d8
MUC: Reject muc:admin query with missing <item> child
Kim Alvefur <zash@zash.se>
parents:
6835
diff
changeset
|
769 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
494938dec5d8
MUC: Reject muc:admin query with missing <item> child
Kim Alvefur <zash@zash.se>
parents:
6835
diff
changeset
|
770 end |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
771 if item.attr.jid then -- Validate provided JID |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
772 item.attr.jid = jid_prep(item.attr.jid); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
773 if not item.attr.jid then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
774 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
775 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
776 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
777 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
778 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
779 local occupant = self:get_occupant_by_nick(self.jid.."/"..item.attr.nick); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
780 if occupant then item.attr.jid = occupant.jid; end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
781 elseif not item.attr.nick and item.attr.jid then |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
782 local nick = self:get_occupant_jid(item.attr.jid); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
783 if nick then item.attr.nick = select(3, jid_split(nick)); end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
784 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
785 local actor = stanza.attr.from; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
786 local reason = item:get_child_text("reason"); |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
787 local success, errtype, err |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
788 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
789 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
790 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
791 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
792 else |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
793 success, errtype, err = nil, "cancel", "bad-request"; |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
794 end |
7364
9ea3094b1fca
MUC: Save yourself! (fixes reference to current room)
Kim Alvefur <zash@zash.se>
parents:
7363
diff
changeset
|
795 self:save(); |
6828
9019bc4c9a5a
MUC: Prevent double replies when MUC affiliation/role change requests fail.
Lance Stout <lancestout@gmail.com>
parents:
6827
diff
changeset
|
796 if not success then |
9019bc4c9a5a
MUC: Prevent double replies when MUC affiliation/role change requests fail.
Lance Stout <lancestout@gmail.com>
parents:
6827
diff
changeset
|
797 origin.send(st.error_reply(stanza, errtype, err)); |
9019bc4c9a5a
MUC: Prevent double replies when MUC affiliation/role change requests fail.
Lance Stout <lancestout@gmail.com>
parents:
6827
diff
changeset
|
798 else |
9019bc4c9a5a
MUC: Prevent double replies when MUC affiliation/role change requests fail.
Lance Stout <lancestout@gmail.com>
parents:
6827
diff
changeset
|
799 origin.send(st.reply(stanza)); |
9019bc4c9a5a
MUC: Prevent double replies when MUC affiliation/role change requests fail.
Lance Stout <lancestout@gmail.com>
parents:
6827
diff
changeset
|
800 end |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
801 return true; |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
802 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
803 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
804 function room_mt:handle_admin_query_get_command(origin, stanza) |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
805 local actor = stanza.attr.from; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
806 local affiliation = self:get_affiliation(actor); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
807 local item = stanza.tags[1].tags[1]; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
808 local _aff = item.attr.affiliation; |
6453
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
809 local _aff_rank = valid_affiliations[_aff or "none"]; |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
810 local _rol = item.attr.role; |
6453
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
811 if _aff and _aff_rank and not _rol then |
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
812 -- You need to be at least an admin, and be requesting info about your affifiliation or lower |
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
813 -- e.g. an admin can't ask for a list of owners |
6827
19c4532946b3
MUC: Fix traceback in request for MUC affiliation lists by non-affiliated (thanks Lance)
Kim Alvefur <zash@zash.se>
parents:
6801
diff
changeset
|
814 local affiliation_rank = valid_affiliations[affiliation or "none"]; |
6453
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
815 if affiliation_rank >= valid_affiliations.admin and affiliation_rank >= _aff_rank then |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
816 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
6478
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
817 for jid in self:each_affiliation(_aff or "none") do |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
818 reply:tag("item", {affiliation = _aff, jid = jid}):up(); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
819 end |
6452
e692ea8c09a0
plugins/muc/muc.lib: Add missing :up()
daurnimator <quae@daurnimator.com>
parents:
6451
diff
changeset
|
820 origin.send(reply:up()); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
821 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
822 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
823 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
824 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
825 end |
6453
14b62ad88d8a
plugins/muc/muc.lib: Validate affiliations and roles to admin query get
daurnimator <quae@daurnimator.com>
parents:
6452
diff
changeset
|
826 elseif _rol and valid_roles[_rol or "none"] and not _aff then |
6126
122e0f26e8f6
plugins/muc/muc.lib: Use `get_role` in `handle_admin_item_get_command`. Removed a TODO that's already done
daurnimator <quae@daurnimator.com>
parents:
6125
diff
changeset
|
827 local role = self:get_role(self:get_occupant_jid(actor)) or self:get_default_role(affiliation); |
6219
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
828 if valid_roles[role or "none"] >= valid_roles.moderator then |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
829 if _rol == "none" then _rol = nil; end |
6219
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
830 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
831 -- TODO: whois check here? (though fully anonymous rooms are not supported) |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
832 for occupant_jid, occupant in self:each_occupant() do |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
833 if occupant.role == _rol then |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
834 local nick = select(3,jid_split(occupant_jid)); |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
835 self:build_item_list(occupant, reply, false, nick); |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
836 end |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
837 end |
6219
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
838 origin.send(reply:up()); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
839 return true; |
1734 | 840 else |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
841 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
842 return true; |
2005
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
843 end |
1734 | 844 else |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
845 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
846 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
847 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
848 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
849 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
850 function room_mt:handle_owner_query_get_to_room(origin, stanza) |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
851 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
852 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
853 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
854 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
855 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
856 self:send_form(origin, stanza); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
857 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
858 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
859 function room_mt:handle_owner_query_set_to_room(origin, stanza) |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
860 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
861 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
862 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
863 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
864 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
865 local child = stanza.tags[1].tags[1]; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
866 if not child then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
867 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
868 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
869 elseif child.name == "destroy" then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
870 local newjid = child.attr.jid; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
871 local reason = child:get_child_text("reason"); |
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
872 local password = child:get_child_text("password"); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
873 self:destroy(newjid, reason, password); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
874 origin.send(st.reply(stanza)); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
875 return true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
876 elseif child.name == "x" and child.attr.xmlns == "jabber:x:data" then |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
877 return self:process_form(origin, stanza); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
878 else |
1734 | 879 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
880 return true; |
1734 | 881 end |
882 end | |
883 | |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
884 function room_mt:handle_groupchat_to_room(origin, stanza) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
885 local from = stanza.attr.from; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
886 local occupant = self:get_occupant_by_real_jid(from); |
6429
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
887 if module:fire_event("muc-occupant-groupchat", { |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
888 room = self; origin = origin; stanza = stanza; from = from; occupant = occupant; |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
889 }) then return true; end |
6223
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
890 stanza.attr.from = occupant.nick; |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
891 self:broadcast_message(stanza); |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
892 stanza.attr.from = from; |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
893 return true; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
894 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
895 |
6429
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
896 -- Role check |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
897 module:hook("muc-occupant-groupchat", function(event) |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
898 local role_rank = valid_roles[event.occupant and event.occupant.role or "none"]; |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
899 if role_rank <= valid_roles.none then |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
900 event.origin.send(st.error_reply(event.stanza, "cancel", "not-acceptable")); |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
901 return true; |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
902 elseif role_rank <= valid_roles.visitor then |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
903 event.origin.send(st.error_reply(event.stanza, "auth", "forbidden")); |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
904 return true; |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
905 end |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
906 end, 50); |
675aea867574
plugins/muc: Add muc-occupant-groupchat event
daurnimator <quae@daurnimator.com>
parents:
6419
diff
changeset
|
907 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
908 -- hack - some buggy clients send presence updates to the room rather than their nick |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
909 function room_mt:handle_presence_to_room(origin, stanza) |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
910 local current_nick = self:get_occupant_jid(stanza.attr.from); |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
911 local handled |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
912 if current_nick then |
1734 | 913 local to = stanza.attr.to; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
914 stanza.attr.to = current_nick; |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
915 handled = self:handle_presence_to_occupant(origin, stanza); |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
916 stanza.attr.to = to; |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
917 end |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
918 return handled; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
919 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
920 |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
921 -- Need visitor role or higher to invite |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
922 module:hook("muc-pre-invite", function(event) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
923 local room, stanza = event.room, event.stanza; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
924 local _from = stanza.attr.from; |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
925 local inviter = room:get_occupant_by_real_jid(_from); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
926 local role = inviter and inviter.role or room:get_default_role(room:get_affiliation(_from)); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
927 if valid_roles[role or "none"] <= valid_roles.visitor then |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
928 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); |
6103
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
929 return true; |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
930 end |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
931 end); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
932 |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
933 function room_mt:handle_mediated_invite(origin, stanza) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
934 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
935 local invitee = jid_prep(payload.attr.to); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
936 if not invitee then |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
937 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
938 return true; |
6229
8aa59b73f801
plugins/muc/muc.lib: Remove reversed conditionals when firing pre- events
daurnimator <quae@daurnimator.com>
parents:
6227
diff
changeset
|
939 elseif module:fire_event("muc-pre-invite", {room = self, origin = origin, stanza = stanza}) then |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
940 return true; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
941 end |
6272
90054f21d1af
plugins/muc/muc: When forwarding mediated invites; use filtered version of original invite instead of new object
daurnimator <quae@daurnimator.com>
parents:
6269
diff
changeset
|
942 local invite = muc_util.filter_muc_x(st.clone(stanza)); |
90054f21d1af
plugins/muc/muc: When forwarding mediated invites; use filtered version of original invite instead of new object
daurnimator <quae@daurnimator.com>
parents:
6269
diff
changeset
|
943 invite.attr.from = self.jid; |
90054f21d1af
plugins/muc/muc: When forwarding mediated invites; use filtered version of original invite instead of new object
daurnimator <quae@daurnimator.com>
parents:
6269
diff
changeset
|
944 invite.attr.to = invitee; |
90054f21d1af
plugins/muc/muc: When forwarding mediated invites; use filtered version of original invite instead of new object
daurnimator <quae@daurnimator.com>
parents:
6269
diff
changeset
|
945 invite:tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
946 :tag('invite', {from = stanza.attr.from;}) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
947 :tag('reason'):text(payload:get_child_text("reason")):up() |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
948 :up() |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
949 :up(); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
950 if not module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}) then |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
951 self:route_stanza(invite); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
952 end |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
953 return true; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
954 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
955 |
6194
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
956 -- COMPAT: Some older clients expect this |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
957 module:hook("muc-invite", function(event) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
958 local room, stanza = event.room, event.stanza; |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
959 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
960 local reason = invite:get_child_text("reason"); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
961 stanza:tag('x', {xmlns = "jabber:x:conference"; jid = room.jid;}) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
962 :text(reason or "") |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
963 :up(); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
964 end); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
965 |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
966 -- Add a plain message for clients which don't support invites |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
967 module:hook("muc-invite", function(event) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
968 local room, stanza = event.room, event.stanza; |
6274
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
969 if not stanza:get_child("body") then |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
970 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
971 local reason = invite:get_child_text("reason") or ""; |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
972 stanza:tag("body") |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
973 :text(invite.attr.from.." invited you to the room "..room.jid..(reason == "" and (" ("..reason..")") or "")) |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
974 :up(); |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
975 end |
6194
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
976 end); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
977 |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
978 function room_mt:handle_mediated_decline(origin, stanza) |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
979 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline"); |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
980 local declinee = jid_prep(payload.attr.to); |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
981 if not declinee then |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
982 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
983 return true; |
6229
8aa59b73f801
plugins/muc/muc.lib: Remove reversed conditionals when firing pre- events
daurnimator <quae@daurnimator.com>
parents:
6227
diff
changeset
|
984 elseif module:fire_event("muc-pre-decline", {room = self, origin = origin, stanza = stanza}) then |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
985 return true; |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
986 end |
6273
7ef064101994
plugins/muc/muc.lib: Use original decline as template for medated decline
daurnimator <quae@daurnimator.com>
parents:
6272
diff
changeset
|
987 local decline = muc_util.filter_muc_x(st.clone(stanza)); |
7ef064101994
plugins/muc/muc.lib: Use original decline as template for medated decline
daurnimator <quae@daurnimator.com>
parents:
6272
diff
changeset
|
988 decline.attr.from = self.jid; |
7ef064101994
plugins/muc/muc.lib: Use original decline as template for medated decline
daurnimator <quae@daurnimator.com>
parents:
6272
diff
changeset
|
989 decline.attr.to = declinee; |
7ef064101994
plugins/muc/muc.lib: Use original decline as template for medated decline
daurnimator <quae@daurnimator.com>
parents:
6272
diff
changeset
|
990 decline:tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
991 :tag("decline", {from = stanza.attr.from}) |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
992 :tag("reason"):text(payload:get_child_text("reason")):up() |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
993 :up() |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
994 :up(); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
995 if not module:fire_event("muc-decline", {room = self, stanza = decline, origin = origin, incoming = stanza}) then |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
996 declinee = decline.attr.to; -- re-fetch, in case event modified it |
6275
d891fa02e5e5
plugins/muc/muc.lib: Deliver declines to in-room jids correctly
daurnimator <quae@daurnimator.com>
parents:
6274
diff
changeset
|
997 local occupant |
d891fa02e5e5
plugins/muc/muc.lib: Deliver declines to in-room jids correctly
daurnimator <quae@daurnimator.com>
parents:
6274
diff
changeset
|
998 if jid_bare(declinee) == self.jid then -- declinee jid is already an in-room jid |
d891fa02e5e5
plugins/muc/muc.lib: Deliver declines to in-room jids correctly
daurnimator <quae@daurnimator.com>
parents:
6274
diff
changeset
|
999 occupant = self:get_occupant_by_nick(declinee); |
d891fa02e5e5
plugins/muc/muc.lib: Deliver declines to in-room jids correctly
daurnimator <quae@daurnimator.com>
parents:
6274
diff
changeset
|
1000 end |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1001 if occupant then |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1002 self:route_to_occupant(occupant, decline); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1003 else |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1004 self:route_stanza(decline); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1005 end |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1006 end |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1007 return true; |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1008 end |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1009 |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1010 -- Add a plain message for clients which don't support declines |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1011 module:hook("muc-decline", function(event) |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1012 local room, stanza = event.room, event.stanza; |
6274
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1013 if not stanza:get_child("body") then |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1014 local decline = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline"); |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1015 local reason = decline:get_child_text("reason") or ""; |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1016 stanza:tag("body") |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1017 :text(decline.attr.from.." declined your invite to the room "..room.jid..(reason == "" and (" ("..reason..")") or "")) |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1018 :up(); |
77bdbaec3b7f
plugins/muc/muc.lib: Don't add invite/decline bodies if they already have one
daurnimator <quae@daurnimator.com>
parents:
6273
diff
changeset
|
1019 end |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
1020 end); |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1021 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1022 function room_mt:handle_message_to_room(origin, stanza) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1023 local type = stanza.attr.type; |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1024 if type == "groupchat" then |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1025 return self:handle_groupchat_to_room(origin, stanza) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1026 elseif type == "error" and is_kickable_error(stanza) then |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
1027 return self:handle_kickable(origin, stanza) |
6103
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1028 elseif type == nil then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1029 local x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1030 if x then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1031 local payload = x.tags[1]; |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
1032 if payload == nil then --luacheck: ignore 542 |
6104
260a18062cb2
plugins/muc/muc: Rename `handle_invite_to_room` to `handle_mediated_invite`; clean up logic
daurnimator <quae@daurnimator.com>
parents:
6103
diff
changeset
|
1033 -- fallthrough |
260a18062cb2
plugins/muc/muc: Rename `handle_invite_to_room` to `handle_mediated_invite`; clean up logic
daurnimator <quae@daurnimator.com>
parents:
6103
diff
changeset
|
1034 elseif payload.name == "invite" and payload.attr.to then |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1035 return self:handle_mediated_invite(origin, stanza) |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1036 elseif payload.name == "decline" and payload.attr.to then |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1037 return self:handle_mediated_decline(origin, stanza) |
6103
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1038 end |
2005
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
1039 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
1040 return true; |
2005
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
1041 end |
1734 | 1042 end |
1043 end | |
1044 | |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
1045 function room_mt:route_stanza(stanza) -- luacheck: ignore 212 |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1046 module:send(stanza); |
6111
f8b94903be52
plugins/muc: Provide a reasonable default `route_stanza`
daurnimator <quae@daurnimator.com>
parents:
6108
diff
changeset
|
1047 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1048 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1049 function room_mt:get_affiliation(jid) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1050 local node, host, resource = jid_split(jid); |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1051 local bare = node and node.."@"..host or host; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1052 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1053 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1054 return result; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1055 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1056 |
6478
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1057 -- Iterates over jid, affiliation pairs |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1058 function room_mt:each_affiliation(with_affiliation) |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1059 if not with_affiliation then |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1060 return pairs(self._affiliations); |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1061 else |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1062 return function(_affiliations, jid) |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1063 local affiliation; |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1064 repeat -- Iterate until we get a match |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1065 jid, affiliation = next(_affiliations, jid); |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1066 until jid == nil or affiliation == with_affiliation |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1067 return jid, affiliation; |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1068 end, self._affiliations, nil |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1069 end |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1070 end |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1071 |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1072 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1073 if not actor then return nil, "modify", "not-acceptable"; end; |
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1074 |
6476
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1075 local node, host, resource = jid_split(jid); |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1076 if not host then return nil, "modify", "not-acceptable"; end |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1077 jid = jid_join(node, host); -- Bare |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1078 local is_host_only = node == nil; |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1079 |
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1080 if valid_affiliations[affiliation or "none"] == nil then |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1081 return nil, "modify", "not-acceptable"; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1082 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1083 affiliation = affiliation ~= "none" and affiliation or nil; -- coerces `affiliation == false` to `nil` |
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1084 |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1085 local target_affiliation = self._affiliations[jid]; -- Raw; don't want to check against host |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1086 local is_downgrade = valid_affiliations[target_affiliation or "none"] > valid_affiliations[affiliation or "none"]; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1087 |
6475
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1088 if actor == true then |
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1089 actor = nil -- So we can pass it safely to 'publicise_occupant_status' below |
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1090 else |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
1091 local actor_affiliation = self:get_affiliation(actor); |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1092 if actor_affiliation == "owner" then |
6392
8528d1da461f
plugins/muc/muc.lib: Use get_affilation() inside of set_affiliation(), so that the override in mod_muc works
daurnimator <quae@daurnimator.com>
parents:
6391
diff
changeset
|
1093 if jid_bare(actor) == jid then -- self change |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1094 -- need at least one owner |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1095 local is_last = true; |
6478
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1096 for j in self:each_affiliation("owner") do |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1097 if j ~= jid then is_last = false; break; end |
413923bbd1a0
plugins/muc/muc.lib: Add :each_affiliation() iterator
daurnimator <quae@daurnimator.com>
parents:
6476
diff
changeset
|
1098 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1099 if is_last then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1100 return nil, "cancel", "conflict"; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1101 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1102 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1103 -- owners can do anything else |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1104 elseif affiliation == "owner" or affiliation == "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1105 or actor_affiliation ~= "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1106 or target_affiliation == "owner" or target_affiliation == "admin" then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1107 -- Can't demote owners or other admins |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1108 return nil, "cancel", "not-allowed"; |
4202
dff7df4a191b
MUC: Don't limit affiliation changes to owners, and allow owners to remove themselves if they are not the last owner.
Waqas Hussain <waqas20@gmail.com>
parents:
4201
diff
changeset
|
1109 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1110 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1111 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1112 -- Set in 'database' |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1113 self._affiliations[jid] = affiliation; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1114 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1115 -- Update roles |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1116 local role = self:get_default_role(affiliation); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1117 local role_rank = valid_roles[role or "none"]; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1118 local occupants_updated = {}; -- Filled with old roles |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
1119 for nick, occupant in self:each_occupant() do -- luacheck: ignore 213 |
6476
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1120 if occupant.bare_jid == jid or ( |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1121 -- Outcast can be by host. |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1122 is_host_only and affiliation == "outcast" and select(2, jid_split(occupant.bare_jid)) == host |
fb8a9873728b
plugins/muc/muc.lib: Kick users from outcast hosts
daurnimator <quae@daurnimator.com>
parents:
6475
diff
changeset
|
1123 ) then |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1124 -- need to publcize in all cases; as affiliation in <item/> has changed. |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1125 occupants_updated[occupant] = occupant.role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1126 if occupant.role ~= role and ( |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1127 is_downgrade or |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1128 valid_roles[occupant.role or "none"] < role_rank -- upgrade |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1129 ) then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1130 occupant.role = role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1131 self:save_occupant(occupant); |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
1132 end |
4202
dff7df4a191b
MUC: Don't limit affiliation changes to owners, and allow owners to remove themselves if they are not the last owner.
Waqas Hussain <waqas20@gmail.com>
parents:
4201
diff
changeset
|
1133 end |
dff7df4a191b
MUC: Don't limit affiliation changes to owners, and allow owners to remove themselves if they are not the last owner.
Waqas Hussain <waqas20@gmail.com>
parents:
4201
diff
changeset
|
1134 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1135 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1136 -- Tell the room of the new occupant affiliations+roles |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1137 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1138 if not role then -- getting kicked |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1139 if affiliation == "outcast" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1140 x:tag("status", {code="301"}):up(); -- banned |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1141 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1142 x:tag("status", {code="321"}):up(); -- affiliation change |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1143 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1144 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1145 local is_semi_anonymous = self:get_whois() == "moderators"; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1146 for occupant, old_role in pairs(occupants_updated) do |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
1147 self:publicise_occupant_status(occupant, x, nil, actor, reason); |
6454
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
1148 if occupant.role == nil then |
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
1149 module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); |
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
1150 elseif is_semi_anonymous and |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1151 (old_role == "moderator" and occupant.role ~= "moderator") or |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1152 (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1153 -- Send everyone else's presences (as jid visibility has changed) |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1154 for real_jid in occupant:each_session() do |
7089
890f4b2cc444
MUC: Add luacheck annotations, remove unused vars, rename conflicting vars etc
Kim Alvefur <zash@zash.se>
parents:
7013
diff
changeset
|
1155 self:send_occupant_list(real_jid, function(occupant_jid, occupant) --luacheck: ignore 212 433 |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1156 return occupant.bare_jid ~= jid; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1157 end); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1158 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1159 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1160 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1161 |
7402
ef7ea3bad7a1
MUC: Don't force-save rooms where not needed
Kim Alvefur <zash@zash.se>
parents:
7397
diff
changeset
|
1162 self:save(); |
6393
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1163 |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1164 module:fire_event("muc-set-affiliation", { |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1165 room = self; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1166 actor = actor; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1167 jid = jid; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1168 affiliation = affiliation or "none"; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1169 reason = reason; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1170 previous_affiliation = target_affiliation; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1171 in_room = next(occupants_updated) ~= nil; |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1172 }); |
fff6ca13cb0f
plugins/muc/muc.lib: Add muc-set-affiliation event
daurnimator <quae@daurnimator.com>
parents:
6392
diff
changeset
|
1173 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1174 return true; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1175 end |
1734 | 1176 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1177 function room_mt:get_role(nick) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1178 local occupant = self:get_occupant_by_nick(nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1179 return occupant and occupant.role or nil; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1180 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1181 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1182 function room_mt:set_role(actor, occupant_jid, role, reason) |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1183 if not actor then return nil, "modify", "not-acceptable"; end |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1184 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1185 local occupant = self:get_occupant_by_nick(occupant_jid); |
7396
71a7140200fc
MUC: Return item-not-found as error when attempting to change role of non-existant occupant
Kim Alvefur <zash@zash.se>
parents:
7386
diff
changeset
|
1186 if not occupant then return nil, "modify", "item-not-found"; end |
5542
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1187 |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1188 if valid_roles[role or "none"] == nil then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1189 return nil, "modify", "not-acceptable"; |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1190 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1191 role = role ~= "none" and role or nil; -- coerces `role == false` to `nil` |
5542
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1192 |
6475
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1193 if actor == true then |
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1194 actor = nil -- So we can pass it safely to 'publicise_occupant_status' below |
3c815a64042b
plugins/muc/muc.lib: Fix passing actor along as a boolean (thanks fippo)
daurnimator <quae@daurnimator.com>
parents:
6454
diff
changeset
|
1195 else |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1196 -- Can't do anything to other owners or admins |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1197 local occupant_affiliation = self:get_affiliation(occupant.bare_jid); |
6776 | 1198 if occupant_affiliation == "owner" or occupant_affiliation == "admin" then |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1199 return nil, "cancel", "not-allowed"; |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1200 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1201 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1202 -- If you are trying to give or take moderator role you need to be an owner or admin |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1203 if occupant.role == "moderator" or role == "moderator" then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1204 local actor_affiliation = self:get_affiliation(actor); |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1205 if actor_affiliation ~= "owner" and actor_affiliation ~= "admin" then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1206 return nil, "cancel", "not-allowed"; |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1207 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1208 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1209 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1210 -- Need to be in the room and a moderator |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1211 local actor_occupant = self:get_occupant_by_real_jid(actor); |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1212 if not actor_occupant or actor_occupant.role ~= "moderator" then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1213 return nil, "cancel", "not-allowed"; |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1214 end |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1215 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1216 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1217 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1218 if not role then |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1219 x:tag("status", {code = "307"}):up(); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1220 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1221 occupant.role = role; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1222 self:save_occupant(occupant); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
1223 self:publicise_occupant_status(occupant, x, nil, actor, reason); |
6454
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
1224 if role == nil then |
6842b07fc7bc
plugins/muc/muc.lib: Fire muc-occupant-left from other places an occupant may leave the room
daurnimator <quae@daurnimator.com>
parents:
6453
diff
changeset
|
1225 module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1226 end |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1227 return true; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1228 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1229 |
6214
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1230 local whois = module:require "muc/whois"; |
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1231 room_mt.get_whois = whois.get; |
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1232 room_mt.set_whois = whois.set; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1233 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1234 local _M = {}; -- module "muc" |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1235 |
3330
bdc325ce9fbc
MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents:
3281
diff
changeset
|
1236 function _M.new_room(jid, config) |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1237 return setmetatable({ |
1734 | 1238 jid = jid; |
1239 _jid_nick = {}; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
1240 _occupants = {}; |
7362
032fcb7b80a1
MUC: Use config passed to rew_roow()
Kim Alvefur <zash@zash.se>
parents:
7360
diff
changeset
|
1241 _data = config or {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1242 _affiliations = {}; |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1243 }, room_mt); |
1734 | 1244 end |
1245 | |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1246 function room_mt:freeze(live) |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1247 local frozen = { |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1248 _jid = self.jid; |
7360
7a37fade5380
MUC: Move 'preserialization' step to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7353
diff
changeset
|
1249 _data = self._data; |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1250 }; |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1251 for user, affiliation in pairs(self._affiliations) do |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1252 frozen[user] = affiliation; |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1253 end |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1254 if live then |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1255 for nick, occupant in self:each_occupant() do |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1256 frozen[nick] = { |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1257 bare_jid = occupant.bare_jid; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1258 role = occupant.role; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1259 jid = occupant.jid; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1260 } |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1261 for jid, presence in occupant:each_session() do |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1262 frozen[jid] = st.preserialize(presence); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1263 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1264 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1265 end |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1266 return frozen; |
7360
7a37fade5380
MUC: Move 'preserialization' step to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7353
diff
changeset
|
1267 end |
7a37fade5380
MUC: Move 'preserialization' step to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7353
diff
changeset
|
1268 |
7367
2aef5e8b69e9
MUC: Move room deserialization to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7366
diff
changeset
|
1269 function _M.restore_room(frozen) |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1270 -- COMPAT |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1271 if frozen.jid and frozen._affiliations then |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1272 local room = _M.new_room(frozen.jid, frozen._data); |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1273 room._affiliations = frozen._affiliations; |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1274 return room; |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1275 end |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1276 |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1277 local room_jid = frozen._jid; |
7367
2aef5e8b69e9
MUC: Move room deserialization to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7366
diff
changeset
|
1278 local room = _M.new_room(room_jid, frozen._data); |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1279 |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1280 local occupants = {}; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1281 local occupant_sessions = {}; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1282 local room_name, room_host = jid_split(room_jid); |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1283 for jid, data in pairs(frozen) do |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1284 local node, host, resource = jid_split(jid); |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1285 if node or host:sub(1,1) ~= "_" then |
7405
5a65750d959a
MUC: Be more careful with deserialization of rooms, fix case where a bare jid has joined as multiple participants
Kim Alvefur <zash@zash.se>
parents:
7402
diff
changeset
|
1286 if not resource and type(data) == "string" then |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1287 -- bare jid: affiliation |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1288 room._affiliations[jid] = data; |
7405
5a65750d959a
MUC: Be more careful with deserialization of rooms, fix case where a bare jid has joined as multiple participants
Kim Alvefur <zash@zash.se>
parents:
7402
diff
changeset
|
1289 elseif host == room_host and node == room_name and resource then |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1290 -- full room jid: bare real jid and role |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1291 local bare_jid = data.bare_jid; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1292 local occupant = occupant_lib.new(bare_jid, jid); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1293 occupant.jid = data.jid; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1294 occupant.role = data.role; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1295 occupants[bare_jid] = occupant; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1296 local sessions = occupant_sessions[bare_jid]; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1297 if sessions then |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1298 for full_jid, presence in pairs(sessions) do |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1299 occupant:set_session(full_jid, presence); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1300 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1301 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1302 occupant_sessions[bare_jid] = nil; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1303 else |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1304 -- full user jid: presence |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1305 local presence = st.deserialize(data); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1306 local bare_jid = jid_bare(jid); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1307 local occupant = occupants[bare_jid]; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1308 local sessions = occupant_sessions[bare_jid]; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1309 if occupant then |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1310 occupant:set_session(jid, presence); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1311 elseif sessions then |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1312 sessions[jid] = presence; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1313 else |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1314 occupant_sessions[bare_jid] = { |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1315 [jid] = presence; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1316 }; |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1317 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1318 end |
7368
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1319 end |
4e24aff1e4df
MUC: Flatten format of serialized rooms
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
1320 end |
7369
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1321 |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1322 for _, occupant in pairs(occupants) do |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1323 room:save_occupant(occupant); |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1324 end |
c5cae59831d7
MUC: Add support for serializing live rooms, including occupants and their presence
Kim Alvefur <zash@zash.se>
parents:
7368
diff
changeset
|
1325 |
7367
2aef5e8b69e9
MUC: Move room deserialization to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7366
diff
changeset
|
1326 return room; |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1327 end |
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1328 |
5063
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1329 _M.room_mt = room_mt; |
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1330 |
1734 | 1331 return _M; |