Software /
code /
prosody
Annotate
plugins/muc/muc.lib.lua @ 6226:7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Fri, 18 Apr 2014 12:19:04 -0400 |
parent | 6225:12537f1c1fec |
child | 6227:bb75c011b15e |
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; |
1734 | 14 |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
15 local dataform = require "util.dataforms"; |
6217
657c707d9229
plugins/muc/muc.lib: Use util.iterators to count occupants
daurnimator <quae@daurnimator.com>
parents:
6216
diff
changeset
|
16 local iterators = require "util.iterators"; |
1734 | 17 local jid_split = require "util.jid".split; |
18 local jid_bare = require "util.jid".bare; | |
1862
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
19 local jid_prep = require "util.jid".prep; |
1734 | 20 local st = require "util.stanza"; |
21 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
|
22 local base64 = require "util.encodings".base64; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
23 local md5 = require "util.hashes".md5; |
1734 | 24 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
25 local occupant_lib = module:require "muc/occupant" |
6218
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
26 local muc_util = module:require "muc/util"; |
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
27 local is_kickable_error = muc_util.is_kickable_error; |
bf11910bad5a
plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
daurnimator <quae@daurnimator.com>
parents:
6217
diff
changeset
|
28 local valid_roles, valid_affiliations = muc_util.valid_roles, muc_util.valid_affiliations; |
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
|
29 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
30 local room_mt = {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
31 room_mt.__index = room_mt; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
32 |
5519
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
33 function room_mt:__tostring() |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
34 return "MUC room ("..self.jid..")"; |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
35 end |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
36 |
6119
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
37 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
|
38 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
|
39 end |
c13f5d6b9b16
plugins/muc/muc.lib: Use `get_occupant_jid` method instead of indexing _jid_nick
daurnimator <quae@daurnimator.com>
parents:
6118
diff
changeset
|
40 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
41 function room_mt:get_default_role(affiliation) |
6220
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
42 local role = module:fire_event("muc-get-default-role", { |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
43 room = self; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
44 affiliation = affiliation; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
45 affiliation_rank = valid_affiliations[affiliation or "none"]; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
46 }); |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
47 return role, valid_roles[role or "none"]; |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
48 end |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
49 module:hook("muc-get-default-role", function(event) |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
50 if event.affiliation_rank >= valid_affiliations.admin then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
51 return "moderator"; |
6226
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
52 elseif event.affiliation_rank >= valid_affiliations.none then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
53 return "participant"; |
6220
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
54 end |
4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
daurnimator <quae@daurnimator.com>
parents:
6219
diff
changeset
|
55 end); |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
56 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
57 --- Occupant functions |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
58 function room_mt:new_occupant(bare_real_jid, nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
59 local occupant = occupant_lib.new(bare_real_jid, nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
60 local affiliation = self:get_affiliation(bare_real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
61 occupant.role = self:get_default_role(affiliation); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
62 return occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
63 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
64 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
65 function room_mt:get_occupant_by_nick(nick) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
66 local occupant = self._occupants[nick]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
67 if occupant == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
68 return occupant_lib.copy(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
69 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
70 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
71 do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
72 local function next_copied_occupant(occupants, occupant_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
73 local next_occupant_jid, raw_occupant = next(occupants, occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
74 if next_occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
75 return next_occupant_jid, occupant_lib.copy(raw_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
76 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
77 function room_mt:each_occupant(read_only) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
78 return next_copied_occupant, self._occupants, nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
79 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
80 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
81 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
82 function room_mt:get_occupant_by_real_jid(real_jid) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
83 local occupant_jid = self:get_occupant_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
84 if occupant_jid == nil then return nil end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
85 return self:get_occupant_by_nick(occupant_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
86 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
87 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
88 function room_mt:save_occupant(occupant) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
89 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
|
90 local id = occupant.nick |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
91 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
92 -- Need to maintain _jid_nick secondary index |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
93 local old_occupant = self._occupants[id]; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
94 if old_occupant then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
95 for real_jid in pairs(old_occupant.sessions) do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
96 self._jid_nick[real_jid] = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
97 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
98 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
99 if occupant.role ~= nil and next(occupant.sessions) then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
100 for real_jid, presence in occupant:each_session() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
101 self._jid_nick[real_jid] = occupant.nick; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
102 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
103 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
104 occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
105 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
106 self._occupants[id] = 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: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
|
110 local to = stanza.attr.to; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
111 for jid, pr in occupant:each_session() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
112 if pr.attr.type ~= "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
113 stanza.attr.to = jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
114 self:route_stanza(stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
120 -- actor is the attribute table |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
121 local function add_item(x, affiliation, role, jid, nick, actor, reason) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
122 x:tag("item", {affiliation = affiliation; role = role; jid = jid; nick = nick;}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
123 if actor then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
124 x:tag("actor", actor):up() |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
125 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
126 if reason then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
127 x:tag("reason"):text(reason):up() |
1734 | 128 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
129 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
130 return x |
1734 | 131 end |
6213
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
132 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
133 -- actor is (real) jid |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
134 function room_mt:build_item_list(occupant, x, is_anonymous, nick, actor, reason) |
6213
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
135 local affiliation = self:get_affiliation(occupant.bare_jid) or "none"; |
95bddf0142f4
plugins/muc/muc.lib: Remember to coerce nil role to "none"
daurnimator <quae@daurnimator.com>
parents:
6212
diff
changeset
|
136 local role = occupant.role or "none"; |
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
|
137 local actor_attr; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
138 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
|
139 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
|
140 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
141 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
|
142 add_item(x, affiliation, role, nil, nick, actor_attr, reason); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
143 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
|
144 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
|
145 actor_attr.jid = actor; |
6179
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 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
|
148 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
|
149 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
150 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
151 return x |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
152 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
153 |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
154 function room_mt:broadcast_message(stanza) |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
155 module:fire_event("muc-broadcast-message", {room = self, stanza = stanza}); |
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
|
156 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
|
157 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
|
158 |
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
|
159 -- Broadcast a stanza to all occupants in the room. |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
160 -- 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
|
161 function room_mt:broadcast(stanza, cond_func) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
166 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
167 end |
1734 | 168 |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
169 local function can_see_real_jids(whois, occupant) |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
170 if whois == "anyone" then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
171 return true; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
172 elseif whois == "moderators" then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
173 return valid_roles[occupant.role or "none"] >= valid_roles.moderator; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
174 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
175 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
176 |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
177 local function get_base_presence(occupant) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
178 if occupant.role ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
179 -- Try to use main jid's presence |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
180 local pr = occupant:get_presence(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
181 if pr ~= nil then |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
182 return st.clone(pr); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
183 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
184 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
185 return st.presence {from = occupant.nick; type = "unavailable";}; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
186 end |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
187 |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
188 -- Broadcasts an occupant's presence to the whole room |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
189 -- Takes the x element that goes into the stanzas |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
190 function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason) |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
191 -- Build real jid and (optionally) occupant jid template presences |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
192 local function get_presence(is_anonymous) |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
193 local x = st.clone(base_x); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
194 self:build_item_list(occupant, x, is_anonymous, nick, actor, reason); |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
195 return get_base_presence(occupant):add_child(x), x; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
196 end |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
197 local full_p, full_x = get_presence(false); |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
198 local anon_p, anon_x; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
199 local function get_anon_p() |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
200 if anon_p == nil then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
201 anon_p, anon_x = get_presence(true); |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
202 end |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
203 return anon_p, anon_x; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
204 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
205 |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
206 local whois = self:get_whois(); |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
207 |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
208 -- General populance |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
209 for nick, n_occupant in self:each_occupant() do |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
210 if nick ~= occupant.nick then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
211 local pr; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
212 if can_see_real_jids(whois, occupant) or occupant.bare_jid == n_occupant.bare_jid then |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
213 pr = full_p; |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
214 else |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
215 pr = get_anon_p(); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
216 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
217 self:route_to_occupant(n_occupant, pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
218 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
219 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
220 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
221 -- Presences for occupant itself |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
222 full_x:tag("status", {code = "110";}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
223 if occupant.role == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
224 -- They get an unavailable |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
225 self:route_to_occupant(occupant, full_p); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
226 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
227 -- use their own presences as templates |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
228 for full_jid, pr in occupant:each_session() do |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
229 pr = st.clone(pr); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
230 pr.attr.to = full_jid; |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
231 -- You can always see your own full jids |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
232 pr:add_child(full_x); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
233 self:route_stanza(pr); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
234 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
235 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
236 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
237 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
238 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
|
239 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
|
240 local is_anonymous = true; |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
241 local whois = self:get_whois(); |
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
242 if whois ~= "anyone" then |
6185
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
243 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
|
244 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
|
245 local occupant = self:get_occupant_by_real_jid(to); |
6211
a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
daurnimator <quae@daurnimator.com>
parents:
6209
diff
changeset
|
246 if not occupant or can_see_real_jids(whois, occupant) then |
6185
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
247 is_anonymous = false; |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
248 end |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
249 end |
d4a8840e72f9
plugins/muc/muc.lib: Fix anonymous check in `send_occupant_list`
daurnimator <quae@daurnimator.com>
parents:
6184
diff
changeset
|
250 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
251 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
|
252 if filter == nil or filter(occupant_jid, occupant) then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
253 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
|
254 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
|
255 local pres = st.clone(occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
256 pres.attr.to = to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
257 pres:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
258 self:route_stanza(pres); |
1734 | 259 end |
260 end | |
261 end | |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5681
diff
changeset
|
262 |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
263 function room_mt:get_disco_info(stanza) |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
264 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
265 local form = dataform.new { |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
266 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" }; |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
267 }; |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
268 module:fire_event("muc-disco#info", {room = self; reply = reply; form = form;}); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
269 reply:add_child(form:form(nil, "result")); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
270 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
271 end |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
272 module:hook("muc-disco#info", function(event) |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
273 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up(); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
274 end); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
275 module:hook("muc-disco#info", function(event) |
6217
657c707d9229
plugins/muc/muc.lib: Use util.iterators to count occupants
daurnimator <quae@daurnimator.com>
parents:
6216
diff
changeset
|
276 local count = iterators.count(event.room:each_occupant()); |
6200
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
277 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
278 end); |
57bc52f67564
plugins/muc/muc.lib: Split up get_disco_info into events
daurnimator <quae@daurnimator.com>
parents:
6199
diff
changeset
|
279 |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 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
|
284 end |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
285 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
286 end |
6139
544f75256883
plugins/muc/muc.lib: Extra utility functions around subjects
daurnimator <quae@daurnimator.com>
parents:
6138
diff
changeset
|
287 |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
288 function room_mt:handle_kickable(origin, stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
289 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
290 local occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
297 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
298 :tag('status'):text(error_message)); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
299 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
300 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
|
301 :tag("status", {code = "307"}) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
306 -- Give the room creator owner affiliation |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
307 module:hook("muc-room-pre-create", function(event) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
308 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
|
309 end, -1); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
310 |
6180
35388114439f
plugins/muc/muc.lib: non-function changes (reordering, semicolons and comments)
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
311 -- check if user is banned |
6193
b9074126639f
plugins/muc/muc.lib: Remove top level pre-join event. Assign event priorities for other handlers
daurnimator <quae@daurnimator.com>
parents:
6192
diff
changeset
|
312 module:hook("muc-occupant-pre-join", function(event) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
313 local room, stanza = event.room, event.stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
314 local affiliation = room:get_affiliation(stanza.attr.from); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
315 if affiliation == "outcast" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 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
|
320 end |
6193
b9074126639f
plugins/muc/muc.lib: Remove top level pre-join event. Assign event priorities for other handlers
daurnimator <quae@daurnimator.com>
parents:
6192
diff
changeset
|
321 end, -10); |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
322 |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
323 -- Send occupant list to newly joined user |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
324 module:hook("muc-occupant-joined", function(event) |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
325 local real_jid = event.stanza.attr.from; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
326 event.room:send_occupant_list(real_jid, function(nick, occupant) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
327 -- Don't include self |
6192
f97aa1f4b1f1
plugins/muc/muc.lib: Use occupant methods where possible
daurnimator <quae@daurnimator.com>
parents:
6191
diff
changeset
|
328 return occupant:get_presence(real_jid) == nil; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
329 end); |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
330 end, 80); |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
331 |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 return self:handle_kickable(origin, stanza) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
336 elseif type == nil or type == "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
337 local real_jid = stanza.attr.from; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
338 local bare_jid = jid_bare(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
339 local orig_occupant, dest_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
340 local is_new_room = next(self._affiliations) == nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
341 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
342 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
|
343 if module:fire_event("muc-room-pre-create", { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
344 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
345 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
346 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
347 }) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
348 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
349 orig_occupant = self:get_occupant_by_real_jid(real_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
350 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
|
351 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
352 local is_first_dest_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
353 if type == "unavailable" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
354 -- dest_occupant = nil |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
355 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
|
356 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
|
357 dest_occupant = orig_occupant; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
358 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
359 local dest_jid = stanza.attr.to; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
360 dest_occupant = self:get_occupant_by_nick(dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
361 if dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
362 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
|
363 is_first_dest_session = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
364 dest_occupant = self:new_occupant(bare_jid, dest_jid); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
365 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
366 is_first_dest_session = false; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
367 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
368 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
369 local is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
370 if orig_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
371 -- Is there are least 2 sessions? |
6192
f97aa1f4b1f1
plugins/muc/muc.lib: Use occupant methods where possible
daurnimator <quae@daurnimator.com>
parents:
6191
diff
changeset
|
372 local iter, ob, last = orig_occupant:each_session(); |
f97aa1f4b1f1
plugins/muc/muc.lib: Use occupant methods where possible
daurnimator <quae@daurnimator.com>
parents:
6191
diff
changeset
|
373 is_last_orig_session = iter(ob, iter(ob, last)) == nil; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
374 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
375 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
376 local event, event_name = { |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
377 room = self; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
378 origin = origin; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
379 stanza = stanza; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
380 is_first_session = is_first_dest_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
381 is_last_session = is_last_orig_session; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
382 }; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
383 if orig_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
384 event_name = "muc-occupant-pre-join"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
385 event.is_new_room = is_new_room; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
386 elseif dest_occupant == nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
387 event_name = "muc-occupant-pre-leave"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
388 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
389 event_name = "muc-occupant-pre-change"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
390 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
391 if module:fire_event(event_name, event) then return true; end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
392 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
393 -- Check for nick conflicts |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
394 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
|
395 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
|
396 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
397 reply.tags[1].attr.code = "409"; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
398 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
399 return true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
400 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
401 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
402 -- Send presence stanza about original occupant |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
403 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
404 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
405 local dest_nick; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
406 if dest_occupant == nil then -- Session is leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
407 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
|
408 orig_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
409 else |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
410 log("debug", "session %s is changing from occupant %s to %s", real_jid, orig_occupant.nick, dest_occupant.nick); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
411 local generated_unavail = st.presence {from = orig_occupant.nick, to = real_jid, type = "unavailable"}; |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
412 orig_occupant:set_session(real_jid, generated_unavail); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
413 dest_nick = select(3, jid_split(dest_occupant.nick)); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
414 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
|
415 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
|
416 -- Show the other session leaving |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
417 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
|
418 :tag("status"):text("you are joining pre-existing session " .. dest_nick):up(); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
419 add_item(x, self:get_affiliation(bare_jid), "none"); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
420 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
|
421 :add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
422 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
423 end |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
424 if is_first_dest_session and is_last_orig_session then -- Normal nick change |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
425 log("debug", "no sessions in %s left; publically marking as nick change", orig_occupant.nick); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
426 orig_x:tag("status", {code = "303";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
427 else -- The session itself always needs to see a nick change |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
428 -- don't want to get our old nick's available presence, |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
429 -- so remove our session from there, and manually generate an unavailable |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
430 orig_occupant:remove_session(real_jid); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
431 log("debug", "generating nick change for %s", real_jid); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
432 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
433 -- self:build_item_list(orig_occupant, x, false, dest_nick); -- COMPAT: clients get confused if they see other items besides their own |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
434 add_item(x, self:get_affiliation(bare_jid), orig_occupant.role, real_jid, dest_nick); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
435 x:tag("status", {code = "303";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
436 x:tag("status", {code = "110";}):up(); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
437 self:route_stanza(generated_unavail:add_child(x)); |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
438 dest_nick = nil; -- set dest_nick to nil; so general populance doesn't see it for whole orig_occupant |
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
439 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
440 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
441 self:save_occupant(orig_occupant); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
442 self:publicise_occupant_status(orig_occupant, orig_x, dest_nick); |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
443 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
444 if is_last_orig_session then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
445 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
|
446 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
447 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
448 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
449 if dest_occupant ~= nil then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
450 dest_occupant:set_session(real_jid, stanza); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
451 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
|
452 if is_new_room then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
453 dest_x:tag("status", {code = "201"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
454 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
455 if orig_occupant == nil and self:get_whois() == "anyone" then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
456 dest_x:tag("status", {code = "100"}):up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
457 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
458 self:save_occupant(dest_occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
459 self:publicise_occupant_status(dest_occupant, dest_x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
460 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
461 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
|
462 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
|
463 -- Show the original nick joining again |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
464 local pr = st.clone(orig_occupant:get_presence()); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
465 pr.attr.to = real_jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
466 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
|
467 self:build_item_list(orig_occupant, x, false); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
468 -- 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
|
469 pr:add_child(x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
470 self:route_stanza(pr); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
471 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
472 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
473 if orig_occupant == nil and is_first_dest_session then |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
474 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
|
475 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
476 end |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
477 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
|
478 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
|
479 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
|
480 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
481 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
482 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
483 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
484 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
485 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
|
486 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
|
487 local type = stanza.attr.type; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
488 local id = stanza.attr.id; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
489 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
|
490 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
|
491 do -- deconstruct_stanza_id |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
492 if 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
|
493 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
|
494 if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
495 local from_occupant_jid = self:get_occupant_jid(from_jid); |
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
496 if from_occupant_jid == nil then return nil; end |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
497 local session_jid |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 break; |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
502 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
503 end |
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
504 if session_jid == nil then return nil; end |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
505 stanza.attr.from, stanza.attr.to, stanza.attr.id = from_jid, session_jid, id; |
6097
538cdc3d8225
plugins/muc/muc.lib: Move (de)construct_stanza_id into `handle_iq_to_occupant`
daurnimator <quae@daurnimator.com>
parents:
6096
diff
changeset
|
506 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
507 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
|
508 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
509 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
|
510 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
511 else -- Type is "get" or "set" |
6216
50b8b7caf200
plugins/muc/muc.lib: Move occupancy check to later in `deconstruct_stanza_id`: As vcards are from the bare jid, you need to use the `from_jid` out of the encoded `id`
daurnimator <quae@daurnimator.com>
parents:
6215
diff
changeset
|
512 local current_nick = self:get_occupant_jid(from); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
513 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
|
514 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
|
515 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
516 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
517 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
|
518 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
|
519 return true; |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
520 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
|
521 do -- construct_stanza_id |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
522 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
|
523 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
524 stanza.attr.from, stanza.attr.to = current_nick, occupant.jid; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
529 self:route_stanza(stanza); |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
530 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
|
531 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
532 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
533 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
534 |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
543 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
544 end |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
545 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
|
546 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
|
547 return true; |
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 end |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
552 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
553 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
|
554 if not o_data then |
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
555 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
|
556 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
557 end |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 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
|
562 -- 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
|
563 stanza.attr.from = from; |
6096
84f9123637d4
plugins/muc/muc.lib: Refactor _to_occupant handlers
daurnimator <quae@daurnimator.com>
parents:
6095
diff
changeset
|
564 return true; |
6094
db2faeb151b6
plugins/muc/muc.lib: Factor `handle_to_occupant` out into many functions
daurnimator <quae@daurnimator.com>
parents:
6093
diff
changeset
|
565 end |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
566 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
567 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
|
568 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
|
569 :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
|
570 ); |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
571 end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
572 |
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
|
573 function room_mt:get_form_layout(actor) |
5541
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
578 name = 'FORM_TYPE', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
579 type = 'hidden', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
580 value = 'http://jabber.org/protocol/muc#roomconfig' |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
581 } |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
582 }); |
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
|
583 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
|
584 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
585 |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
586 function room_mt:process_form(origin, stanza) |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
587 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
588 if form.attr.type == "cancel" then |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
589 origin.send(st.reply(stanza)); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
590 elseif form.attr.type == "submit" then |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
591 local fields = self:get_form_layout(stanza.attr.from):data(form); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
592 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
593 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
594 return true; |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
595 end |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
596 |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
597 local event = {room = self; origin = origin; stanza = stanza; fields = fields; status_codes = {};}; |
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
598 function event.update_option(name, field, allowed) |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
599 local new = fields[field]; |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
600 if new == nil then return; end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
601 if allowed and not allowed[new] then return; end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
602 if new == self["get_"..name](self) then return; end |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
603 event.status_codes["104"] = true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
604 self["set_"..name](self, new); |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
605 return true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
606 end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
607 module:fire_event("muc-config-submitted", event); |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
608 |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
609 if self.save then self:save(true); end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
610 origin.send(st.reply(stanza)); |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
611 |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
612 if next(event.status_codes) then |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
613 local msg = st.message({type='groupchat', from=self.jid}) |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
614 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
615 for code in pairs(event.status_codes) do |
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
616 msg:tag("status", {code = code;}):up(); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
617 end |
6203
b6ffce01e6cf
plugins/muc/muc.lib: Modify muc-config-submitted to keep a list of status codes instead of fields changed
daurnimator <quae@daurnimator.com>
parents:
6202
diff
changeset
|
618 msg:up(); |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
619 self:broadcast_message(msg); |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
620 end |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
621 else |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
622 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
5808
026367992a0f
mod_muc: Support for locking newly-created rooms until they are configured (enabled with muc_room_locking = true)
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
623 end |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
624 return true; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
625 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
626 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
627 -- Removes everyone from the room |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
628 function room_mt:clear(x) |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
629 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
|
630 local occupants_updated = {}; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
631 for nick, occupant in self:each_occupant() do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
632 occupant.role = nil; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
633 self:save_occupant(occupant); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
634 occupants_updated[occupant] = true; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
635 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
636 for occupant in pairs(occupants_updated) do |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
637 self:publicise_occupant_status(occupant, x); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
638 module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; }); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
639 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
640 end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
641 |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
642 function room_mt:destroy(newjid, reason, password) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
643 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
|
644 :tag("item", { affiliation='none', role='none' }):up() |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
645 :tag("destroy", {jid=newjid}); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
646 if reason then x:tag("reason"):text(reason):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
647 if password then x:tag("password"):text(password):up(); end |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
648 x:up(); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
649 self:clear(x); |
5577
8b09b0d068d4
mod_muc: Fire muc-room-created and muc-room-destroyed events (thanks nik)
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
650 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
|
651 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
652 |
6101
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
653 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
|
654 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
|
655 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
656 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
657 |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
658 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
|
659 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
|
660 return true; |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
661 end |
a861dc18e08d
plugins/muc/muc.lib: Add disco iq handlers with compatible argument signature
daurnimator <quae@daurnimator.com>
parents:
6100
diff
changeset
|
662 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
670 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
671 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
679 local actor = stanza.attr.from; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 else |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
687 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
|
688 end |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
689 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
|
690 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
|
691 return true; |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
692 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
693 |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6140
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
707 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
708 origin.send(reply); |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
709 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
710 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
711 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
|
712 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
713 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
714 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
|
715 local role = self:get_role(self:get_occupant_jid(actor)) or self:get_default_role(affiliation); |
6219
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
716 if valid_roles[role or "none"] >= valid_roles.moderator then |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
717 if _rol == "none" then _rol = nil; end |
6219
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
718 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
719 -- TODO: whois check here? (though fully anonymous rooms are not supported) |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
720 for occupant_jid, occupant in self:each_occupant() do |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
721 if occupant.role == _rol then |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
722 local nick = select(3,jid_split(occupant_jid)); |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
723 self:build_item_list(occupant, reply, false, nick); |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
724 end |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
725 end |
a90159cfa530
plugins/muc/muc.lib: Fix getting a list of occupants by role (it was sending presences instead of items inside an iq)
daurnimator <quae@daurnimator.com>
parents:
6218
diff
changeset
|
726 origin.send(reply:up()); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
727 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
728 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
729 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
|
730 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
731 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
732 else |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
733 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
|
734 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
735 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
736 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
737 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
738 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
|
739 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
|
740 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
|
741 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
742 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
743 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
744 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
|
745 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
746 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
747 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
|
748 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
|
749 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
|
750 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
751 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
752 |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
753 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
|
754 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
|
755 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
|
756 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
757 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
|
758 local newjid = child.attr.jid; |
6112
819e00a86239
plugins/muc/muc.lib: Use more modern stanza methods
daurnimator <quae@daurnimator.com>
parents:
6111
diff
changeset
|
759 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
|
760 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
|
761 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
|
762 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
|
763 return true; |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
764 elseif child.name == "x" and child.attr.xmlns == "jabber:x:data" then |
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
765 return self:process_form(origin, stanza); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
766 else |
6202
64ed7f538f81
plugins/muc/muc.lib: Refactor out process_form into hooks
daurnimator <quae@daurnimator.com>
parents:
6201
diff
changeset
|
767 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
6095
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
768 return true; |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
769 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
770 end |
7900ebc544ce
plugins/muc/muc.lib: Split out the room iq handler into functions
daurnimator <quae@daurnimator.com>
parents:
6094
diff
changeset
|
771 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
772 function room_mt:handle_groupchat_to_room(origin, stanza) |
6223
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
773 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
774 -- e.g. body will be ignored; even if the subject change was not allowed |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
775 if stanza:get_child("subject") then |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
776 return module:fire_event("muc-subject-change", {room = self, origin = origin, stanza = stanza}); |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
777 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
|
778 local from = stanza.attr.from; |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
779 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
|
780 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
|
781 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
|
782 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
|
783 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
|
784 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
|
785 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
|
786 end |
6223
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
787 stanza.attr.from = occupant.nick; |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
788 self:broadcast_message(stanza); |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
789 stanza.attr.from = from; |
2a7ce69844ca
plugins/muc/muc.lib: Refactor subject logic; fix bug of mixed up subject/author
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
790 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
|
791 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
792 |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
793 -- 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
|
794 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
|
795 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
|
796 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
|
797 if current_nick then |
1734 | 798 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
|
799 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
|
800 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
|
801 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
|
802 end |
6100
c78ba94d3261
plugins/muc/muc.lib: Move all kick code into one place
daurnimator <quae@daurnimator.com>
parents:
6099
diff
changeset
|
803 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
|
804 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
805 |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
806 -- Need visitor role or higher to invite |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
807 module:hook("muc-pre-invite", function(event) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
808 local room, stanza = event.room, event.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
|
809 local _from, _to = stanza.attr.from, stanza.attr.to; |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
810 local inviter = room:get_occupant_by_real_jid(_from); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
811 local role = inviter and inviter.role or room:get_default_role(room:get_affiliation(_from)); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
812 if valid_roles[role or "none"] <= valid_roles.visitor then |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
813 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); |
6103
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
814 return true; |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
815 end |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
816 end); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
817 |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
818 function room_mt:handle_mediated_invite(origin, stanza) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
819 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
820 local invitee = jid_prep(payload.attr.to); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
821 if not invitee then |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
822 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
|
823 return true; |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
824 elseif not module:fire_event("muc-pre-invite", {room = self, origin = origin, stanza = stanza}) then |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
825 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
|
826 end |
6195
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
827 local invite = st.message({from = self.jid, to = invitee, id = stanza.attr.id}) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
828 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
829 :tag('invite', {from = stanza.attr.from;}) |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
830 :tag('reason'):text(payload:get_child_text("reason")):up() |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
831 :up() |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
832 :up(); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
833 if not module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}) then |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
834 self:route_stanza(invite); |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
835 end |
9f6a003baf2e
plugins/muc/muc.lib: Add pre-invite event. Move role check to it
daurnimator <quae@daurnimator.com>
parents:
6194
diff
changeset
|
836 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
|
837 end |
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
838 |
6194
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
839 -- COMPAT: Some older clients expect this |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
840 module:hook("muc-invite", function(event) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
841 local room, stanza = event.room, event.stanza; |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
842 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
843 local reason = invite:get_child_text("reason"); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
844 stanza:tag('x', {xmlns = "jabber:x:conference"; jid = room.jid;}) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
845 :text(reason or "") |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
846 :up(); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
847 end); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
848 |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
849 -- Add a plain message for clients which don't support invites |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
850 module:hook("muc-invite", function(event) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
851 local room, stanza = event.room, event.stanza; |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
852 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
853 local reason = invite:get_child_text("reason") or ""; |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
854 stanza:tag("body") |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
855 :text(invite.attr.from.." invited you to the room "..room.jid..(reason == "" and (" ("..reason..")") or "")) |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
856 :up(); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
857 end); |
9b6c2d89f143
plugins/muc/muc.lib: Tidy up muc-invite event.
daurnimator <quae@daurnimator.com>
parents:
6193
diff
changeset
|
858 |
6123
7f82bbd249fe
plugins/muc/muc.lib: Remove `payload` argument from `handle_mediated_*`; extract it from inside.
daurnimator <quae@daurnimator.com>
parents:
6122
diff
changeset
|
859 function room_mt:handle_mediated_decline(origin, stanza) |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
860 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
|
861 local declinee = jid_prep(payload.attr.to); |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
862 if not declinee then |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
863 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
864 return true; |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
865 elseif not module:fire_event("muc-pre-decline", {room = self, origin = origin, stanza = stanza}) then |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
866 return true; |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
867 end |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
868 local decline = st.message({from = self.jid, to = declinee, id = stanza.attr.id}) |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
869 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
870 :tag("decline", {from = stanza.attr.from}) |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
871 :tag("reason"):text(payload:get_child_text("reason")):up() |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
872 :up() |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
873 :up(); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
874 if not module:fire_event("muc-decline", {room = self, stanza = decline, origin = origin, incoming = stanza}) then |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
875 local occupant = self:get_occupant_by_real_jid(decline.attr.to); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
876 if occupant then |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
877 self:route_to_occupant(occupant, decline); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
878 else |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
879 self:route_stanza(decline); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
880 end |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
881 end |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
882 return true; |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
883 end |
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
884 |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
885 -- Add a plain message for clients which don't support declines |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
886 module:hook("muc-decline", function(event) |
6196
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
887 local room, stanza = event.room, event.stanza; |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
888 local decline = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline"); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
889 local reason = decline:get_child_text("reason") or ""; |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
890 stanza:tag("body") |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
891 :text(decline.attr.from.." declined your invite to the room "..room.jid..(reason == "" and (" ("..reason..")") or "")) |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
892 :up(); |
e73bb1568d87
plugins/muc/muc.lib: Update declines to be more like invites
daurnimator <quae@daurnimator.com>
parents:
6195
diff
changeset
|
893 end); |
6131
8dd0c6145603
plugins/muc/muc.lib: Add decline event for parity with invite
daurnimator <quae@daurnimator.com>
parents:
6130
diff
changeset
|
894 |
6093
9a7eaf0a35b6
plugins/muc/muc.lib: Split up `handle_to_room` into smaller handlers (thanks sysko)
daurnimator <quae@daurnimator.com>
parents:
6092
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 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
|
901 elseif type == nil then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
902 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
|
903 if x then |
25ba4e2b31b3
plugins/muc/muc: Check for mediated invites in a smarter way
daurnimator <quae@daurnimator.com>
parents:
6102
diff
changeset
|
904 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
|
905 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
|
906 -- 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
|
907 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
|
908 return self:handle_mediated_invite(origin, stanza) |
6105
68f53b9a186e
plugins/muc/muc: Support mediated declines
daurnimator <quae@daurnimator.com>
parents:
6104
diff
changeset
|
909 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
|
910 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
|
911 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
|
912 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
|
913 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
|
914 end |
1734 | 915 end |
916 end | |
917 | |
6111
f8b94903be52
plugins/muc: Provide a reasonable default `route_stanza`
daurnimator <quae@daurnimator.com>
parents:
6108
diff
changeset
|
918 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
|
919 module:send(stanza); |
6111
f8b94903be52
plugins/muc: Provide a reasonable default `route_stanza`
daurnimator <quae@daurnimator.com>
parents:
6108
diff
changeset
|
920 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
921 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
922 function room_mt:get_affiliation(jid) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
923 local node, host, resource = jid_split(jid); |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
924 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
|
925 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
|
926 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
|
927 return result; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
928 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
929 |
6181
6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6180
diff
changeset
|
930 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
|
931 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
|
932 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
933 jid = jid_bare(jid); |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
934 |
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
935 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
|
936 return nil, "modify", "not-acceptable"; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
937 end |
6186
85f7cd91dc31
plugins/muc/muc.lib: Smarter validation in set_affiliation
daurnimator <quae@daurnimator.com>
parents:
6185
diff
changeset
|
938 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
|
939 |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
940 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
|
941 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
|
942 |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
943 if actor ~= true then |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
944 local actor_bare = jid_bare(actor); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
945 local actor_affiliation = self._affiliations[actor_bare]; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
946 if actor_affiliation == "owner" then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
947 if actor_bare == jid then -- self change |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
948 -- need at least one owner |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
949 local is_last = true; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
950 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
|
951 if is_last then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
952 return nil, "cancel", "conflict"; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
953 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
954 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
955 -- owners can do anything else |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
956 elseif affiliation == "owner" or affiliation == "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
957 or actor_affiliation ~= "admin" |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
958 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
|
959 -- Can't demote owners or other admins |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
960 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
|
961 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
962 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
963 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
964 -- Set in 'database' |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
965 self._affiliations[jid] = affiliation; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
966 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
967 -- Update roles |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
968 local role = self:get_default_role(affiliation); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
969 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
|
970 local occupants_updated = {}; -- Filled with old roles |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
971 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
|
972 if occupant.bare_jid == jid then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
973 -- 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
|
974 occupants_updated[occupant] = occupant.role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
975 if occupant.role ~= role and ( |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
976 is_downgrade or |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
977 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
|
978 ) then |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
979 occupant.role = role; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
980 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
|
981 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
|
982 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
|
983 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
984 |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
985 -- Tell the room of the new occupant affiliations+roles |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
986 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
|
987 if not role then -- getting kicked |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
988 if affiliation == "outcast" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
989 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
|
990 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
991 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
|
992 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
993 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
994 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
|
995 for occupant, old_role in pairs(occupants_updated) do |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
996 self:publicise_occupant_status(occupant, x, nil, actor, reason); |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
997 if is_semi_anonymous and |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
998 (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
|
999 (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
|
1000 -- 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
|
1001 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
|
1002 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
|
1003 return occupant.bare_jid ~= jid; |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1004 end); |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1005 end |
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1006 end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1007 end |
6187
c0b4b5d41e55
plugins/muc/muc.lib: Improve set affiliation logic;
daurnimator <quae@daurnimator.com>
parents:
6186
diff
changeset
|
1008 |
1755
1614e8e62ad5
MUC: Fixed an undefined global access.
Waqas Hussain <waqas20@gmail.com>
parents:
1754
diff
changeset
|
1009 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
|
1010 return true; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1011 end |
1734 | 1012 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1013 function room_mt:get_role(nick) |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1014 local occupant = self:get_occupant_by_nick(nick); |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1015 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
|
1016 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1017 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1018 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
|
1019 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
|
1020 |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1021 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
|
1022 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
|
1023 |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1024 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
|
1025 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
|
1026 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1027 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
|
1028 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1029 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
|
1030 -- 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
|
1031 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
|
1032 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
|
1033 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
|
1034 end |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1035 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1036 -- 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
|
1037 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
|
1038 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
|
1039 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
|
1040 return nil, "cancel", "not-allowed"; |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1041 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1042 end |
6182
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1043 |
dbf0b09664cd
plugins/muc/muc.lib: Clean up :set_role. Removes :can_set_role
daurnimator <quae@daurnimator.com>
parents:
6181
diff
changeset
|
1044 -- 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
|
1045 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
|
1046 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
|
1047 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
|
1048 end |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1049 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1050 |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1055 occupant.role = role; |
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6143
diff
changeset
|
1056 self:save_occupant(occupant); |
6212
b82523f92b06
plugins/muc/muc.lib: Refactor of change-nick presence handling
daurnimator <quae@daurnimator.com>
parents:
6211
diff
changeset
|
1057 self:publicise_occupant_status(occupant, x, nil, actor, reason); |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1058 return true; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1059 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1060 |
6209
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6208
diff
changeset
|
1061 local name = module:require "muc/name"; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6208
diff
changeset
|
1062 room_mt.get_name = name.get; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6208
diff
changeset
|
1063 room_mt.set_name = name.set; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6208
diff
changeset
|
1064 |
6204
c3254827698d
plugins/muc/muc.lib: Move description functions out to own file
daurnimator <quae@daurnimator.com>
parents:
6203
diff
changeset
|
1065 local description = module:require "muc/description"; |
c3254827698d
plugins/muc/muc.lib: Move description functions out to own file
daurnimator <quae@daurnimator.com>
parents:
6203
diff
changeset
|
1066 room_mt.get_description = description.get; |
c3254827698d
plugins/muc/muc.lib: Move description functions out to own file
daurnimator <quae@daurnimator.com>
parents:
6203
diff
changeset
|
1067 room_mt.set_description = description.set; |
c3254827698d
plugins/muc/muc.lib: Move description functions out to own file
daurnimator <quae@daurnimator.com>
parents:
6203
diff
changeset
|
1068 |
6225
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1069 local hidden = module:require "muc/hidden"; |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1070 room_mt.get_hidden = hidden.get; |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1071 room_mt.set_hidden = hidden.set; |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1072 function room_mt:get_public() |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1073 return not self:get_hidden(); |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1074 end |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1075 function room_mt:set_public(public) |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1076 return self:set_hidden(not public); |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1077 end |
12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
daurnimator <quae@daurnimator.com>
parents:
6224
diff
changeset
|
1078 |
6208
d724289a5226
plugins/muc: Move password functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6206
diff
changeset
|
1079 local password = module:require "muc/password"; |
d724289a5226
plugins/muc: Move password functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6206
diff
changeset
|
1080 room_mt.get_password = password.get; |
d724289a5226
plugins/muc: Move password functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6206
diff
changeset
|
1081 room_mt.set_password = password.set; |
d724289a5226
plugins/muc: Move password functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
6206
diff
changeset
|
1082 |
6214
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1083 local whois = module:require "muc/whois"; |
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1084 room_mt.get_whois = whois.get; |
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1085 room_mt.set_whois = whois.set; |
9813c74ce006
plugins/muc: Move `whois` code to seperate file
daurnimator <quae@daurnimator.com>
parents:
6213
diff
changeset
|
1086 |
6221
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
6220
diff
changeset
|
1087 local members_only = module:require "muc/members_only"; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
6220
diff
changeset
|
1088 room_mt.get_members_only = members_only.get; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
6220
diff
changeset
|
1089 room_mt.set_members_only = members_only.set; |
f321536afeec
plugins/muc/muc.lib: Move members_only into seperate file
daurnimator <quae@daurnimator.com>
parents:
6220
diff
changeset
|
1090 |
6226
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
1091 local moderated = module:require "muc/moderated"; |
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
1092 room_mt.get_moderated = moderated.get; |
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
1093 room_mt.set_moderated = moderated.set; |
7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
6225
diff
changeset
|
1094 |
6222
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
1095 local persistent = module:require "muc/persistent"; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
1096 room_mt.get_persistent = persistent.get; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
1097 room_mt.set_persistent = persistent.set; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
6221
diff
changeset
|
1098 |
6224
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1099 local subject = module:require "muc/subject"; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1100 room_mt.get_changesubject = subject.get_changesubject; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1101 room_mt.set_changesubject = subject.set_changesubject; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1102 room_mt.get_subject = subject.get; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1103 room_mt.set_subject = subject.set; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1104 room_mt.send_subject = subject.send; |
2a9aff163545
plugins/muc: Move subject code to seperate module
daurnimator <quae@daurnimator.com>
parents:
6223
diff
changeset
|
1105 |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1106 local history = module:require "muc/history"; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1107 room_mt.send_history = history.send; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1108 room_mt.get_historylength = history.get_length; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1109 room_mt.set_historylength = history.set_length; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1110 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1111 local _M = {}; -- module "muc" |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1112 |
6215
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1113 _M.set_max_history_length = history.set_max_length; |
1dd09dc04945
plugins/muc: Move history to an external module
daurnimator <quae@daurnimator.com>
parents:
6214
diff
changeset
|
1114 |
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
|
1115 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
|
1116 return setmetatable({ |
1734 | 1117 jid = jid; |
1118 _jid_nick = {}; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
1119 _occupants = {}; |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1120 _data = { |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1121 }; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1122 _affiliations = {}; |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1123 }, room_mt); |
1734 | 1124 end |
1125 | |
5063
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1126 _M.room_mt = room_mt; |
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1127 |
1734 | 1128 return _M; |