Software /
code /
prosody
Annotate
plugins/muc/muc.lib.lua @ 6188:f47268c8a8d0
plugins/muc/muc.lib: Status codes should be inside of x element
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Fri, 28 Mar 2014 18:33:38 -0400 |
parent | 6187:c0b4b5d41e55 |
child | 6189:c54ef63f6e20 |
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; |
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
11 local pairs, ipairs = pairs, ipairs; |
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; |
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
14 local t_insert, t_remove = table.insert, table.remove; |
3281
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
15 |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
16 local gettime = os.time; |
1734 | 17 local datetime = require "util.datetime"; |
18 | |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
19 local dataform = require "util.dataforms"; |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
20 |
1734 | 21 local jid_split = require "util.jid".split; |
22 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
|
23 local jid_prep = require "util.jid".prep; |
1734 | 24 local st = require "util.stanza"; |
25 local log = require "util.logger".init("mod_muc"); | |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
26 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
|
27 local md5 = require "util.hashes".md5; |
1734 | 28 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
29 local occupant_lib = module:require "muc/occupant" |
1734 | 30 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
31 local default_history_length, max_history_length = 20, math.huge; |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
32 |
6115
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
33 local is_kickable_error do |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
34 local kickable_error_conditions = { |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
35 ["gone"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
36 ["internal-server-error"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
37 ["item-not-found"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
38 ["jid-malformed"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
39 ["recipient-unavailable"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
40 ["redirect"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
41 ["remote-server-not-found"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
42 ["remote-server-timeout"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
43 ["service-unavailable"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
44 ["malformed error"] = true; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
45 }; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
46 function is_kickable_error(stanza) |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
47 local cond = select(2, stanza:get_error()) or "malformed error"; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
48 return kickable_error_conditions[cond]; |
b8b68d09c9d8
plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition.
daurnimator <quae@daurnimator.com>
parents:
6114
diff
changeset
|
49 end |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
50 end |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
51 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
52 local room_mt = {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
53 room_mt.__index = room_mt; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
54 |
5519
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
55 function room_mt:__tostring() |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
56 return "MUC room ("..self.jid..")"; |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
57 end |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
58 |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
59 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
|
60 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
|
61 end |
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
62 |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
63 local valid_affiliations = { |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
64 outcast = 0; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
65 none = 1; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
66 member = 2; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
67 admin = 3; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
68 owner = 4; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
69 }; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
70 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
71 local valid_roles = { |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
72 none = 0; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
73 visitor = 1; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
74 participant = 2; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
75 moderator = 3; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
76 }; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
77 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
78 function room_mt:get_default_role(affiliation) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
79 if affiliation == "owner" or affiliation == "admin" then |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
80 return "moderator"; |
3251
f2f9fe088f6e
MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3250
diff
changeset
|
81 elseif affiliation == "member" then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
82 return "participant"; |
3251
f2f9fe088f6e
MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3250
diff
changeset
|
83 elseif not affiliation then |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
84 if not self:get_members_only() then |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
85 return self:get_moderated() and "visitor" or "participant"; |
3255
6bffb5c63131
MUC: Updated room:get_default_role() to not assign unaffiliated occupants a role in members-only rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3254
diff
changeset
|
86 end |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
87 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
88 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
89 |
6129
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
90 function room_mt:lock() |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
91 self.locked = true |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
92 end |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
93 function room_mt:unlock() |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
94 module:fire_event("muc-room-unlocked", { room = self }); |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
95 self.locked = nil |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
96 end |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
97 function room_mt:is_locked() |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
98 return not not self.locked |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
99 end |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
100 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
101 --- Occupant functions |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
102 function room_mt:new_occupant(bare_real_jid, nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
103 local occupant = occupant_lib.new(bare_real_jid, nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
104 local affiliation = self:get_affiliation(bare_real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
105 occupant.role = self:get_default_role(affiliation); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
106 return occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
107 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
108 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
109 function room_mt:get_occupant_by_nick(nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
110 local occupant = self._occupants[nick]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
111 if occupant == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
112 return occupant_lib.copy(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
113 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
114 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
115 do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
116 local function next_copied_occupant(occupants, occupant_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
117 local next_occupant_jid, raw_occupant = next(occupants, occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
118 if next_occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
119 return next_occupant_jid, occupant_lib.copy(raw_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
120 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
121 function room_mt:each_occupant(read_only) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
122 return next_copied_occupant, self._occupants, nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
123 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
124 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
125 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
126 function room_mt:get_occupant_by_real_jid(real_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
127 local occupant_jid = self:get_occupant_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
128 if occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
129 return self:get_occupant_by_nick(occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
130 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
131 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
132 function room_mt:save_occupant(occupant) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
133 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
|
134 local id = occupant.nick |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
135 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
136 -- Need to maintain _jid_nick secondary index |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
137 local old_occupant = self._occupants[id]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
138 if old_occupant then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
139 for real_jid in pairs(old_occupant.sessions) do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
140 self._jid_nick[real_jid] = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
141 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
142 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
143 if occupant.role ~= nil and next(occupant.sessions) then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
144 for real_jid, presence in occupant:each_session() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
145 self._jid_nick[real_jid] = occupant.nick; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
146 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
147 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
148 occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
149 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
150 self._occupants[id] = occupant |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
151 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
152 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
153 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
|
154 local to = stanza.attr.to; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
155 for jid, pr in occupant:each_session() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
156 if pr.attr.type ~= "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
157 stanza.attr.to = jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
158 self:route_stanza(stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
159 end |
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
|
160 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
|
161 stanza.attr.to = to; |
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
|
162 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
|
163 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
164 -- Adds an item to an "x" element. |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
165 -- actor is the attribute table |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
166 local function add_item(x, affiliation, role, jid, nick, actor, reason) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
167 x:tag("item", {affiliation = affiliation; role = role; jid = jid; nick = nick;}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
168 if actor then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
169 x:tag("actor", actor):up() |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
170 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
171 if reason then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
172 x:tag("reason"):text(reason):up() |
1734 | 173 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
174 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
175 return x |
1734 | 176 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
177 -- actor is (real) jid |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
178 function room_mt:build_item_list(occupant, x, is_anonymous, nick, actor, reason) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
179 local affiliation = self:get_affiliation(occupant.bare_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
180 local role = occupant.role; |
6183
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
181 local actor_attr; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
182 if actor then |
6183
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
183 actor_attr = {nick = select(3,jid_split(self:get_occupant_jid(actor)))}; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
184 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
185 if is_anonymous then |
6183
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
186 add_item(x, affiliation, role, nil, nick, actor_attr, reason); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
187 else |
6183
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
188 if actor_attr then |
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
189 actor_attr.jid = actor; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
190 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
191 for real_jid, session in occupant:each_session() do |
6183
a8e777a19816
plugins/muc/muc.lib: Fix sending occupant jid instead of real jid in <item/> actor
daurnimator <quae@daurnimator.com>
parents:
6182
diff
changeset
|
192 add_item(x, affiliation, role, real_jid, nick, actor_attr, reason); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
193 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
194 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
195 return x |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
196 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
197 |
1736
98f833669d7f
MUC: Fixed function declarations.
Waqas Hussain <waqas20@gmail.com>
parents:
1735
diff
changeset
|
198 function room_mt:broadcast_message(stanza, historic) |
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
|
199 module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic}); |
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
|
200 self:broadcast(stanza); |
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
|
201 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
|
202 |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
203 -- add to history |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
204 module:hook("muc-broadcast-message", function(event) |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
205 if event.historic then |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
206 local room = event.room |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
207 local history = room._data['history']; |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
208 if not history then history = {}; room._data['history'] = history; 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
|
209 local stanza = st.clone(event.stanza); |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
210 stanza.attr.to = ""; |
6142
a6e526c00e6e
plugins/muc/muc.lib: Have timestamp as seconds since epoch inside of history
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
211 local ts = gettime(); |
a6e526c00e6e
plugins/muc/muc.lib: Have timestamp as seconds since epoch inside of history
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
212 local stamp = datetime.datetime(ts); |
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
|
213 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
214 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
6142
a6e526c00e6e
plugins/muc/muc.lib: Have timestamp as seconds since epoch inside of history
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
215 local entry = { stanza = stanza, timestamp = ts }; |
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
|
216 t_insert(history, entry); |
7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
daurnimator <quae@daurnimator.com>
parents:
6136
diff
changeset
|
217 while #history > room:get_historylength() do t_remove(history, 1) end |
1734 | 218 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
219 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
|
220 |
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
|
221 -- Broadcast a stanza to all occupants in the room. |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
222 -- 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
|
223 function room_mt:broadcast(stanza, cond_func) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
228 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
229 end |
1734 | 230 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
231 -- Broadcasts an occupant's presence to the whole room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
232 -- Takes (and modifies) the x element that goes into the stanzas |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
233 function room_mt:publicise_occupant_status(occupant, full_x, actor, reason) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
234 local anon_x; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
235 local has_anonymous = self:get_whois() ~= "anyone"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
236 if has_anonymous then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
237 anon_x = st.clone(full_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
238 self:build_item_list(occupant, anon_x, true, nil, actor, reason); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
239 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
240 self:build_item_list(occupant,full_x, false, nil, actor, reason); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
241 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
242 -- General populance |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
243 local full_p |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
244 if occupant.role ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
245 -- Try to use main jid's presence |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
246 local pr = occupant:get_presence(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
247 if pr ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
248 full_p = st.clone(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
249 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
250 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
251 if full_p == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
252 full_p = st.presence{from=occupant.nick; type="unavailable"}; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
253 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
254 local anon_p; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
255 if has_anonymous then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
256 anon_p = st.clone(full_p); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
257 anon_p:add_child(anon_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
258 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
259 full_p:add_child(full_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
260 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
261 for nick, n_occupant in self:each_occupant() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
262 if nick ~= occupant.nick or n_occupant.role == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
263 local pr = full_p; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
264 if has_anonymous and n_occupant.role ~= "moderators" and occupant.bare_jid ~= n_occupant.bare_jid then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
265 pr = anon_p; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
266 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
267 self:route_to_occupant(n_occupant, pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
268 end |
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 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
271 -- Presences for occupant itself |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
272 full_x:tag("status", {code = "110";}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
273 if occupant.role == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
274 -- They get an unavailable |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
275 self:route_to_occupant(occupant, full_p); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
276 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
277 -- use their own presences as templates |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
278 for full_jid, pr in occupant:each_session() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
279 if pr.attr.type ~= "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
280 pr = st.clone(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
281 pr.attr.to = full_jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
282 -- You can always see your own full jids |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
283 pr:add_child(full_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
284 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
285 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
286 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
287 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
288 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
289 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
290 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
|
291 local to_bare = jid_bare(to); |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
292 local is_anonymous = true; |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
293 if self:get_whois() ~= "anyone" then |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
294 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
|
295 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
|
296 local occupant = self:get_occupant_by_real_jid(to); |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
297 if not occupant or occupant.role ~= "moderator" then |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
298 is_anonymous = false; |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
299 end |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
300 end |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
301 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
302 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
|
303 if filter == nil or filter(occupant_jid, occupant) then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
304 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
|
305 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
|
306 local pres = st.clone(occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
307 pres.attr.to = to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
308 pres:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
309 self:route_stanza(pres); |
1734 | 310 end |
311 end | |
312 end | |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
313 |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
314 local function parse_history(stanza) |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
315 local x_tag = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
316 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc"); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
317 if not history_tag then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
318 return nil, 20, nil |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
319 end |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
320 |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
321 local maxchars = tonumber(history_tag.attr.maxchars); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
322 |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
323 local maxstanzas = tonumber(history_tag.attr.maxstanzas); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
324 |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
325 -- messages received since the UTC datetime specified |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
326 local since = history_tag.attr.since; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
327 if since then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
328 since = datetime.parse(since); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
329 end |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
330 |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
331 -- messages received in the last "X" seconds. |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
332 local seconds = tonumber(history_tag.attr.seconds); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
333 if seconds then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
334 seconds = gettime() - seconds |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
335 if since then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
336 since = math.max(since, seconds); |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
337 else |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
338 since = seconds; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
339 end |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
340 end |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
341 |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
342 return maxchars, maxstanzas, since |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
343 end |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
344 |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
345 module:hook("muc-get-history", function(event) |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
346 local room = event.room |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
347 local history = room._data['history']; -- send discussion history |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
348 if not history then return nil end |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
349 local history_len = #history |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
350 |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
351 local to = event.to |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
352 local maxchars = event.maxchars |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
353 local maxstanzas = event.maxstanzas or history_len |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
354 local since = event.since |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
355 local n = 0; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
356 local charcount = 0; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
357 for i=history_len,1,-1 do |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
358 local entry = history[i]; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
359 if maxchars then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
360 if not entry.chars then |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
361 entry.stanza.attr.to = ""; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
362 entry.chars = #tostring(entry.stanza); |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
363 end |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
364 charcount = charcount + entry.chars + #to; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
365 if charcount > maxchars then break; end |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
366 end |
6142
a6e526c00e6e
plugins/muc/muc.lib: Have timestamp as seconds since epoch inside of history
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
367 if since and since > entry.timestamp then break; end |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
368 if n + 1 > maxstanzas then break; end |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
369 n = n + 1; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
370 end |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
371 |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
372 local i = history_len-n+1 |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
373 function event:next_stanza() |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
374 if i > history_len then return nil end |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
375 local entry = history[i] |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
376 local msg = entry.stanza |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
377 msg.attr.to = to; |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
378 i = i + 1 |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
379 return msg |
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
380 end |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
381 return true; |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
382 end); |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
383 |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
384 function room_mt:send_history(stanza) |
6092
16d5049fe842
plugins/muc/muc.lib: Split out `send_history` into `parse_history` and `get_history`
daurnimator <quae@daurnimator.com>
parents:
6004
diff
changeset
|
385 local maxchars, maxstanzas, since = parse_history(stanza) |
6138
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
386 local event = { |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
387 room = self; |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
388 to = stanza.attr.from; -- `to` is required to calculate the character count for `maxchars` |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
389 maxchars = maxchars, maxstanzas = maxstanzas, since = since; |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
390 next_stanza = function() end; -- events should define this iterator |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
391 } |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
392 module:fire_event("muc-get-history", event) |
fa746d834424
plugins/muc/muc.lib: Add muc-get-history event; it uses an iterator in the event object so that messages don't need to be all in memory at once
daurnimator <quae@daurnimator.com>
parents:
6137
diff
changeset
|
393 for msg in event.next_stanza , event do |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
394 self:route_stanza(msg); |
1734 | 395 end |
5983
930109558aa2
MUC: Split out sending of the topic into method separate from sending history
Kim Alvefur <zash@zash.se>
parents:
5982
diff
changeset
|
396 end |
1734 | 397 |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
398 function room_mt:get_disco_info(stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
399 local count = 0; for _ in self:each_occupant() do count = count + 1; end |
1808
e164fdb2d18f
MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1778
diff
changeset
|
400 return st.reply(stanza):query("http://jabber.org/protocol/disco#info") |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
401 :tag("identity", {category="conference", type="text", name=self:get_name()}):up() |
3246
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
402 :tag("feature", {var="http://jabber.org/protocol/muc"}):up() |
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
403 :tag("feature", {var=self:get_password() and "muc_passwordprotected" or "muc_unsecured"}):up() |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
404 :tag("feature", {var=self:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
405 :tag("feature", {var=self:get_members_only() and "muc_membersonly" or "muc_open"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
406 :tag("feature", {var=self:get_persistent() and "muc_persistent" or "muc_temporary"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
407 :tag("feature", {var=self:get_hidden() and "muc_hidden" or "muc_public"}):up() |
6118
aae3d6daa50d
plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
daurnimator <quae@daurnimator.com>
parents:
6117
diff
changeset
|
408 :tag("feature", {var=self:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
409 :add_child(dataform.new({ |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
410 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" }, |
5853
3ee3d79db18c
muc.lib.lua: Fix Spark jabber client not displaying conference room lists, seemingly due to a missing value tag for the room description if the description has not been set
Paul <paul@quakenet.org>
parents:
5680
diff
changeset
|
411 { name = "muc#roominfo_description", label = "Description", value = "" }, |
4266
513485a11b85
MUC: Include occupant count in room disco#info response.
Waqas Hussain <waqas20@gmail.com>
parents:
4202
diff
changeset
|
412 { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) } |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
413 }):form({["muc#roominfo_description"] = self:get_description()}, 'result')) |
3246
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
414 ; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
415 end |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 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
|
420 end |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
421 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
422 end |
6139
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
423 |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
424 function room_mt:get_subject() |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
425 return self._data['subject'], self._data['subject_from'] |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
426 end |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
427 local function create_subject_message(subject) |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
428 return st.message({type='groupchat'}) |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
429 :tag('subject'):text(subject):up(); |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
430 end |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
431 function room_mt:send_subject(to) |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
432 local from, subject = self:get_subject() |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
433 if subject then |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
434 local msg = create_subject_message(subject) |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
435 msg.attr.from = from |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
436 msg.attr.to = to |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
437 self:route_stanza(msg); |
6139
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
438 end |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
439 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
440 function room_mt:set_subject(current_nick, subject) |
1734 | 441 if subject == "" then subject = nil; end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
442 self._data['subject'] = subject; |
3393
5b8de0731c4d
MUC: Store the nick (full room JID) which set the subject, and send subject to occupants from that JID.
Waqas Hussain <waqas20@gmail.com>
parents:
3361
diff
changeset
|
443 self._data['subject_from'] = current_nick; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
444 if self.save then self:save(); end |
6139
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
445 local msg = create_subject_message(subject) |
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
446 msg.attr.from = current_nick |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
447 self:broadcast_message(msg, false); |
1734 | 448 return true; |
449 end | |
450 | |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
451 function room_mt:handle_kickable(origin, stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
452 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
453 local occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
460 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
461 :tag('status'):text(error_message)); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
462 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
463 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
|
464 :tag("status", {code = "307"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
465 self:publicise_occupant_status(occupant, x); |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
466 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
|
467 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
|
468 |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
469 function room_mt:set_name(name) |
3510
711eb5bf94b4
MUC: Make the room node be the default room name (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3509
diff
changeset
|
470 if name == "" or type(name) ~= "string" or name == (jid_split(self.jid)) then name = nil; end |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
471 if self._data.name ~= name then |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
472 self._data.name = name; |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
473 if self.save then self:save(true); end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
474 end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
475 end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
476 function room_mt:get_name() |
3510
711eb5bf94b4
MUC: Make the room node be the default room name (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3509
diff
changeset
|
477 return self._data.name or jid_split(self.jid); |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
478 end |
3508
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
479 function room_mt:set_description(description) |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
480 if description == "" or type(description) ~= "string" then description = nil; end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
481 if self._data.description ~= description then |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
482 self._data.description = description; |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
483 if self.save then self:save(true); end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
484 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
485 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
486 function room_mt:get_description() |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
487 return self._data.description; |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
488 end |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
489 function room_mt:set_password(password) |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
490 if password == "" or type(password) ~= "string" then password = nil; end |
3249
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
491 if self._data.password ~= password then |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
492 self._data.password = password; |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
493 if self.save then self:save(true); end |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
494 end |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
495 end |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
496 function room_mt:get_password() |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
497 return self._data.password; |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
498 end |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
499 function room_mt:set_moderated(moderated) |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
500 moderated = moderated and true or nil; |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
501 if self._data.moderated ~= moderated then |
3252
22062c50eabe
MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents:
3251
diff
changeset
|
502 self._data.moderated = moderated; |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
503 if self.save then self:save(true); end |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
504 end |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
505 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
506 function room_mt:get_moderated() |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
507 return self._data.moderated; |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
508 end |
3254
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
509 function room_mt:set_members_only(members_only) |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
510 members_only = members_only and true or nil; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
511 if self._data.members_only ~= members_only then |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
512 self._data.members_only = members_only; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
513 if self.save then self:save(true); end |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
514 end |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
515 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
516 function room_mt:get_members_only() |
3254
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
517 return self._data.members_only; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
518 end |
3258
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
519 function room_mt:set_persistent(persistent) |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
520 persistent = persistent and true or nil; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
521 if self._data.persistent ~= persistent then |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
522 self._data.persistent = persistent; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
523 if self.save then self:save(true); end |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
524 end |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
525 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
526 function room_mt:get_persistent() |
3258
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
527 return self._data.persistent; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
528 end |
3261
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
529 function room_mt:set_hidden(hidden) |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
530 hidden = hidden and true or nil; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
531 if self._data.hidden ~= hidden then |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
532 self._data.hidden = hidden; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
533 if self.save then self:save(true); end |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
534 end |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
535 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
536 function room_mt:get_hidden() |
3261
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
537 return self._data.hidden; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
538 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
539 function room_mt:get_public() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
540 return not self:get_hidden(); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
541 end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
542 function room_mt:set_public(public) |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
543 return self:set_hidden(not public); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
544 end |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
545 function room_mt:set_changesubject(changesubject) |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
546 changesubject = changesubject and true or nil; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
547 if self._data.changesubject ~= changesubject then |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
548 self._data.changesubject = changesubject; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
549 if self.save then self:save(true); end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
550 end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
551 end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
552 function room_mt:get_changesubject() |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
553 return self._data.changesubject; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
554 end |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
555 function room_mt:get_historylength() |
4785
36234dc4b177
mod_muc/muc.lib: Fall back to default_history_length if no length in config
Matthew Wild <mwild1@gmail.com>
parents:
4766
diff
changeset
|
556 return self._data.history_length or default_history_length; |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
557 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
558 function room_mt:set_historylength(length) |
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
|
559 length = math.min(tonumber(length) or default_history_length, max_history_length or math.huge); |
4876
fa41d05ee7ef
muc.lib: room:set_historylength(): Condense code, and don't store length when equal to default
Matthew Wild <mwild1@gmail.com>
parents:
4875
diff
changeset
|
560 if length == default_history_length then |
fa41d05ee7ef
muc.lib: room:set_historylength(): Condense code, and don't store length when equal to default
Matthew Wild <mwild1@gmail.com>
parents:
4875
diff
changeset
|
561 length = nil; |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
562 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
563 self._data.history_length = length; |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
564 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
565 |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
566 |
5600
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
567 local valid_whois = { moderators = true, anyone = true }; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
568 |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
569 function room_mt:set_whois(whois) |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
570 if valid_whois[whois] and self._data.whois ~= whois then |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
571 self._data.whois = whois; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
572 if self.save then self:save(true); end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
573 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
574 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
575 |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
576 function room_mt:get_whois() |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
577 return self._data.whois; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
578 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
579 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
580 module:hook("muc-room-pre-create", function(event) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
581 local room = event.room; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
582 if room:is_locked() and not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
583 room:unlock(); -- Older groupchat protocol doesn't lock |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
584 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
585 end, 10); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
586 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
587 -- Give the room creator owner affiliation |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
588 module:hook("muc-room-pre-create", function(event) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
589 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
|
590 end, -1); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
591 |
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
|
592 module:hook("muc-occupant-pre-join", function(event) |
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
|
593 return module:fire_event("muc-occupant-pre-join/affiliation", event) |
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
|
594 or module:fire_event("muc-occupant-pre-join/password", event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
595 or module:fire_event("muc-occupant-pre-join/locked", event); |
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
|
596 end, -1) |
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
|
597 |
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
|
598 module:hook("muc-occupant-pre-join/password", function(event) |
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
|
599 local room, stanza = event.room, event.stanza; |
6134
48b6ef993888
plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
daurnimator <quae@daurnimator.com>
parents:
6133
diff
changeset
|
600 local password = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
6136
2068242028ff
plugins/muc/muc.lib: Better password check
daurnimator <quae@daurnimator.com>
parents:
6135
diff
changeset
|
601 password = password and password:get_child_text("password", "http://jabber.org/protocol/muc"); |
2068242028ff
plugins/muc/muc.lib: Better password check
daurnimator <quae@daurnimator.com>
parents:
6135
diff
changeset
|
602 if not password or password == "" then password = nil; end |
2068242028ff
plugins/muc/muc.lib: Better password check
daurnimator <quae@daurnimator.com>
parents:
6135
diff
changeset
|
603 if room:get_password() ~= password then |
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
|
604 local from, to = stanza.attr.from, stanza.attr.to; |
6134
48b6ef993888
plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
daurnimator <quae@daurnimator.com>
parents:
6133
diff
changeset
|
605 log("debug", "%s couldn't join due to invalid password: %s", from, to); |
48b6ef993888
plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
daurnimator <quae@daurnimator.com>
parents:
6133
diff
changeset
|
606 local reply = st.error_reply(stanza, "auth", "not-authorized"):up(); |
48b6ef993888
plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
daurnimator <quae@daurnimator.com>
parents:
6133
diff
changeset
|
607 reply.tags[1].attr.code = "401"; |
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
|
608 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
6134
48b6ef993888
plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
daurnimator <quae@daurnimator.com>
parents:
6133
diff
changeset
|
609 return true; |
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
|
610 end |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
611 end, -1); |
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
|
612 |
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
|
613 module:hook("muc-occupant-pre-join/locked", function(event) |
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
|
614 if event.room:is_locked() then -- Deny entry |
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
|
615 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found")); |
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
|
616 return true; |
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
|
617 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
618 end, -1); |
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
|
619 |
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
|
620 -- registration required for entering members-only room |
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
|
621 module:hook("muc-occupant-pre-join/affiliation", function(event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
622 local room, stanza = event.room, event.stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
623 local affiliation = room:get_affiliation(stanza.attr.from); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
624 if affiliation == nil and event.room:get_members_only() then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
625 local reply = st.error_reply(stanza, "auth", "registration-required"):up(); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
626 reply.tags[1].attr.code = "407"; |
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
|
627 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
628 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
629 end |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
630 end, -1); |
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
|
631 |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
632 -- check if user is banned |
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
|
633 module:hook("muc-occupant-pre-join/affiliation", function(event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
634 local room, stanza = event.room, event.stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
635 local affiliation = room:get_affiliation(stanza.attr.from); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
636 if affiliation == "outcast" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 return true; |
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
|
641 end |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
642 end, -1); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
643 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
644 module:hook("muc-occupant-joined", function(event) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
645 local room, stanza = event.room, event.stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
646 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
647 room:send_occupant_list(real_jid, function(nick, occupant) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
648 -- Don't include self |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
649 return occupant.sessions[real_jid] == nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
650 end); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
651 room:send_history(stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
652 room:send_subject(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
653 end, -1); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
654 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 return self:handle_kickable(origin, stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
659 elseif type == nil or type == "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
660 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
661 local bare_jid = jid_bare(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
662 local orig_occupant, dest_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
663 local is_new_room = next(self._affiliations) == nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
664 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
665 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
|
666 if module:fire_event("muc-room-pre-create", { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
667 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
668 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
669 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
670 }) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
671 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
672 orig_occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
673 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
|
674 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
675 local is_first_dest_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
676 if type == "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
677 -- dest_occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
678 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
|
679 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
|
680 dest_occupant = orig_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
681 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
682 local dest_jid = stanza.attr.to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
683 dest_occupant = self:get_occupant_by_nick(dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
684 if dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
685 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
|
686 is_first_dest_session = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
687 dest_occupant = self:new_occupant(bare_jid, dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
688 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
689 is_first_dest_session = false; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
690 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
691 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
692 local is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
693 if orig_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
694 -- Is there are least 2 sessions? |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
695 is_last_orig_session = next(orig_occupant.sessions, next(orig_occupant.sessions)) == nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
696 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
697 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
698 local event, event_name = { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
699 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
700 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
701 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
702 is_first_session = is_first_dest_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
703 is_last_session = is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
704 }; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
705 if orig_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
706 event_name = "muc-occupant-pre-join"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
707 event.is_new_room = is_new_room; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
708 elseif dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
709 event_name = "muc-occupant-pre-leave"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
710 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
711 event_name = "muc-occupant-pre-change"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
712 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
713 if module:fire_event(event_name, event) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
714 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
715 -- Check for nick conflicts |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
716 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
|
717 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
|
718 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
719 reply.tags[1].attr.code = "409"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
720 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
721 return true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
722 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
723 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
724 -- Send presence stanza about original occupant |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
725 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
726 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
727 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
728 if dest_occupant == nil then -- Session is leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
729 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
730 orig_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
731 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
732 log("debug", "session %s is changing from occupant %s to %s", real_jid, orig_occupant.nick, dest_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
733 orig_occupant:remove_session(real_jid); -- If we are moving to a new nick; we don't want to get our own presence |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
734 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
735 local dest_nick = select(3, jid_split(dest_occupant.nick)); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
736 local affiliation = self:get_affiliation(bare_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
737 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
738 -- This session |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
739 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
|
740 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
|
741 -- Show the other session leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
742 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
|
743 :tag("status"):text("you are joining pre-existing session " .. dest_nick):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
744 add_item(x, affiliation, "none"); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
745 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
|
746 :add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
747 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
748 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
749 if is_last_orig_session then -- User is moving to a new session |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
750 log("debug", "no sessions in %s left; marking as nick change", orig_occupant.nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
751 -- Everyone gets to see this as a nick change |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
752 local jid = self:get_whois() ~= "anyone" and real_jid or nil; -- FIXME: mods should see real jids |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
753 add_item(orig_x, affiliation, orig_occupant.role, jid, dest_nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
754 orig_x:tag("status", {code = "303";}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
755 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
756 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
757 -- The session itself always sees a nick change |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
758 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
|
759 add_item(x, affiliation, orig_occupant.role, real_jid, dest_nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
760 -- self:build_item_list(orig_occupant, x, false); -- COMPAT |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
761 x:tag("status", {code = "303";}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
762 x:tag("status", {code = "110";}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
763 self:route_stanza(st.presence{from = dest_occupant.nick, to = real_jid, type = "unavailable"}:add_child(x)); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
764 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
765 self:save_occupant(orig_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
766 self:publicise_occupant_status(orig_occupant, orig_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
767 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
768 if is_last_orig_session then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
769 module:fire_event("muc-occupant-left", {room = self; nick = orig_occupant.nick;}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
770 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
771 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
772 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
773 if dest_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
774 dest_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
775 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
|
776 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
777 dest_x:tag("status", {code = "201"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
778 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
779 if orig_occupant == nil and self:get_whois() == "anyone" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
780 dest_x:tag("status", {code = "100"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
781 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
782 self:save_occupant(dest_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
783 self:publicise_occupant_status(dest_occupant, dest_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
784 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
785 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
|
786 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
|
787 -- Show the original nick joining again |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
788 local pr = st.clone(orig_occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
789 pr.attr.to = real_jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
790 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
|
791 self:build_item_list(orig_occupant, x, false); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
792 -- 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
|
793 pr:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
794 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
795 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
796 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
797 if orig_occupant == nil and is_first_dest_session then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
798 module:fire_event("muc-occupant-joined", {room = self; nick = dest_occupant.nick; stanza = stanza;}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
799 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
800 end |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
801 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
|
802 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
|
803 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
|
804 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
805 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
806 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
807 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
808 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
809 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
|
810 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
|
811 local type = stanza.attr.type; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
812 local id = stanza.attr.id; |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
813 local current_nick = self:get_occupant_jid(from); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
814 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
|
815 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
|
816 do -- deconstruct_stanza_id |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
817 if not current_nick or not occupant 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
|
818 local from_jid, id, to_jid_hash = (base64.decode(stanza.attr.id) or ""):match("^(.+)%z(.*)%z(.+)$"); |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
819 if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
820 local session_jid |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
821 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
|
822 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
|
823 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
|
824 break; |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
825 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
826 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
827 if session_jid == nil then return nil; end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
828 stanza.attr.from, stanza.attr.to, stanza.attr.id = current_nick, session_jid, id |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
829 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
830 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
|
831 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
832 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
|
833 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
834 else -- Type is "get" or "set" |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
835 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
|
836 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
|
837 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
838 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
839 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
|
840 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
|
841 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
842 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
|
843 do -- construct_stanza_id |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
844 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
|
845 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
846 stanza.attr.from, stanza.attr.to = current_nick, occupant.jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
847 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
|
848 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
|
849 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
|
850 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
851 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
852 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
|
853 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
854 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
855 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
856 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
857 function room_mt:handle_message_to_occupant(origin, stanza) |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
858 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
|
859 local current_nick = self:get_occupant_jid(from); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
860 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
|
861 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
|
862 if type ~= "error" then |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
863 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
864 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
865 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
866 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
867 if type == "groupchat" then -- groupchat messages not allowed in PM |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
868 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
869 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
870 elseif type == "error" and is_kickable_error(stanza) then |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
871 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
|
872 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
|
873 end |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
874 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
875 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
|
876 if not o_data then |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
877 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
|
878 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
879 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
880 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
|
881 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
|
882 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
|
883 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
|
884 -- 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
|
885 stanza.attr.from = from; |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
886 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
887 end |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
888 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
889 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
|
890 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
|
891 :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
|
892 ); |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
893 end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
894 |
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
|
895 function room_mt:get_form_layout(actor) |
6118
aae3d6daa50d
plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
daurnimator <quae@daurnimator.com>
parents:
6117
diff
changeset
|
896 local whois = self:get_whois() |
5541
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
897 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
|
898 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
|
899 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
|
900 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
901 name = 'FORM_TYPE', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
902 type = 'hidden', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
903 value = 'http://jabber.org/protocol/muc#roomconfig' |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
904 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
905 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
906 name = 'muc#roomconfig_roomname', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
907 type = 'text-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
908 label = 'Name', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
909 value = self:get_name() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
910 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
911 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
912 name = 'muc#roomconfig_roomdesc', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
913 type = 'text-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
914 label = 'Description', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
915 value = self:get_description() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
916 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
917 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
918 name = 'muc#roomconfig_persistentroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
919 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
920 label = 'Make Room Persistent?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
921 value = self:get_persistent() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
922 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
923 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
924 name = 'muc#roomconfig_publicroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
925 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
926 label = 'Make Room Publicly Searchable?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
927 value = not self:get_hidden() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
928 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
929 { |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
930 name = 'muc#roomconfig_changesubject', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
931 type = 'boolean', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
932 label = 'Allow Occupants to Change Subject?', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
933 value = self:get_changesubject() |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
934 }, |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
935 { |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
936 name = 'muc#roomconfig_whois', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
937 type = 'list-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
938 label = 'Who May Discover Real JIDs?', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
939 value = { |
6118
aae3d6daa50d
plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
daurnimator <quae@daurnimator.com>
parents:
6117
diff
changeset
|
940 { value = 'moderators', label = 'Moderators Only', default = whois == 'moderators' }, |
aae3d6daa50d
plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
daurnimator <quae@daurnimator.com>
parents:
6117
diff
changeset
|
941 { value = 'anyone', label = 'Anyone', default = whois == 'anyone' } |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
942 } |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
943 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
944 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
945 name = 'muc#roomconfig_roomsecret', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
946 type = 'text-private', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
947 label = 'Password', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
948 value = self:get_password() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
949 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
950 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
951 name = 'muc#roomconfig_moderatedroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
952 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
953 label = 'Make Room Moderated?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
954 value = self:get_moderated() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
955 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
956 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
957 name = 'muc#roomconfig_membersonly', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
958 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
959 label = 'Make Room Members-Only?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
960 value = self:get_members_only() |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
961 }, |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
962 { |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
963 name = 'muc#roomconfig_historylength', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
964 type = 'text-single', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
965 label = 'Maximum Number of History Messages Returned by Room', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
966 value = tostring(self:get_historylength()) |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
967 } |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
968 }); |
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
|
969 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
|
970 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
971 |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
972 function room_mt:process_form(origin, stanza) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
973 local query = stanza.tags[1]; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
974 local form = query:get_child("x", "jabber:x:data") |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
975 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
976 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
977 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
978 |
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
|
979 local fields = self:get_form_layout(stanza.attr.from):data(form); |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
980 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); return; end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
981 |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
982 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
983 local changed = {}; |
5541
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
984 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
985 local function handle_option(name, field, allowed) |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
986 local new = fields[field]; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
987 if new == nil then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
988 if allowed and not allowed[new] then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
989 if new == self["get_"..name](self) then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
990 changed[name] = true; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
991 self["set_"..name](self, new); |
3508
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
992 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
993 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
994 local event = { room = self, fields = fields, changed = changed, stanza = stanza, origin = origin, update_option = handle_option }; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
995 module:fire_event("muc-config-submitted", event); |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
996 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
997 handle_option("name", "muc#roomconfig_roomname"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
998 handle_option("description", "muc#roomconfig_roomdesc"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
999 handle_option("persistent", "muc#roomconfig_persistentroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1000 handle_option("moderated", "muc#roomconfig_moderatedroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1001 handle_option("members_only", "muc#roomconfig_membersonly"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1002 handle_option("public", "muc#roomconfig_publicroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1003 handle_option("changesubject", "muc#roomconfig_changesubject"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1004 handle_option("historylength", "muc#roomconfig_historylength"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1005 handle_option("whois", "muc#roomconfig_whois", valid_whois); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1006 handle_option("password", "muc#roomconfig_roomsecret"); |
3248
f8d14ea3ad0e
MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents:
3247
diff
changeset
|
1007 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
1008 if self.save then self:save(true); end |
6129
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
1009 if self:is_locked() then |
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
1010 self:unlock(); |
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
|
1011 end |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
1012 origin.send(st.reply(stanza)); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
1013 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1014 if next(changed) then |
3592
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
1015 local msg = st.message({type='groupchat', from=self.jid}) |
6188
f47268c8a8d0
plugins/muc/muc.lib: Status codes should be inside of x element
daurnimator <quae@daurnimator.com>
parents:
6187
diff
changeset
|
1016 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
f47268c8a8d0
plugins/muc/muc.lib: Status codes should be inside of x element
daurnimator <quae@daurnimator.com>
parents:
6187
diff
changeset
|
1017 :tag('status', {code = '104'}):up() |
f47268c8a8d0
plugins/muc/muc.lib: Status codes should be inside of x element
daurnimator <quae@daurnimator.com>
parents:
6187
diff
changeset
|
1018 :up(); |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
1019 if changed.whois then |
5600
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
1020 local code = (self:get_whois() == 'moderators') and "173" or "172"; |
3592
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
1021 msg.tags[1]:tag('status', {code = code}):up(); |
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
1022 end |
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
1023 self:broadcast_message(msg, false) |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
1024 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
1025 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
1026 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1027 -- Removes everyone from the room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1028 function room_mt:clear(x) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1029 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
|
1030 local occupants_updated = {}; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1031 for nick, occupant in self:each_occupant() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1032 occupant.role = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1033 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1034 occupants_updated[occupant] = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1035 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1036 for occupant in pairs(occupants_updated) do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1037 self:publicise_occupant_status(occupant, x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1038 module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; }); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1039 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1040 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1041 |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
1042 function room_mt:destroy(newjid, reason, password) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1043 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
|
1044 :tag("item", { affiliation='none', role='none' }):up() |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1045 :tag("destroy", {jid=newjid}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1046 if reason then x:tag("reason"):text(reason):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1047 if password then x:tag("password"):text(password):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1048 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1049 self:clear(x); |
3259
a5b9209efb23
MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3258
diff
changeset
|
1050 self:set_persistent(false); |
5577
8b09b0d068d4
mod_muc: Fire muc-room-created and muc-room-destroyed events (thanks nik)
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
1051 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
|
1052 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
1053 |
6101
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1054 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
|
1055 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
|
1056 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1057 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1058 |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1059 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
|
1060 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
|
1061 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1062 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
1063 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 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
|
1070 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1071 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1072 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1080 local actor = stanza.attr.from; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
1081 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
|
1082 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
|
1083 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
|
1084 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
|
1085 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
|
1086 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
|
1087 else |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1088 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
|
1089 end |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1090 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1091 origin.send(st.reply(stanza)); |
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1092 return true; |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1093 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1094 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 local _aff = item.attr.affiliation; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1100 local _rol = item.attr.role; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1101 if _aff and not _rol then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1102 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1103 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1104 for jid, affiliation in pairs(self._affiliations) do |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1105 if affiliation == _aff then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1106 reply:tag("item", {affiliation = _aff, jid = jid}):up(); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1107 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1108 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1109 origin.send(reply); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1110 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1111 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1112 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
|
1113 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1114 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1115 elseif _rol 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
|
1116 local role = self:get_role(self:get_occupant_jid(actor)) or self:get_default_role(affiliation); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1117 if role == "moderator" then |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1118 if _rol == "none" then _rol = nil; end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1119 self:send_occupant_list(actor, function(occupant_jid, occupant) return occupant.role == _rol end); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1120 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1121 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1122 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
|
1123 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1124 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1125 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1126 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
|
1127 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1128 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1129 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1130 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1131 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
|
1132 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
|
1133 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
|
1134 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1135 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1136 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1137 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
|
1138 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1139 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1140 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
|
1141 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
|
1142 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
|
1143 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1144 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1145 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1146 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
|
1147 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
|
1148 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
|
1149 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1150 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
|
1151 local newjid = child.attr.jid; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1157 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1158 self:process_form(origin, stanza); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1159 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1160 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1161 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
1162 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1163 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
|
1164 local from = stanza.attr.from; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1165 local occupant = self:get_occupant_by_real_jid(from); |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1166 if not occupant then -- not in room |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1167 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
1168 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
|
1169 elseif occupant.role == "visitor" then |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1170 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
1171 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
|
1172 else |
5613
f3166adab512
mod_muc: Remove unused variable
Matthew Wild <mwild1@gmail.com>
parents:
5612
diff
changeset
|
1173 local from = stanza.attr.from; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1174 stanza.attr.from = occupant.nick; |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1175 local subject = stanza:get_child_text("subject"); |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1176 if subject then |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1177 if occupant.role == "moderator" or |
6118
aae3d6daa50d
plugins/muc/muc.lib: Fetch config via accessors instead of using `_data`
daurnimator <quae@daurnimator.com>
parents:
6117
diff
changeset
|
1178 ( self:get_changesubject() and occupant.role == "participant" ) then -- and participant |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1179 self:set_subject(occupant.nick, subject); |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1180 else |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1181 stanza.attr.from = from; |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1182 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1183 end |
1734 | 1184 else |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1185 self:broadcast_message(stanza, self:get_historylength() > 0 and stanza:get_child("body")); |
1734 | 1186 end |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1187 stanza.attr.from = from; |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
1188 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
|
1189 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1190 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1191 |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1192 -- 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
|
1193 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
|
1194 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
|
1195 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
|
1196 if current_nick then |
1734 | 1197 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
|
1198 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
|
1199 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
|
1200 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
|
1201 end |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
1202 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
|
1203 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1204 |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1205 function room_mt:handle_mediated_invite(origin, stanza) |
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1206 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite") |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1207 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
|
1208 local current_nick = self:get_occupant_jid(_from) |
6124
203f2b4933b0
plugins/muc/muc.lib: Check role instead of current_nick
daurnimator <quae@daurnimator.com>
parents:
6123
diff
changeset
|
1209 -- Need visitor role or higher to invite |
6127
a66ebc5d0ab5
plugins/muc/muc.lib: Allow users with affiliations to invite while not in room themselves
daurnimator <quae@daurnimator.com>
parents:
6126
diff
changeset
|
1210 if not self:get_role(current_nick) or not self:get_default_role(self:get_affiliation(_from)) then |
6103
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1211 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1212 return true; |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1213 end |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1214 local _invitee = jid_prep(payload.attr.to); |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1215 if _invitee then |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1216 local _reason = payload:get_child_text("reason"); |
6128
8a71a1c34202
plugins/muc/muc.lib: Use occupant jids when whois == "moderators"
daurnimator <quae@daurnimator.com>
parents:
6127
diff
changeset
|
1217 if self:get_whois() == "moderators" then |
8a71a1c34202
plugins/muc/muc.lib: Use occupant jids when whois == "moderators"
daurnimator <quae@daurnimator.com>
parents:
6127
diff
changeset
|
1218 _from = current_nick; |
8a71a1c34202
plugins/muc/muc.lib: Use occupant jids when whois == "moderators"
daurnimator <quae@daurnimator.com>
parents:
6127
diff
changeset
|
1219 end |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1220 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1221 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1222 :tag('invite', {from=_from}) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1223 :tag('reason'):text(_reason or ""):up() |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1224 :up(); |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1225 local password = self:get_password(); |
6107
5491be05b84c
plugins/muc/muc: Only call get_password once in invite creation
daurnimator <quae@daurnimator.com>
parents:
6106
diff
changeset
|
1226 if password then |
5491be05b84c
plugins/muc/muc: Only call get_password once in invite creation
daurnimator <quae@daurnimator.com>
parents:
6106
diff
changeset
|
1227 invite:tag("password"):text(password):up(); |
5491be05b84c
plugins/muc/muc: Only call get_password once in invite creation
daurnimator <quae@daurnimator.com>
parents:
6106
diff
changeset
|
1228 end |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1229 invite:up() |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1230 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1231 :text(_reason or "") |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1232 :up() |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1233 :tag('body') -- Add a plain message for clients which don't support invites |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1234 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1235 :up(); |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1236 module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}); |
6098
1d7e5d091980
plugins/muc/muc.lib: Add some missing return values
daurnimator <quae@daurnimator.com>
parents:
6097
diff
changeset
|
1237 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
|
1238 else |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1239 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
|
1240 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
|
1241 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1242 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1243 |
6125
4a35a0281d8a
plugins/muc/muc.lib: Send invite out from event: removes '-prepared' from event name
daurnimator <quae@daurnimator.com>
parents:
6124
diff
changeset
|
1244 module:hook("muc-invite", function(event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1245 event.room:route_stanza(event.stanza); |
6125
4a35a0281d8a
plugins/muc/muc.lib: Send invite out from event: removes '-prepared' from event name
daurnimator <quae@daurnimator.com>
parents:
6124
diff
changeset
|
1246 return true; |
4a35a0281d8a
plugins/muc/muc.lib: Send invite out from event: removes '-prepared' from event name
daurnimator <quae@daurnimator.com>
parents:
6124
diff
changeset
|
1247 end, -1) |
4a35a0281d8a
plugins/muc/muc.lib: Send invite out from event: removes '-prepared' from event name
daurnimator <quae@daurnimator.com>
parents:
6124
diff
changeset
|
1248 |
6121
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1249 -- When an invite is sent; add an affiliation for the invitee |
6125
4a35a0281d8a
plugins/muc/muc.lib: Send invite out from event: removes '-prepared' from event name
daurnimator <quae@daurnimator.com>
parents:
6124
diff
changeset
|
1250 module:hook("muc-invite", function(event) |
6121
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1251 local room, stanza = event.room, event.stanza |
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1252 local invitee = stanza.attr.to |
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1253 if room:get_members_only() and not room:get_affiliation(invitee) then |
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1254 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from |
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1255 local current_nick = room:get_occupant_jid(from) |
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1256 log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid); |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1257 room:set_affiliation(from, invitee, "member", "Invited by " .. current_nick) |
6121
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1258 end |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1259 end); |
6121
74bbcef3978e
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
daurnimator <quae@daurnimator.com>
parents:
6120
diff
changeset
|
1260 |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1261 function room_mt:handle_mediated_decline(origin, stanza) |
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
1262 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
|
1263 local declinee = jid_prep(payload.attr.to); |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1264 if declinee then |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1265 local from, to = stanza.attr.from, stanza.attr.to; |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1266 -- TODO: Validate declinee |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1267 local reason = payload:get_child_text("reason") |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1268 local decline = st.message({from = to, to = declinee, id = stanza.attr.id}) |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1269 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1270 :tag('decline', {from=from}) |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1271 :tag('reason'):text(reason or ""):up() |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1272 :up() |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1273 :up() |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1274 :tag('body') -- Add a plain message for clients which don't support declines |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1275 :text(from..' declined your invite to the room '..to..(reason and (' ('..reason..')') or "")) |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1276 :up(); |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1277 module:fire_event("muc-decline", { room = self, stanza = decline, origin = origin, incoming = stanza }); |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1278 return true; |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1279 else |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1280 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1281 return true; |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1282 end |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1283 end |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1284 |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1285 module:hook("muc-decline", function(event) |
6143
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1286 local room, stanza = event.room, event.stanza |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1287 local occupant = room:get_occupant_by_real_jid(stanza.attr.to); |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1288 if occupant then |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1289 room:route_to_occupant(occupant, stanza) |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1290 else |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1291 room:route_stanza(stanza); |
82b3a2155a55
plugins/muc/muc.lib: If decline is to person in room; route to all sessions
daurnimator <quae@daurnimator.com>
parents:
6142
diff
changeset
|
1292 end |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1293 return true; |
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1294 end, -1) |
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
1295 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
1296 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
|
1297 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
|
1298 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
|
1299 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
|
1300 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
|
1301 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
|
1302 elseif type == nil then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1303 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
|
1304 if x then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
1305 local payload = x.tags[1]; |
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
|
1306 if payload == nil then |
260a18062cb2
plugins/muc/muc: Rename `handle_invite_to_room` to `handle_mediated_invite`; clean up logic
daurnimator <quae@daurnimator.com>
parents:
6103
diff
changeset
|
1307 -- 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
|
1308 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
|
1309 return self:handle_mediated_invite(origin, stanza) |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
1310 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
|
1311 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
|
1312 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
|
1313 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
|
1314 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
|
1315 end |
1734 | 1316 end |
1317 end | |
1318 | |
6111
f8b94903be52
plugins/muc: Provide a reasonable default `route_stanza`
daurnimator <quae@daurnimator.com>
parents:
6108
diff
changeset
|
1319 function room_mt:route_stanza(stanza) |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
1320 module:send(stanza); |
6111
f8b94903be52
plugins/muc: Provide a reasonable default `route_stanza`
daurnimator <quae@daurnimator.com>
parents:
6108
diff
changeset
|
1321 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1322 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1323 function room_mt:get_affiliation(jid) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1324 local node, host, resource = jid_split(jid); |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 return result; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1329 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1330 |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
1331 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
|
1332 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
|
1333 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1334 jid = jid_bare(jid); |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1335 |
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1336 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
|
1337 return nil, "modify", "not-acceptable"; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1338 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
1339 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
|
1340 |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1341 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
|
1342 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
|
1343 |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
1344 if actor ~= true then |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1345 local actor_bare = jid_bare(actor); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1346 local actor_affiliation = self._affiliations[actor_bare]; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1347 if actor_affiliation == "owner" then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1348 if actor_bare == jid then -- self change |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1349 -- need at least one owner |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1350 local is_last = true; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1351 for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1352 if is_last then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1353 return nil, "cancel", "conflict"; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1354 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1355 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1356 -- owners can do anything else |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1357 elseif affiliation == "owner" or affiliation == "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1358 or actor_affiliation ~= "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1359 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
|
1360 -- Can't demote owners or other admins |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1361 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
|
1362 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1363 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1364 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1365 -- Set in 'database' |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1366 self._affiliations[jid] = affiliation; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1367 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1368 -- Update roles |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1369 local role = self:get_default_role(affiliation); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1370 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
|
1371 local occupants_updated = {}; -- Filled with old roles |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1372 for nick, occupant in self:each_occupant() do |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1373 if occupant.bare_jid == jid then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1374 -- 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
|
1375 occupants_updated[occupant] = occupant.role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1376 if occupant.role ~= role and ( |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1377 is_downgrade or |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1378 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
|
1379 ) then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1380 occupant.role = role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1381 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
|
1382 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
|
1383 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
|
1384 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1385 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1386 -- Tell the room of the new occupant affiliations+roles |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1387 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
|
1388 if not role then -- getting kicked |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1389 if affiliation == "outcast" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1390 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
|
1391 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1392 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
|
1393 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1394 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1395 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
|
1396 for occupant, old_role in pairs(occupants_updated) do |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1397 self:publicise_occupant_status(occupant, x, actor, reason); |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1398 if is_semi_anonymous and |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1399 (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
|
1400 (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
|
1401 -- 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
|
1402 for real_jid in occupant:each_session() do |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1403 self:send_occupant_list(real_jid, function(occupant_jid, occupant) |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1404 return occupant.bare_jid ~= jid; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1405 end); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1406 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1407 end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1408 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1409 |
1755
1614e8e62ad5
MUC: Fixed an undefined global access.
Waqas Hussain <waqas20@gmail.com>
parents:
1754
diff
changeset
|
1410 if self.save then self:save(); end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1411 return true; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1412 end |
1734 | 1413 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1414 function room_mt:get_role(nick) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1415 local occupant = self:get_occupant_by_nick(nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1416 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
|
1417 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1418 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1419 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
|
1420 if not actor then return nil, "modify", "not-acceptable"; end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1421 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1422 local occupant = self:get_occupant_by_nick(occupant_jid); |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1423 if not occupant then return nil, "modify", "not-acceptable"; end |
5542
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1424 |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1425 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
|
1426 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
|
1427 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1428 role = role ~= "none" and role or nil; -- coerces `role == false` to `nil` |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1429 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1430 if actor ~= true then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1431 -- 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
|
1432 local occupant_affiliation = self:get_affiliation(occupant.bare_jid); |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1433 if occupant_affiliation == "owner" and occupant_affiliation == "admin" then |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1434 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
|
1435 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1436 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1437 -- 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
|
1438 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
|
1439 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
|
1440 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
|
1441 return nil, "cancel", "not-allowed"; |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1442 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1443 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1444 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1445 -- 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
|
1446 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
|
1447 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
|
1448 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
|
1449 end |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1450 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1451 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1452 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
|
1453 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
|
1454 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
|
1455 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1456 occupant.role = role; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1457 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1458 self:publicise_occupant_status(occupant, x, actor, reason); |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1459 return true; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1460 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1461 |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1462 local _M = {}; -- module "muc" |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1463 |
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
|
1464 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
|
1465 return setmetatable({ |
1734 | 1466 jid = jid; |
6129
6c66571ab0f9
plugins/muc: Have utility methods for locking the room
daurnimator <quae@daurnimator.com>
parents:
6128
diff
changeset
|
1467 locked = nil; |
1734 | 1468 _jid_nick = {}; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
1469 _occupants = {}; |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1470 _data = { |
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
|
1471 whois = 'moderators'; |
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
|
1472 history_length = math.min((config and config.history_length) |
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
|
1473 or default_history_length, max_history_length); |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1474 }; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1475 _affiliations = {}; |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1476 }, room_mt); |
1734 | 1477 end |
1478 | |
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
|
1479 function _M.set_max_history_length(_max_history_length) |
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
|
1480 max_history_length = _max_history_length or math.huge; |
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
|
1481 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
|
1482 |
5063
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1483 _M.room_mt = room_mt; |
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1484 |
1734 | 1485 return _M; |