Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2529:7968e8b3ecf9
MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 29 Jan 2010 15:13:06 +0000 |
parent | 2528:3365ed0ed5bd |
child | 2540:8c52b023f0b9 |
comparison
equal
deleted
inserted
replaced
2528:3365ed0ed5bd | 2529:7968e8b3ecf9 |
---|---|
186 :tag('subject'):text(subject):up(); | 186 :tag('subject'):text(subject):up(); |
187 self:broadcast_message(msg, false); | 187 self:broadcast_message(msg, false); |
188 return true; | 188 return true; |
189 end | 189 end |
190 | 190 |
191 local function build_unavailable_presence_from_error(stanza) | |
192 local type, condition, text = stanza:get_error(); | |
193 local error_message = "Kicked: "..condition:gsub("%-", " "); | |
194 if text then | |
195 error_message = error_message..": "..text; | |
196 end | |
197 return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) | |
198 :tag('status'):text(error_message); | |
199 end | |
200 | |
191 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc | 201 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc |
192 local from, to = stanza.attr.from, stanza.attr.to; | 202 local from, to = stanza.attr.from, stanza.attr.to; |
193 local room = jid_bare(to); | 203 local room = jid_bare(to); |
194 local current_nick = self._jid_nick[from]; | 204 local current_nick = self._jid_nick[from]; |
195 local type = stanza.attr.type; | 205 local type = stanza.attr.type; |
198 if stanza.name == "presence" then | 208 if stanza.name == "presence" then |
199 local pr = get_filtered_presence(stanza); | 209 local pr = get_filtered_presence(stanza); |
200 pr.attr.from = current_nick; | 210 pr.attr.from = current_nick; |
201 if type == "error" then -- error, kick em out! | 211 if type == "error" then -- error, kick em out! |
202 if current_nick then | 212 if current_nick then |
203 local type, condition, text = stanza:get_error(); | 213 log("debug", "kicking %s from %s", current_nick, room); |
204 local error_message = "Kicked: "..condition:gsub("%-", " "); | 214 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); |
205 if text then | |
206 error_message = error_message..": "..text; | |
207 end | |
208 log("debug", "kicking %s from %s for %s", current_nick, room, condition); | |
209 self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) | |
210 :tag('status'):text(error_message)); -- send unavailable | |
211 end | 215 end |
212 elseif type == "unavailable" then -- unavailable | 216 elseif type == "unavailable" then -- unavailable |
213 if current_nick then | 217 if current_nick then |
214 log("debug", "%s leaving %s", current_nick, room); | 218 log("debug", "%s leaving %s", current_nick, room); |
215 local occupant = self._occupants[current_nick]; | 219 local occupant = self._occupants[current_nick]; |
352 end | 356 end |
353 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM | 357 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM |
354 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 358 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
355 elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then | 359 elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
356 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); | 360 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
357 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) | 361 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable |
358 :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable | |
359 else -- private stanza | 362 else -- private stanza |
360 local o_data = self._occupants[to]; | 363 local o_data = self._occupants[to]; |
361 if o_data then | 364 if o_data then |
362 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); | 365 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); |
363 local jid = o_data.jid; | 366 local jid = o_data.jid; |
612 stanza.attr.from = from; | 615 stanza.attr.from = from; |
613 end | 616 end |
614 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then | 617 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
615 local current_nick = self._jid_nick[stanza.attr.from]; | 618 local current_nick = self._jid_nick[stanza.attr.from]; |
616 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); | 619 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
617 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) | 620 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable |
618 :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable | |
619 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick | 621 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick |
620 local to = stanza.attr.to; | 622 local to = stanza.attr.to; |
621 local current_nick = self._jid_nick[stanza.attr.from]; | 623 local current_nick = self._jid_nick[stanza.attr.from]; |
622 if current_nick then | 624 if current_nick then |
623 stanza.attr.to = current_nick; | 625 stanza.attr.to = current_nick; |