Software /
code /
prosody
Annotate
plugins/muc/muc.lib.lua @ 5613:f3166adab512
mod_muc: Remove unused variable
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 21 May 2013 10:10:09 +0100 |
parent | 5612:5404832d6f7a |
child | 5614:2a3341e7ed32 |
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 |
1734 | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | |
6 -- COPYING file in the source package for more information. | |
7 -- | |
8 | |
3281
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
9 local select = select; |
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
10 local pairs, ipairs = pairs, ipairs; |
fd6ab269ecc2
MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents:
3280
diff
changeset
|
11 |
1734 | 12 local datetime = require "util.datetime"; |
13 | |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
14 local dataform = require "util.dataforms"; |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
15 |
1734 | 16 local jid_split = require "util.jid".split; |
17 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
|
18 local jid_prep = require "util.jid".prep; |
1734 | 19 local st = require "util.stanza"; |
20 local log = require "util.logger".init("mod_muc"); | |
21 local t_insert, t_remove = table.insert, table.remove; | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
22 local setmetatable = setmetatable; |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
23 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
|
24 local md5 = require "util.hashes".md5; |
1734 | 25 |
26 local muc_domain = nil; --module:get_host(); | |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
27 local default_history_length, max_history_length = 20, math.huge; |
1734 | 28 |
29 ------------ | |
5612
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
30 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; |
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
31 local function presence_filter(tag) |
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
32 if presence_filters[tag.attr.xmlns] then |
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
33 return nil; |
1734 | 34 end |
5612
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
35 return tag; |
1734 | 36 end |
5612
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
37 |
1734 | 38 local function get_filtered_presence(stanza) |
5612
5404832d6f7a
mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5611
diff
changeset
|
39 return st.clone(stanza):maptags(presence_filter); |
1734 | 40 end |
41 local kickable_error_conditions = { | |
42 ["gone"] = true; | |
43 ["internal-server-error"] = true; | |
44 ["item-not-found"] = true; | |
45 ["jid-malformed"] = true; | |
46 ["recipient-unavailable"] = true; | |
47 ["redirect"] = true; | |
48 ["remote-server-not-found"] = true; | |
49 ["remote-server-timeout"] = true; | |
50 ["service-unavailable"] = true; | |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
51 ["malformed error"] = true; |
1734 | 52 }; |
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
|
53 |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
54 local function get_error_condition(stanza) |
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
|
55 local _, condition = stanza:get_error(); |
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
|
56 return condition or "malformed error"; |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
57 end |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
58 |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
59 local function is_kickable_error(stanza) |
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
60 local cond = get_error_condition(stanza); |
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
61 return kickable_error_conditions[cond] and cond; |
1734 | 62 end |
63 ----------- | |
64 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
65 local room_mt = {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
66 room_mt.__index = room_mt; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
67 |
5519
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
68 function room_mt:__tostring() |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
69 return "MUC room ("..self.jid..")"; |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
70 end |
06e188268df1
MUC: add __tostring on room metatable
Matthew Wild <mwild1@gmail.com>
parents:
5397
diff
changeset
|
71 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
72 function room_mt:get_default_role(affiliation) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
73 if affiliation == "owner" or affiliation == "admin" then |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
74 return "moderator"; |
3251
f2f9fe088f6e
MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3250
diff
changeset
|
75 elseif affiliation == "member" then |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
76 return "participant"; |
3251
f2f9fe088f6e
MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3250
diff
changeset
|
77 elseif not affiliation then |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
78 if not self:get_members_only() then |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
79 return self:get_moderated() and "visitor" or "participant"; |
3255
6bffb5c63131
MUC: Updated room:get_default_role() to not assign unaffiliated occupants a role in members-only rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3254
diff
changeset
|
80 end |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
81 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
82 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
83 |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
84 function room_mt:broadcast_presence(stanza, sid, code, nick) |
1734 | 85 stanza = get_filtered_presence(stanza); |
1825
f67e4bfc62f1
MUC: Renamed a variable name.
Waqas Hussain <waqas20@gmail.com>
parents:
1824
diff
changeset
|
86 local occupant = self._occupants[stanza.attr.from]; |
1734 | 87 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
88 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none", nick=nick}):up(); |
1734 | 89 if code then |
90 stanza:tag("status", {code=code}):up(); | |
91 end | |
1824
8e66c9d09f81
MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents:
1819
diff
changeset
|
92 self:broadcast_except_nick(stanza, stanza.attr.from); |
8e66c9d09f81
MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents:
1819
diff
changeset
|
93 local me = self._occupants[stanza.attr.from]; |
1734 | 94 if me then |
3590
dcc5f3402f5b
MUC: Added a missing :up() to the stanza building for presence broadcast (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3580
diff
changeset
|
95 stanza:tag("status", {code='110'}):up(); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
96 stanza.attr.to = sid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
97 self:_route_stanza(stanza); |
1734 | 98 end |
99 end | |
1736
98f833669d7f
MUC: Fixed function declarations.
Waqas Hussain <waqas20@gmail.com>
parents:
1735
diff
changeset
|
100 function room_mt:broadcast_message(stanza, historic) |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
101 local to = stanza.attr.to; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
102 for occupant, o_data in pairs(self._occupants) do |
1734 | 103 for jid in pairs(o_data.sessions) do |
104 stanza.attr.to = jid; | |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
105 self:_route_stanza(stanza); |
1734 | 106 end |
107 end | |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
108 stanza.attr.to = to; |
1734 | 109 if historic then -- add to history |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
110 local history = self._data['history']; |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
111 if not history then history = {}; self._data['history'] = history; end |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
112 stanza = st.clone(stanza); |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
113 stanza.attr.to = ""; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
114 local stamp = datetime.datetime(); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
115 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203 |
1734 | 116 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
117 local entry = { stanza = stanza, stamp = stamp }; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
118 t_insert(history, entry); |
4874
4e9781a61242
muc.lib: Fix for traceback when no history length is set for the room
Matthew Wild <mwild1@gmail.com>
parents:
4839
diff
changeset
|
119 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end |
1734 | 120 end |
121 end | |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
122 function room_mt:broadcast_except_nick(stanza, nick) |
1751
55ee6e792e3e
MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents:
1750
diff
changeset
|
123 for rnick, occupant in pairs(self._occupants) do |
55ee6e792e3e
MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents:
1750
diff
changeset
|
124 if rnick ~= nick then |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
125 for jid in pairs(occupant.sessions) do |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
126 stanza.attr.to = jid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
127 self:_route_stanza(stanza); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
128 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
129 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
130 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
131 end |
1734 | 132 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
133 function room_mt:send_occupant_list(to) |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
134 local current_nick = self._jid_nick[to]; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
135 for occupant, o_data in pairs(self._occupants) do |
1734 | 136 if occupant ~= current_nick then |
137 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); | |
138 pres.attr.to, pres.attr.from = to, occupant; | |
139 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
140 :tag("item", {affiliation=o_data.affiliation or "none", role=o_data.role or "none"}):up(); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
141 self:_route_stanza(pres); |
1734 | 142 end |
143 end | |
144 end | |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
145 function room_mt:send_history(to, stanza) |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
146 local history = self._data['history']; -- send discussion history |
1734 | 147 if history then |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
148 local x_tag = stanza and stanza:get_child("x", "http://jabber.org/protocol/muc"); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
149 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc"); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
150 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
151 local maxchars = history_tag and tonumber(history_tag.attr.maxchars); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
152 if maxchars then maxchars = math.floor(maxchars); end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
153 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
154 local maxstanzas = math.floor(history_tag and tonumber(history_tag.attr.maxstanzas) or #history); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
155 if not history_tag then maxstanzas = 20; end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
156 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
157 local seconds = history_tag and tonumber(history_tag.attr.seconds); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
158 if seconds then seconds = datetime.datetime(os.time() - math.floor(seconds)); end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
159 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
160 local since = history_tag and history_tag.attr.since; |
3516
de54a7ab7e6e
MUC: fix timezone support when sending history
Kim Alvefur <zash@zash.se>
parents:
3510
diff
changeset
|
161 if since then since = datetime.parse(since); since = since and datetime.datetime(since); end |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
162 if seconds and (not since or since < seconds) then since = seconds; end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
163 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
164 local n = 0; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
165 local charcount = 0; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
166 |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
167 for i=#history,1,-1 do |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
168 local entry = history[i]; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
169 if maxchars then |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
170 if not entry.chars then |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
171 entry.stanza.attr.to = ""; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
172 entry.chars = #tostring(entry.stanza); |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
173 end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
174 charcount = charcount + entry.chars + #to; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
175 if charcount > maxchars then break; end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
176 end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
177 if since and since > entry.stamp then break; end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
178 if n + 1 > maxstanzas then break; end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
179 n = n + 1; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
180 end |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
181 for i=#history-n+1,#history do |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
182 local msg = history[i].stanza; |
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
183 msg.attr.to = to; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
184 self:_route_stanza(msg); |
1734 | 185 end |
186 end | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
187 if self._data['subject'] then |
3393
5b8de0731c4d
MUC: Store the nick (full room JID) which set the subject, and send subject to occupants from that JID.
Waqas Hussain <waqas20@gmail.com>
parents:
3361
diff
changeset
|
188 self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject'])); |
1734 | 189 end |
190 end | |
191 | |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
192 function room_mt:get_disco_info(stanza) |
4266
513485a11b85
MUC: Include occupant count in room disco#info response.
Waqas Hussain <waqas20@gmail.com>
parents:
4202
diff
changeset
|
193 local count = 0; for _ in pairs(self._occupants) do count = count + 1; end |
1808
e164fdb2d18f
MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1778
diff
changeset
|
194 return st.reply(stanza):query("http://jabber.org/protocol/disco#info") |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
195 :tag("identity", {category="conference", type="text", name=self:get_name()}):up() |
3246
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
196 :tag("feature", {var="http://jabber.org/protocol/muc"}):up() |
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
197 :tag("feature", {var=self:get_password() and "muc_passwordprotected" or "muc_unsecured"}):up() |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
198 :tag("feature", {var=self:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
199 :tag("feature", {var=self:get_members_only() and "muc_membersonly" or "muc_open"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
200 :tag("feature", {var=self:get_persistent() and "muc_persistent" or "muc_temporary"}):up() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
201 :tag("feature", {var=self:get_hidden() and "muc_hidden" or "muc_public"}):up() |
3264
e1c787c6f86e
MUC: Added disco#info features to advertise room's anonymity status (muc_semianonymous or muc_nonanonymous).
Waqas Hussain <waqas20@gmail.com>
parents:
3263
diff
changeset
|
202 :tag("feature", {var=self._data.whois ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
203 :add_child(dataform.new({ |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
204 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" }, |
4266
513485a11b85
MUC: Include occupant count in room disco#info response.
Waqas Hussain <waqas20@gmail.com>
parents:
4202
diff
changeset
|
205 { name = "muc#roominfo_description", label = "Description"}, |
513485a11b85
MUC: Include occupant count in room disco#info response.
Waqas Hussain <waqas20@gmail.com>
parents:
4202
diff
changeset
|
206 { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) } |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
207 }):form({["muc#roominfo_description"] = self:get_description()}, 'result')) |
3246
3371419eb0e1
MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents:
3245
diff
changeset
|
208 ; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
209 end |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
210 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
|
211 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
212 for room_jid in pairs(self._occupants) do |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
213 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
|
214 end |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
215 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
216 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
217 function room_mt:set_subject(current_nick, subject) |
1734 | 218 -- TODO check nick's authority |
219 if subject == "" then subject = nil; end | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
220 self._data['subject'] = subject; |
3393
5b8de0731c4d
MUC: Store the nick (full room JID) which set the subject, and send subject to occupants from that JID.
Waqas Hussain <waqas20@gmail.com>
parents:
3361
diff
changeset
|
221 self._data['subject_from'] = current_nick; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
222 if self.save then self:save(); end |
1734 | 223 local msg = st.message({type='groupchat', from=current_nick}) |
224 :tag('subject'):text(subject):up(); | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
225 self:broadcast_message(msg, false); |
1734 | 226 return true; |
227 end | |
228 | |
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
|
229 local function build_unavailable_presence_from_error(stanza) |
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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) |
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
|
236 :tag('status'):text(error_message); |
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
|
237 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
|
238 |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
239 function room_mt:set_name(name) |
3510
711eb5bf94b4
MUC: Make the room node be the default room name (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3509
diff
changeset
|
240 if name == "" or type(name) ~= "string" or name == (jid_split(self.jid)) then name = nil; end |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
241 if self._data.name ~= name then |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
242 self._data.name = name; |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
243 if self.save then self:save(true); end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
244 end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
245 end |
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
246 function room_mt:get_name() |
3510
711eb5bf94b4
MUC: Make the room node be the default room name (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3509
diff
changeset
|
247 return self._data.name or jid_split(self.jid); |
3507
b639042bb0d5
MUC: Added a 'Name' property (muc#roomconfig_roomname)
Kim Alvefur <zash@zash.se>
parents:
3446
diff
changeset
|
248 end |
3508
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
249 function room_mt:set_description(description) |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
250 if description == "" or type(description) ~= "string" then description = nil; end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
251 if self._data.description ~= description then |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
252 self._data.description = description; |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
253 if self.save then self:save(true); end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
254 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
255 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
256 function room_mt:get_description() |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
257 return self._data.description; |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
258 end |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
259 function room_mt:set_password(password) |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
260 if password == "" or type(password) ~= "string" then password = nil; end |
3249
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
261 if self._data.password ~= password then |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
262 self._data.password = password; |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
263 if self.save then self:save(true); end |
95daf6398dbb
MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents:
3248
diff
changeset
|
264 end |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
265 end |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
266 function room_mt:get_password() |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
267 return self._data.password; |
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
268 end |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
269 function room_mt:set_moderated(moderated) |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
270 moderated = moderated and true or nil; |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
271 if self._data.moderated ~= moderated then |
3252
22062c50eabe
MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents:
3251
diff
changeset
|
272 self._data.moderated = moderated; |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
273 if self.save then self:save(true); end |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
274 end |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
275 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
276 function room_mt:get_moderated() |
3250
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
277 return self._data.moderated; |
38402e874b45
MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents:
3249
diff
changeset
|
278 end |
3254
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
279 function room_mt:set_members_only(members_only) |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
280 members_only = members_only and true or nil; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
281 if self._data.members_only ~= members_only then |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
282 self._data.members_only = members_only; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
283 if self.save then self:save(true); end |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
284 end |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
285 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
286 function room_mt:get_members_only() |
3254
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
287 return self._data.members_only; |
a01c6411fdfb
MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents:
3253
diff
changeset
|
288 end |
3258
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
289 function room_mt:set_persistent(persistent) |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
290 persistent = persistent and true or nil; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
291 if self._data.persistent ~= persistent then |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
292 self._data.persistent = persistent; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
293 if self.save then self:save(true); end |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
294 end |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
295 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
296 function room_mt:get_persistent() |
3258
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
297 return self._data.persistent; |
bc07564bec6d
MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents:
3257
diff
changeset
|
298 end |
3261
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
299 function room_mt:set_hidden(hidden) |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
300 hidden = hidden and true or nil; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
301 if self._data.hidden ~= hidden then |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
302 self._data.hidden = hidden; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
303 if self.save then self:save(true); end |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
304 end |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
305 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
306 function room_mt:get_hidden() |
3261
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
307 return self._data.hidden; |
fe1c93296abd
MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents:
3260
diff
changeset
|
308 end |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
309 function room_mt:get_public() |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
310 return not self:get_hidden(); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
311 end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
312 function room_mt:set_public(public) |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
313 return self:set_hidden(not public); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
314 end |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
315 function room_mt:set_changesubject(changesubject) |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
316 changesubject = changesubject and true or nil; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
317 if self._data.changesubject ~= changesubject then |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
318 self._data.changesubject = changesubject; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
319 if self.save then self:save(true); end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
320 end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
321 end |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
322 function room_mt:get_changesubject() |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
323 return self._data.changesubject; |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
324 end |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
325 function room_mt:get_historylength() |
4785
36234dc4b177
mod_muc/muc.lib: Fall back to default_history_length if no length in config
Matthew Wild <mwild1@gmail.com>
parents:
4766
diff
changeset
|
326 return self._data.history_length or default_history_length; |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
327 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
328 function room_mt:set_historylength(length) |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
329 length = math.min(tonumber(length) or default_history_length, max_history_length or math.huge); |
4876
fa41d05ee7ef
muc.lib: room:set_historylength(): Condense code, and don't store length when equal to default
Matthew Wild <mwild1@gmail.com>
parents:
4875
diff
changeset
|
330 if length == default_history_length then |
fa41d05ee7ef
muc.lib: room:set_historylength(): Condense code, and don't store length when equal to default
Matthew Wild <mwild1@gmail.com>
parents:
4875
diff
changeset
|
331 length = nil; |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
332 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
333 self._data.history_length = length; |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
334 end |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
335 |
3244
616a3bb2bad9
MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents:
2985
diff
changeset
|
336 |
5600
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
337 local valid_whois = { moderators = true, anyone = true }; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
338 |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
339 function room_mt:set_whois(whois) |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
340 if valid_whois[whois] and self._data.whois ~= whois then |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
341 self._data.whois = whois; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
342 if self.save then self:save(true); end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
343 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
344 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
345 |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
346 function room_mt:get_whois() |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
347 return self._data.whois; |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
348 end |
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
349 |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
350 local function construct_stanza_id(room, stanza) |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
351 local from_jid, to_nick = stanza.attr.from, stanza.attr.to; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
352 local from_nick = room._jid_nick[from_jid]; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
353 local occupant = room._occupants[to_nick]; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
354 local to_jid = occupant.jid; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
355 |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
356 return from_nick, to_jid, base64.encode(to_jid.."\0"..stanza.attr.id.."\0"..md5(from_jid)); |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
357 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
358 local function deconstruct_stanza_id(room, stanza) |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
359 local from_jid_possiblybare, to_nick = stanza.attr.from, stanza.attr.to; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
360 local from_jid, id, to_jid_hash = (base64.decode(stanza.attr.id) or ""):match("^(.+)%z(.*)%z(.+)$"); |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
361 local from_nick = room._jid_nick[from_jid]; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
362 |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
363 if not(from_nick) then return; end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
364 if not(from_jid_possiblybare == from_jid or from_jid_possiblybare == jid_bare(from_jid)) then return; end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
365 |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
366 local occupant = room._occupants[to_nick]; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
367 for to_jid in pairs(occupant and occupant.sessions or {}) do |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
368 if md5(to_jid) == to_jid_hash then |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
369 return from_nick, to_jid, id; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
370 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
371 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
372 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
373 |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
374 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
375 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc |
1734 | 376 local from, to = stanza.attr.from, stanza.attr.to; |
377 local room = jid_bare(to); | |
378 local current_nick = self._jid_nick[from]; | |
379 local type = stanza.attr.type; | |
380 log("debug", "room: %s, current_nick: %s, stanza: %s", room or "nil", current_nick or "nil", stanza:top_tag()); | |
381 if (select(2, jid_split(from)) == muc_domain) then error("Presence from the MUC itself!!!"); end | |
382 if stanza.name == "presence" then | |
383 local pr = get_filtered_presence(stanza); | |
384 pr.attr.from = current_nick; | |
385 if type == "error" then -- error, kick em out! | |
386 if current_nick then | |
387 log("debug", "kicking %s from %s", current_nick, room); | |
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
|
388 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); |
1734 | 389 end |
390 elseif type == "unavailable" then -- unavailable | |
391 if current_nick then | |
392 log("debug", "%s leaving %s", current_nick, room); | |
4424
1cbf3744300c
MUC: Fix a possible stack overflow (when a local component joins a room, then disconnects, an unavailble-error presence cycle can occur).
Waqas Hussain <waqas20@gmail.com>
parents:
4357
diff
changeset
|
393 self._jid_nick[from] = nil; |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
394 local occupant = self._occupants[current_nick]; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
395 local new_jid = next(occupant.sessions); |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
396 if new_jid == from then new_jid = next(occupant.sessions, new_jid); end |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
397 if new_jid then |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
398 local jid = occupant.jid; |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
399 occupant.jid = new_jid; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
400 occupant.sessions[from] = nil; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
401 pr.attr.to = from; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
402 pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
403 :tag("item", {affiliation=occupant.affiliation or "none", role='none'}):up() |
3989
84792db89336
MUC: Fix a pair of missing :up()
Kim Alvefur <zash@zash.se>
parents:
3632
diff
changeset
|
404 :tag("status", {code='110'}):up(); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
405 self:_route_stanza(pr); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
406 if jid ~= new_jid then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
407 pr = st.clone(occupant.sessions[new_jid]) |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
408 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
409 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none"}); |
2051
2567f4bf0085
MUC: Fixed an issue with multi-session nicks where the 'from' attribute in a presence broadcast was not being properly set.
Waqas Hussain <waqas20@gmail.com>
parents:
2035
diff
changeset
|
410 pr.attr.from = current_nick; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
411 self:broadcast_except_nick(pr, current_nick); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
412 end |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
413 else |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
414 occupant.role = 'none'; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
415 self:broadcast_presence(pr, from); |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
416 self._occupants[current_nick] = nil; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
417 end |
1734 | 418 end |
419 elseif not type then -- available | |
420 if current_nick then | |
421 --if #pr == #stanza or current_nick ~= to then -- commented because google keeps resending directed presence | |
422 if current_nick == to then -- simple presence | |
423 log("debug", "%s broadcasted presence", current_nick); | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
424 self._occupants[current_nick].sessions[from] = pr; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
425 self:broadcast_presence(pr, from); |
1734 | 426 else -- change nick |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
427 local occupant = self._occupants[current_nick]; |
2008
6b6b924ee558
MUC: Re-enable nick changes for non-multisession nicks.
Waqas Hussain <waqas20@gmail.com>
parents:
2006
diff
changeset
|
428 local is_multisession = next(occupant.sessions, next(occupant.sessions)); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
429 if self._occupants[to] or is_multisession then |
1734 | 430 log("debug", "%s couldn't change nick", current_nick); |
1818
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
431 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
432 reply.tags[1].attr.code = "409"; |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
433 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 434 else |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
435 local data = self._occupants[current_nick]; |
1734 | 436 local to_nick = select(3, jid_split(to)); |
437 if to_nick then | |
438 log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to); | |
439 local p = st.presence({type='unavailable', from=current_nick}); | |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
440 self:broadcast_presence(p, from, '303', to_nick); |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
441 self._occupants[current_nick] = nil; |
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
442 self._occupants[to] = data; |
1734 | 443 self._jid_nick[from] = to; |
444 pr.attr.from = to; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
445 self._occupants[to].sessions[from] = pr; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
446 self:broadcast_presence(pr, from); |
1734 | 447 else |
448 --TODO malformed-jid | |
449 end | |
450 end | |
451 end | |
452 --else -- possible rejoin | |
453 -- log("debug", "%s had connection replaced", current_nick); | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
454 -- self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
455 -- :tag('status'):text('Replaced by new connection'):up()); -- send unavailable |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
456 -- self:handle_to_occupant(origin, stanza); -- resend available |
1734 | 457 --end |
458 else -- enter room | |
459 local new_nick = to; | |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
460 local is_merge; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
461 if self._occupants[to] then |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
462 if jid_bare(from) ~= jid_bare(self._occupants[to].jid) then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
463 new_nick = nil; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
464 end |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
465 is_merge = true; |
1734 | 466 end |
3245
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
467 local password = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
468 password = password and password:get_child("password", "http://jabber.org/protocol/muc"); |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
469 password = password and password[1] ~= "" and password[1]; |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
470 if self:get_password() and self:get_password() ~= password then |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
471 log("debug", "%s couldn't join due to invalid password: %s", from, to); |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
472 local reply = st.error_reply(stanza, "auth", "not-authorized"):up(); |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
473 reply.tags[1].attr.code = "401"; |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
474 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
a8a4c87a4fbf
MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents:
3244
diff
changeset
|
475 elseif not new_nick then |
1734 | 476 log("debug", "%s couldn't join due to nick conflict: %s", from, to); |
1818
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
477 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
478 reply.tags[1].attr.code = "409"; |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
479 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 480 else |
481 log("debug", "%s joining as %s", from, to); | |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
482 if not next(self._affiliations) then -- new room, no owners |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
483 self._affiliations[jid_bare(from)] = "owner"; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
484 end |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
485 local affiliation = self:get_affiliation(from); |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
486 local role = self:get_default_role(affiliation) |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
487 if role then -- new occupant |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
488 if not is_merge then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
489 self._occupants[to] = {affiliation=affiliation, role=role, jid=from, sessions={[from]=get_filtered_presence(stanza)}}; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
490 else |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
491 self._occupants[to].sessions[from] = get_filtered_presence(stanza); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
492 end |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
493 self._jid_nick[from] = to; |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
494 self:send_occupant_list(from); |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
495 pr.attr.from = to; |
3593
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
496 pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
497 :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up(); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
498 if not is_merge then |
3593
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
499 self:broadcast_except_nick(pr, to); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
500 end |
3989
84792db89336
MUC: Fix a pair of missing :up()
Kim Alvefur <zash@zash.se>
parents:
3632
diff
changeset
|
501 pr:tag("status", {code='110'}):up(); |
3593
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
502 if self._data.whois == 'anyone' then |
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
503 pr:tag("status", {code='100'}):up(); |
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
504 end |
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
505 pr.attr.to = from; |
58a4af582eb3
MUC: Only send status code 110 (entering non-anonymous room) to the occupant themselves, not to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
3592
diff
changeset
|
506 self:_route_stanza(pr); |
2880
a3f6cc3417f2
MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents:
2658
diff
changeset
|
507 self:send_history(from, stanza); |
3445
2fde9cb97f76
MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents:
3393
diff
changeset
|
508 elseif not affiliation then -- registration required for entering members-only room |
2fde9cb97f76
MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents:
3393
diff
changeset
|
509 local reply = st.error_reply(stanza, "auth", "registration-required"):up(); |
2fde9cb97f76
MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents:
3393
diff
changeset
|
510 reply.tags[1].attr.code = "407"; |
2fde9cb97f76
MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents:
3393
diff
changeset
|
511 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
512 else -- banned |
1819
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
513 local reply = st.error_reply(stanza, "auth", "forbidden"):up(); |
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
514 reply.tags[1].attr.code = "403"; |
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
515 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 516 end |
517 end | |
518 end | |
519 elseif type ~= 'result' then -- bad type | |
1998
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
520 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences |
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
521 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? |
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
522 end |
1734 | 523 end |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
524 elseif not current_nick then -- not in room |
5144
a30507061526
MUC: Fix traceback caused by faulty logic precedence. (thanks waqas, nulani)
Kim Alvefur <zash@zash.se>
parents:
5086
diff
changeset
|
525 if (type == "error" or type == "result") and stanza.name == "iq" then |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
526 local id = stanza.attr.id; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
527 stanza.attr.from, stanza.attr.to, stanza.attr.id = deconstruct_stanza_id(self, stanza); |
5086
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
528 if stanza.attr.id then |
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
529 self:_route_stanza(stanza); |
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
530 end |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
531 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; |
5294
87f07dd0bbfb
MUC: Don't reply to errors (thanks iron)
Kim Alvefur <zash@zash.se>
parents:
5241
diff
changeset
|
532 elseif type ~= "error" then |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
533 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
534 end |
1734 | 535 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM |
536 origin.send(st.error_reply(stanza, "modify", "bad-request")); | |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
537 elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
1996
3e6b36c6d7b7
MUC: Kick occupants on sending error messages to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1989
diff
changeset
|
538 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
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
|
539 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable |
1734 | 540 else -- private stanza |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
541 local o_data = self._occupants[to]; |
1734 | 542 if o_data then |
543 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); | |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
544 if stanza.name == "iq" then |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
545 local id = stanza.attr.id; |
5078
cba0b426b542
MUC: Fix private IQ results and errors for non-vcard queries.
Waqas Hussain <waqas20@gmail.com>
parents:
5063
diff
changeset
|
546 if stanza.attr.type == "get" or stanza.attr.type == "set" then |
cba0b426b542
MUC: Fix private IQ results and errors for non-vcard queries.
Waqas Hussain <waqas20@gmail.com>
parents:
5063
diff
changeset
|
547 stanza.attr.from, stanza.attr.to, stanza.attr.id = construct_stanza_id(self, stanza); |
cba0b426b542
MUC: Fix private IQ results and errors for non-vcard queries.
Waqas Hussain <waqas20@gmail.com>
parents:
5063
diff
changeset
|
548 else |
cba0b426b542
MUC: Fix private IQ results and errors for non-vcard queries.
Waqas Hussain <waqas20@gmail.com>
parents:
5063
diff
changeset
|
549 stanza.attr.from, stanza.attr.to, stanza.attr.id = deconstruct_stanza_id(self, stanza); |
cba0b426b542
MUC: Fix private IQ results and errors for non-vcard queries.
Waqas Hussain <waqas20@gmail.com>
parents:
5063
diff
changeset
|
550 end |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
551 if type == 'get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
552 stanza.attr.to = jid_bare(stanza.attr.to); |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
553 end |
5086
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
554 if stanza.attr.id then |
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
555 self:_route_stanza(stanza); |
1ef9aa0c9fb0
MUC: Fix a traceback caused by private IQ result and error stanzas where the encoded id can't be processed.
Waqas Hussain <waqas20@gmail.com>
parents:
5078
diff
changeset
|
556 end |
5061
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
557 stanza.attr.from, stanza.attr.to, stanza.attr.id = from, to, id; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
558 else -- message |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
559 stanza.attr.from = current_nick; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
560 for jid in pairs(o_data.sessions) do |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
561 stanza.attr.to = jid; |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
562 self:_route_stanza(stanza); |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
563 end |
186f34d88073
MUC: Fix private IQ and message routing.
Waqas Hussain <waqas20@gmail.com>
parents:
4999
diff
changeset
|
564 stanza.attr.from, stanza.attr.to = from, to; |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
565 end |
1734 | 566 elseif type ~= "error" and type ~= "result" then -- recipient not in room |
567 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); | |
568 end | |
569 end | |
570 end | |
571 | |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
572 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
|
573 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
|
574 :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
|
575 ); |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
576 end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
577 |
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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
583 name = 'FORM_TYPE', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
584 type = 'hidden', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
585 value = 'http://jabber.org/protocol/muc#roomconfig' |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
586 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
587 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
588 name = 'muc#roomconfig_roomname', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
589 type = 'text-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
590 label = 'Name', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
591 value = self:get_name() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
592 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
593 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
594 name = 'muc#roomconfig_roomdesc', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
595 type = 'text-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
596 label = 'Description', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
597 value = self:get_description() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
598 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
599 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
600 name = 'muc#roomconfig_persistentroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
601 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
602 label = 'Make Room Persistent?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
603 value = self:get_persistent() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
604 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
605 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
606 name = 'muc#roomconfig_publicroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
607 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
608 label = 'Make Room Publicly Searchable?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
609 value = not self:get_hidden() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
610 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
611 { |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
612 name = 'muc#roomconfig_changesubject', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
613 type = 'boolean', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
614 label = 'Allow Occupants to Change Subject?', |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
615 value = self:get_changesubject() |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
616 }, |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
617 { |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
618 name = 'muc#roomconfig_whois', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
619 type = 'list-single', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
620 label = 'Who May Discover Real JIDs?', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
621 value = { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
622 { value = 'moderators', label = 'Moderators Only', default = self._data.whois == 'moderators' }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
623 { value = 'anyone', label = 'Anyone', default = self._data.whois == 'anyone' } |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
624 } |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
625 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
626 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
627 name = 'muc#roomconfig_roomsecret', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
628 type = 'text-private', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
629 label = 'Password', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
630 value = self:get_password() or "", |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
631 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
632 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
633 name = 'muc#roomconfig_moderatedroom', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
634 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
635 label = 'Make Room Moderated?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
636 value = self:get_moderated() |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
637 }, |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
638 { |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
639 name = 'muc#roomconfig_membersonly', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
640 type = 'boolean', |
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
641 label = 'Make Room Members-Only?', |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
642 value = self:get_members_only() |
4528
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
643 }, |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
644 { |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
645 name = 'muc#roomconfig_historylength', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
646 type = 'text-single', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
647 label = 'Maximum Number of History Messages Returned by Room', |
875b90d5ce0f
muc - implement per channel history limits
Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
parents:
4424
diff
changeset
|
648 value = tostring(self:get_historylength()) |
3517
530f7de1d265
MUC: Use util.dataforms to generate forms
Kim Alvefur <zash@zash.se>
parents:
3516
diff
changeset
|
649 } |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
650 }); |
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
|
651 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
|
652 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
653 |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
654 function room_mt:process_form(origin, stanza) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
655 local query = stanza.tags[1]; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
656 local form; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
657 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
658 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
659 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
660 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end |
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
661 |
5601
f55ab5fa939f
mod_muc: Pass actor (requesting JID) when generating the config form, and to the muc-config-form event handler
Matthew Wild <mwild1@gmail.com>
parents:
5600
diff
changeset
|
662 local fields = self:get_form_layout(stanza.attr.from):data(form); |
3591
dff4a77ee285
MUC: Parse submitted form with util.dataforms
Kim Alvefur <zash@zash.se>
parents:
3590
diff
changeset
|
663 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); return; end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
664 |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
665 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
666 local changed = {}; |
5541
1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
Matthew Wild <mwild1@gmail.com>
parents:
5519
diff
changeset
|
667 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
668 local function handle_option(name, field, allowed) |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
669 local new = fields[field]; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
670 if new == nil then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
671 if allowed and not allowed[new] then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
672 if new == self["get_"..name](self) then return; end |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
673 changed[name] = true; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
674 self["set_"..name](self, new); |
3508
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
675 end |
9e4c2b048f9a
MUC: Added a 'Description' property (muc#roomconfig_roomdesc)
Kim Alvefur <zash@zash.se>
parents:
3507
diff
changeset
|
676 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
677 local event = { room = self, fields = fields, changed = changed, stanza = stanza, origin = origin, update_option = handle_option }; |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
678 module:fire_event("muc-config-submitted", event); |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
679 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
680 handle_option("name", "muc#roomconfig_roomname"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
681 handle_option("description", "muc#roomconfig_roomdesc"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
682 handle_option("persistent", "muc#roomconfig_persistentroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
683 handle_option("moderated", "muc#roomconfig_moderatedroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
684 handle_option("members_only", "muc#roomconfig_membersonly"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
685 handle_option("public", "muc#roomconfig_publicroom"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
686 handle_option("changesubject", "muc#roomconfig_changesubject"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
687 handle_option("historylength", "muc#roomconfig_historylength"); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
688 handle_option("whois", "muc#roomconfig_whois", valid_whois); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
689 handle_option("password", "muc#roomconfig_roomsecret"); |
3248
f8d14ea3ad0e
MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents:
3247
diff
changeset
|
690 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
691 if self.save then self:save(true); end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
692 origin.send(st.reply(stanza)); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
693 |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
694 if next(changed) then |
3592
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
695 local msg = st.message({type='groupchat', from=self.jid}) |
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
696 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up() |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
697 :tag('status', {code = '104'}):up(); |
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
698 if changed.whois then |
5600
1b326a1e4da6
mod_muc: Add getter/setter for 'whois' (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
699 local code = (self:get_whois() == 'moderators') and "173" or "172"; |
3592
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
700 msg.tags[1]:tag('status', {code = code}):up(); |
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
701 end |
3adac5780c5a
MUC: Added some more missing :up()s to the stanza building for presence broadcasts (thanks again Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3591
diff
changeset
|
702 self:broadcast_message(msg, false) |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
703 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
704 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
705 |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
706 function room_mt:destroy(newjid, reason, password) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
707 local pr = st.presence({type = "unavailable"}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
708 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
709 :tag("item", { affiliation='none', role='none' }):up() |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
710 :tag("destroy", {jid=newjid}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
711 if reason then pr:tag("reason"):text(reason):up(); end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
712 if password then pr:tag("password"):text(password):up(); end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
713 for nick, occupant in pairs(self._occupants) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
714 pr.attr.from = nick; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
715 for jid in pairs(occupant.sessions) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
716 pr.attr.to = jid; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
717 self:_route_stanza(pr); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
718 self._jid_nick[jid] = nil; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
719 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
720 self._occupants[nick] = nil; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
721 end |
3259
a5b9209efb23
MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3258
diff
changeset
|
722 self:set_persistent(false); |
5577
8b09b0d068d4
mod_muc: Fire muc-room-created and muc-room-destroyed events (thanks nik)
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
723 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
|
724 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
725 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
726 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc |
1734 | 727 local type = stanza.attr.type; |
1745
15039fac3693
MUC: Some fixes for minor bugs in IQ handling.
Waqas Hussain <waqas20@gmail.com>
parents:
1744
diff
changeset
|
728 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
729 if stanza.name == "iq" then |
5335
bb81c13d2c6f
MUC: Always return <service-unavailable/> when a node is present in service discovery requests.
Waqas Hussain <waqas20@gmail.com>
parents:
5334
diff
changeset
|
730 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" and not stanza.tags[1].attr.node then |
bb81c13d2c6f
MUC: Always return <service-unavailable/> when a node is present in service discovery requests.
Waqas Hussain <waqas20@gmail.com>
parents:
5334
diff
changeset
|
731 origin.send(self:get_disco_info(stanza)); |
bb81c13d2c6f
MUC: Always return <service-unavailable/> when a node is present in service discovery requests.
Waqas Hussain <waqas20@gmail.com>
parents:
5334
diff
changeset
|
732 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" and not stanza.tags[1].attr.node then |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
733 origin.send(self:get_disco_items(stanza)); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
734 elseif xmlns == "http://jabber.org/protocol/muc#admin" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
735 local actor = stanza.attr.from; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
736 local affiliation = self:get_affiliation(actor); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
737 local current_nick = self._jid_nick[actor]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
738 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
739 local item = stanza.tags[1].tags[1]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
740 if item and item.name == "item" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
741 if type == "set" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
742 local callback = function() origin.send(st.reply(stanza)); end |
1862
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
743 if item.attr.jid then -- Validate provided JID |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
744 item.attr.jid = jid_prep(item.attr.jid); |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
745 if not item.attr.jid then |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
746 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
747 return; |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
748 end |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
749 end |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
750 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
751 local occupant = self._occupants[self.jid.."/"..item.attr.nick]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
752 if occupant then item.attr.jid = occupant.jid; end |
2864
1ce0e2ceb419
MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents:
2845
diff
changeset
|
753 elseif not item.attr.nick and item.attr.jid then |
1ce0e2ceb419
MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents:
2845
diff
changeset
|
754 local nick = self._jid_nick[item.attr.jid]; |
1ce0e2ceb419
MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents:
2845
diff
changeset
|
755 if nick then item.attr.nick = select(3, jid_split(nick)); end |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
756 end |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
757 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
758 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
759 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
760 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
761 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
762 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
763 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
764 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
765 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
766 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
767 elseif type == "get" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
768 local _aff = item.attr.affiliation; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
769 local _rol = item.attr.role; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
770 if _aff and not _rol then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
771 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
772 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
773 for jid, affiliation in pairs(self._affiliations) do |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
774 if affiliation == _aff then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
775 reply:tag("item", {affiliation = _aff, jid = jid}):up(); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
776 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
777 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
778 origin.send(reply); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
779 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
780 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
781 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
782 elseif _rol and not _aff then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
783 if role == "moderator" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
784 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
785 if _rol == "none" then _rol = nil; end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
786 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
787 for occupant_jid, occupant in pairs(self._occupants) do |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
788 if occupant.role == _rol then |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
789 reply:tag("item", { |
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
790 nick = select(3, jid_split(occupant_jid)), |
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
791 role = _rol or "none", |
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
792 affiliation = occupant.affiliation or "none", |
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
793 jid = occupant.jid |
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
794 }):up(); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
795 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
796 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
797 origin.send(reply); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
798 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
799 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
800 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
801 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
802 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
803 end |
1744
265863a5612b
MUC: Added support for requesting various lists (owner, admin, voice, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
1743
diff
changeset
|
804 end |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
805 elseif type == "set" or type == "get" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
806 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
807 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
808 elseif xmlns == "http://jabber.org/protocol/muc#owner" and (type == "get" or type == "set") and stanza.tags[1].name == "query" then |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
809 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
4201
9a8d2baf7a9c
MUC: Add a textual error message when the user isn't allowed to get/set config form.
Waqas Hussain <waqas20@gmail.com>
parents:
4119
diff
changeset
|
810 origin.send(st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms")); |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
811 elseif stanza.attr.type == "get" then |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
812 self:send_form(origin, stanza); |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
813 elseif stanza.attr.type == "set" then |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
814 local child = stanza.tags[1].tags[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
815 if not child then |
4326
6c082bf9bf0f
MUC: Change error type of badly-formatted stanza from 'auth' to 'modify' (thanks Andrew)
Matthew Wild <mwild1@gmail.com>
parents:
4266
diff
changeset
|
816 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
817 elseif child.name == "destroy" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
818 local newjid = child.attr.jid; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
819 local reason, password; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
820 for _,tag in ipairs(child.tags) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
821 if tag.name == "reason" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
822 reason = #tag.tags == 0 and tag[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
823 elseif tag.name == "password" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
824 password = #tag.tags == 0 and tag[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
825 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
826 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
827 self:destroy(newjid, reason, password); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
828 origin.send(st.reply(stanza)); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
829 else |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
830 self:process_form(origin, stanza); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
831 end |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
832 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
833 elseif type == "set" or type == "get" then |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
834 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
835 end |
1734 | 836 elseif stanza.name == "message" and type == "groupchat" then |
5613
f3166adab512
mod_muc: Remove unused variable
Matthew Wild <mwild1@gmail.com>
parents:
5612
diff
changeset
|
837 local from = stanza.attr.from; |
1734 | 838 local current_nick = self._jid_nick[from]; |
2173
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
839 local occupant = self._occupants[current_nick]; |
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
840 if not occupant then -- not in room |
1734 | 841 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
2173
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
842 elseif occupant.role == "visitor" then |
4999
d5a3c5c1873c
mod_muc: Fix a couple of cases of 'forbidden' stanza error being sent with type 'cancel' - fixes #303
Matthew Wild <mwild1@gmail.com>
parents:
4876
diff
changeset
|
843 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
1734 | 844 else |
845 local from = stanza.attr.from; | |
846 stanza.attr.from = current_nick; | |
5611
e043d4d65423
mod_muc: Replace getText() with get_child_text(), 1 insertion, 12 deletions!
Matthew Wild <mwild1@gmail.com>
parents:
5601
diff
changeset
|
847 local subject = stanza:get_child_text("subject"); |
1734 | 848 if subject then |
4119
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
849 if occupant.role == "moderator" or |
813adb81d7da
MUC: Add option to allow participants to change the subject.
Kim Alvefur <zash@zash.se>
parents:
3989
diff
changeset
|
850 ( self._data.changesubject and occupant.role == "participant" ) then -- and participant |
2174
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
851 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
852 else |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
853 stanza.attr.from = from; |
4999
d5a3c5c1873c
mod_muc: Fix a couple of cases of 'forbidden' stanza error being sent with type 'cancel' - fixes #303
Matthew Wild <mwild1@gmail.com>
parents:
4876
diff
changeset
|
854 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
2174
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
855 end |
1734 | 856 else |
5397
ed55a48270be
mod_muc/muc.lib: Don't add messages without a body (such as chat state notifications) to the room history (thanks louiz’, Link Mauve, poezio and all its users)
Matthew Wild <mwild1@gmail.com>
parents:
5335
diff
changeset
|
857 self:broadcast_message(stanza, self:get_historylength() > 0 and stanza:get_child("body")); |
1734 | 858 end |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
859 stanza.attr.from = from; |
1734 | 860 end |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
861 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
1768
802c40384dd0
MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1764
diff
changeset
|
862 local current_nick = self._jid_nick[stanza.attr.from]; |
802c40384dd0
MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1764
diff
changeset
|
863 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
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
|
864 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable |
1734 | 865 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick |
866 local to = stanza.attr.to; | |
867 local current_nick = self._jid_nick[stanza.attr.from]; | |
868 if current_nick then | |
869 stanza.attr.to = current_nick; | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
870 self:handle_to_occupant(origin, stanza); |
1734 | 871 stanza.attr.to = to; |
872 elseif type ~= "error" and type ~= "result" then | |
873 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
874 end | |
5241
4516e6bd51b4
MUC: Support invite messages when stanza type is explicitly set to "normal" or to an unknown value.
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
875 elseif stanza.name == "message" and not(type == "chat" or type == "error" or type == "groupchat" or type == "headline") and #stanza.tags == 1 |
4516e6bd51b4
MUC: Support invite messages when stanza type is explicitly set to "normal" or to an unknown value.
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
876 and self._jid_nick[stanza.attr.from] and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then |
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
|
877 local x = stanza.tags[1]; |
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
|
878 local payload = (#x.tags == 1 and x.tags[1]); |
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
|
879 if payload and payload.name == "invite" and payload.attr.to then |
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
|
880 local _from, _to = stanza.attr.from, stanza.attr.to; |
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
|
881 local _invitee = jid_prep(payload.attr.to); |
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
|
882 if _invitee then |
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
|
883 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1]; |
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
|
884 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
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
|
885 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
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
|
886 :tag('invite', {from=_from}) |
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
|
887 :tag('reason'):text(_reason or ""):up() |
3247
ee8aaca3226c
MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3246
diff
changeset
|
888 :up(); |
ee8aaca3226c
MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3246
diff
changeset
|
889 if self:get_password() then |
ee8aaca3226c
MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3246
diff
changeset
|
890 invite:tag("password"):text(self:get_password()):up(); |
ee8aaca3226c
MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3246
diff
changeset
|
891 end |
ee8aaca3226c
MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
3246
diff
changeset
|
892 invite:up() |
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
|
893 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this |
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
|
894 :text(_reason or "") |
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
|
895 :up() |
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
|
896 :tag('body') -- Add a plain message for clients which don't support invites |
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
|
897 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) |
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
|
898 :up(); |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
899 if self:get_members_only() and not self:get_affiliation(_invitee) then |
3611
d58da6bb8a77
MUC: Grant membership when inviteing someone into a members-only room.
Kim Alvefur <zash@zash.se>
parents:
3593
diff
changeset
|
900 log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to); |
d58da6bb8a77
MUC: Grant membership when inviteing someone into a members-only room.
Kim Alvefur <zash@zash.se>
parents:
3593
diff
changeset
|
901 self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. self._jid_nick[_from]) |
d58da6bb8a77
MUC: Grant membership when inviteing someone into a members-only room.
Kim Alvefur <zash@zash.se>
parents:
3593
diff
changeset
|
902 end |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
903 self:_route_stanza(invite); |
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
|
904 else |
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
|
905 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
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
|
906 end |
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
|
907 else |
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
|
908 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
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
|
909 end |
1734 | 910 else |
911 if type == "error" or type == "result" then return; end | |
912 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
913 end | |
914 end | |
915 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
916 function room_mt:handle_stanza(origin, stanza) |
1734 | 917 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
918 if to_resource then | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
919 self:handle_to_occupant(origin, stanza); |
1734 | 920 else |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
921 self:handle_to_room(origin, stanza); |
1734 | 922 end |
923 end | |
924 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
925 function room_mt:route_stanza(stanza) end -- Replace with a routing function, e.g., function(room, stanza) core_route_stanza(origin, stanza); end |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
926 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
927 function room_mt:get_affiliation(jid) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
928 local node, host, resource = jid_split(jid); |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 return result; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
933 end |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
934 function room_mt:set_affiliation(actor, jid, affiliation, callback, reason) |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
935 jid = jid_bare(jid); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
936 if affiliation == "none" then affiliation = nil; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
937 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
938 return nil, "modify", "not-acceptable"; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
939 end |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
940 if actor ~= true then |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
941 local actor_affiliation = self:get_affiliation(actor); |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
942 local target_affiliation = self:get_affiliation(jid); |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
943 if target_affiliation == affiliation then -- no change, shortcut |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
944 if callback then callback(); end |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
945 return true; |
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
|
946 end |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
947 if actor_affiliation ~= "owner" then |
5334
da7857891eb8
MUC: Fix affiliation check for admins, and bring it in line with the spec (thanks Maranda).
Waqas Hussain <waqas20@gmail.com>
parents:
5294
diff
changeset
|
948 if affiliation == "owner" or affiliation == "admin" or actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then |
4357
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
949 return nil, "cancel", "not-allowed"; |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
950 end |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
951 elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
952 local is_last = true; |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
953 for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
954 if is_last then |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
955 return nil, "cancel", "conflict"; |
d6928b78c548
MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
Waqas Hussain <waqas20@gmail.com>
parents:
4326
diff
changeset
|
956 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
|
957 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
|
958 end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
959 self._affiliations[jid] = affiliation; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
960 local role = self:get_default_role(affiliation); |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
961 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
962 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
963 :tag("reason"):text(reason or ""):up() |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
964 :up(); |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
965 local presence_type = nil; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
966 if not role then -- getting kicked |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
967 presence_type = "unavailable"; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
968 if affiliation == "outcast" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
969 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
|
970 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
971 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
|
972 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
973 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
974 local modified_nicks = {}; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
975 for nick, occupant in pairs(self._occupants) do |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
976 if jid_bare(occupant.jid) == jid then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
977 if not role then -- getting kicked |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
978 self._occupants[nick] = nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
979 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
980 occupant.affiliation, occupant.role = affiliation, role; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
981 end |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
982 for jid,pres in pairs(occupant.sessions) do -- remove for all sessions of the nick |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
983 if not role then self._jid_nick[jid] = nil; end |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
984 local p = st.clone(pres); |
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
985 p.attr.from = nick; |
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
986 p.attr.type = presence_type; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
987 p.attr.to = jid; |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
988 p:add_child(x); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
989 self:_route_stanza(p); |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
990 if occupant.jid == jid then |
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
991 modified_nicks[nick] = p; |
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
992 end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
993 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
994 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
995 end |
1755
1614e8e62ad5
MUC: Fixed an undefined global access.
Waqas Hussain <waqas20@gmail.com>
parents:
1754
diff
changeset
|
996 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
|
997 if callback then callback(); end |
3631
138f385e8246
MUC: Include the user's current presence contents when broadcasting an affiliation change.
Waqas Hussain <waqas20@gmail.com>
parents:
3629
diff
changeset
|
998 for nick,p in pairs(modified_nicks) do |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
999 p.attr.from = nick; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1000 self:broadcast_except_nick(p, nick); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1001 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1002 return true; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1003 end |
1734 | 1004 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1005 function room_mt:get_role(nick) |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1006 local session = self._occupants[nick]; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1007 return session and session.role or nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1008 end |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1009 function room_mt:can_set_role(actor_jid, occupant_jid, role) |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1010 local occupant = self._occupants[occupant_jid]; |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1011 if not occupant or not actor then return nil, "modify", "not-acceptable"; end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1012 |
5542
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1013 if actor_jid == true then return true; end |
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1014 |
329ebdfb39a2
MUC: Allow actor == true to set roles (like affiliations)
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
1015 local actor = self._occupants[self._jid_nick[actor_jid]]; |
3279
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1016 if actor.role == "moderator" then |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1017 if occupant.affiliation ~= "owner" and occupant.affiliation ~= "admin" then |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1018 if actor.affiliation == "owner" or actor.affiliation == "admin" then |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1019 return true; |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1020 elseif occupant.role ~= "moderator" and role ~= "moderator" then |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1021 return true; |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1022 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1023 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1024 end |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1025 return nil, "cancel", "not-allowed"; |
8b0a4a7d2c6e
MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3264
diff
changeset
|
1026 end |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
1027 function room_mt:set_role(actor, occupant_jid, role, callback, reason) |
1752
4db786919805
MUC: Added kicking support.
Waqas Hussain <waqas20@gmail.com>
parents:
1751
diff
changeset
|
1028 if role == "none" then role = nil; end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1029 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end |
3280
eef4f31f2d7b
MUC: Updated room:set_role() to use room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3279
diff
changeset
|
1030 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role); |
eef4f31f2d7b
MUC: Updated room:set_role() to use room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents:
3279
diff
changeset
|
1031 if not allowed then return allowed, err_type, err_condition; end |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
1032 local occupant = self._occupants[occupant_jid]; |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1033 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
1034 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"}) |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
1035 :tag("reason"):text(reason or ""):up() |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
1036 :up(); |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1037 local presence_type = nil; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1038 if not role then -- kick |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1039 presence_type = "unavailable"; |
2845
f76139aa7cd5
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents:
2174
diff
changeset
|
1040 self._occupants[occupant_jid] = nil; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1041 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1042 self._jid_nick[jid] = nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1043 end |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1044 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
|
1045 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1046 occupant.role = role; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1047 end |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1048 local bp; |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1049 for jid,pres in pairs(occupant.sessions) do -- send to all sessions of the nick |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1050 local p = st.clone(pres); |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1051 p.attr.from = occupant_jid; |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1052 p.attr.type = presence_type; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1053 p.attr.to = jid; |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1054 p:add_child(x); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1055 self:_route_stanza(p); |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1056 if occupant.jid == jid then |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1057 bp = p; |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1058 end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1059 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
1060 if callback then callback(); end |
3632
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1061 if bp then |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1062 self:broadcast_except_nick(bp, occupant_jid); |
d82189efecc0
MUC: Include the user's current presence contents when broadcasting a role change.
Waqas Hussain <waqas20@gmail.com>
parents:
3631
diff
changeset
|
1063 end |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1064 return true; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1065 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1066 |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1067 function room_mt:_route_stanza(stanza) |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1068 local muc_child; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1069 local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]]; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1070 local from_occupant = self._occupants[stanza.attr.from]; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1071 if stanza.name == "presence" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1072 if to_occupant and from_occupant then |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1073 if self._data.whois == 'anyone' then |
2416
89be536aae25
mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents:
2412
diff
changeset
|
1074 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1075 else |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1076 if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then |
2416
89be536aae25
mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents:
2412
diff
changeset
|
1077 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1078 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1079 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1080 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1081 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1082 if muc_child then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1083 for _, item in pairs(muc_child.tags) do |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1084 if item.name == "item" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1085 if from_occupant == to_occupant then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1086 item.attr.jid = stanza.attr.to; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1087 else |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1088 item.attr.jid = from_occupant.jid; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1089 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1090 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1091 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1092 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1093 self:route_stanza(stanza); |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1094 if muc_child then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1095 for _, item in pairs(muc_child.tags) do |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1096 if item.name == "item" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1097 item.attr.jid = nil; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1098 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1099 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1100 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1101 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
1102 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1103 local _M = {}; -- module "muc" |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1104 |
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
|
1105 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
|
1106 return setmetatable({ |
1734 | 1107 jid = jid; |
1108 _jid_nick = {}; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
1109 _occupants = {}; |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1110 _data = { |
3330
bdc325ce9fbc
MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents:
3281
diff
changeset
|
1111 whois = 'moderators'; |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1112 history_length = math.min((config and config.history_length) |
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1113 or default_history_length, max_history_length); |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
1114 }; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
1115 _affiliations = {}; |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
1116 }, room_mt); |
1734 | 1117 end |
1118 | |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1119 function _M.set_max_history_length(_max_history_length) |
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1120 max_history_length = _max_history_length or math.huge; |
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1121 end |
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5144
diff
changeset
|
1122 |
5063
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1123 _M.room_mt = room_mt; |
4bc202a7b351
MUC: Expose room metatable in the MUC lib.
Waqas Hussain <waqas20@gmail.com>
parents:
5061
diff
changeset
|
1124 |
1734 | 1125 return _M; |