Comparison

plugins/muc/muc.lib.lua @ 12010:f995d62044fa

MUC: Allow modules a chance to act prior to room destruction
author Kim Alvefur <zash@zash.se>
date Sun, 05 Dec 2021 14:49:06 +0100
parent 11915:e0b58717f0c5
child 12026:f3b09b8445b3
comparison
equal deleted inserted replaced
12009:f6fff0658108 12010:f995d62044fa
1016 }); 1016 });
1017 end 1017 end
1018 end 1018 end
1019 1019
1020 function room_mt:destroy(newjid, reason, password) 1020 function room_mt:destroy(newjid, reason, password)
1021 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) 1021 local x = st.stanza("x", { xmlns = "http://jabber.org/protocol/muc#user" });
1022 :tag("destroy", {jid=newjid}); 1022 local event = { room = self; newjid = newjid; reason = reason; password = password; x = x, allowed = true };
1023 module:fire_event("muc-pre-room-destroy", event);
1024 if not event.allowed then return false, event.error; end
1025 newjid, reason, password = event.newjid, event.reason, event.password;
1026 x:tag("destroy", { jid = newjid });
1023 if reason then x:tag("reason"):text(reason):up(); end 1027 if reason then x:tag("reason"):text(reason):up(); end
1024 if password then x:tag("password"):text(password):up(); end 1028 if password then x:tag("password"):text(password):up(); end
1025 x:up(); 1029 x:up();
1026 self.destroying = reason or true; 1030 self.destroying = reason or true;
1027 self:clear(x); 1031 self:clear(x);
1170 return true; 1174 return true;
1171 elseif child.name == "destroy" then 1175 elseif child.name == "destroy" then
1172 local newjid = child.attr.jid; 1176 local newjid = child.attr.jid;
1173 local reason = child:get_child_text("reason"); 1177 local reason = child:get_child_text("reason");
1174 local password = child:get_child_text("password"); 1178 local password = child:get_child_text("password");
1175 self:destroy(newjid, reason, password); 1179 local destroyed, err = self:destroy(newjid, reason, password);
1176 origin.send(st.reply(stanza)); 1180 if destroyed then
1181 origin.send(st.reply(stanza));
1182 else
1183 origin.send(st.error_reply(stanza, err or "cancel", "not-allowed"));
1184 end
1177 return true; 1185 return true;
1178 elseif child.name == "x" and child.attr.xmlns == "jabber:x:data" then 1186 elseif child.name == "x" and child.attr.xmlns == "jabber:x:data" then
1179 return self:process_form(origin, stanza); 1187 return self:process_form(origin, stanza);
1180 else 1188 else
1181 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 1189 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));