diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-01-29 15:13:06 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-01-29 15:13:06 +0000 |
commit | a24c95d2c90c47339ae396cf7ae5132769269f14 (patch) | |
tree | f667d12d984a6114d94554a88f9f7e3caadf90aa | |
parent | 71a08805224b3693573fade6b1f2c1f6d71bef6d (diff) | |
download | prosody-a24c95d2c90c47339ae396cf7ae5132769269f14.tar.gz prosody-a24c95d2c90c47339ae396cf7ae5132769269f14.zip |
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
-rw-r--r-- | plugins/muc/muc.lib.lua | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 103227f0..0544cfe3 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -188,6 +188,16 @@ function room_mt:set_subject(current_nick, subject) return true; end +local function build_unavailable_presence_from_error(stanza) + local type, condition, text = stanza:get_error(); + local error_message = "Kicked: "..condition:gsub("%-", " "); + if text then + error_message = error_message..": "..text; + end + return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) + :tag('status'):text(error_message); +end + function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc local from, to = stanza.attr.from, stanza.attr.to; local room = jid_bare(to); @@ -200,14 +210,8 @@ function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc pr.attr.from = current_nick; if type == "error" then -- error, kick em out! if current_nick then - local type, condition, text = stanza:get_error(); - local error_message = "Kicked: "..condition:gsub("%-", " "); - if text then - error_message = error_message..": "..text; - end - log("debug", "kicking %s from %s for %s", current_nick, room, condition); - self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) - :tag('status'):text(error_message)); -- send unavailable + log("debug", "kicking %s from %s", current_nick, room); + self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); end elseif type == "unavailable" then -- unavailable if current_nick then @@ -354,8 +358,7 @@ function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc origin.send(st.error_reply(stanza, "modify", "bad-request")); elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); - self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) - :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable + self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable else -- private stanza local o_data = self._occupants[to]; if o_data then @@ -614,8 +617,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then local current_nick = self._jid_nick[stanza.attr.from]; log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); - self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) - :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable + self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick local to = stanza.attr.to; local current_nick = self._jid_nick[stanza.attr.from]; |