MUC: Added support for the room-destroy owner use case.
authorWaqas Hussain <waqas20@gmail.com>
Wed, 25 Nov 2009 19:03:16 +0000 (00:03 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Wed, 25 Nov 2009 19:03:16 +0000 (00:03 +0500)
plugins/muc/muc.lib.lua

index 8fd0a0934d0842fb54f4b2b676f5a3d3b80bbb31..002498af371f69157b20471d465240884aaaf107 100644 (file)
@@ -435,6 +435,26 @@ function room_mt:process_form(origin, stanza)
        origin.send(st.reply(stanza));
 end
 
+function room_mt:destroy(newjid, reason, password)
+       local pr = st.presence({type = "unavailable"})
+               :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
+                       :tag("item", { affiliation='none', role='none' }):up()
+                       :tag("destroy", {jid=newjid})
+       if reason then pr:tag("reason"):text(reason):up(); end
+       if password then pr:tag("password"):text(password):up(); end
+       for nick, occupant in pairs(self._occupants) do
+               pr.attr.from = nick;
+               for jid in pairs(occupant.sessions) do
+                       pr.attr.to = jid;
+                       self:_route_stanza(pr);
+                       self._jid_nick[jid] = nil;
+               end
+               self._occupants[nick] = nil;
+       end
+       self._data.persistent = nil;
+       if self.save then self:save(true); end
+end
+
 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc
        local type = stanza.attr.type;
        local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
@@ -515,7 +535,24 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
                        elseif stanza.attr.type == "get" then
                                self:send_form(origin, stanza);
                        elseif stanza.attr.type == "set" then
-                               self:process_form(origin, stanza)
+                               local child = stanza.tags[1].tags[1];
+                               if not child then
+                                       origin.send(st.error_reply(stanza, "auth", "bad-request"));
+                               elseif child.name == "destroy" then
+                                       local newjid = child.attr.jid;
+                                       local reason, password;
+                                       for _,tag in ipairs(child.tags) do
+                                               if tag.name == "reason" then
+                                                       reason = #tag.tags == 0 and tag[1];
+                                               elseif tag.name == "password" then
+                                                       password = #tag.tags == 0 and tag[1];
+                                               end
+                                       end
+                                       self:destroy(newjid, reason, password);
+                                       origin.send(st.reply(stanza));
+                               else
+                                       self:process_form(origin, stanza);
+                               end
                        end
                elseif type == "set" or type == "get" then
                        origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));