Comparison

plugins/muc/muc.lib.lua @ 6112:819e00a86239

plugins/muc/muc.lib: Use more modern stanza methods
author daurnimator <quae@daurnimator.com>
date Wed, 19 Mar 2014 12:19:44 -0400
parent 6111:f8b94903be52
child 6113:f535f7de44b6
comparison
equal deleted inserted replaced
6111:f8b94903be52 6112:819e00a86239
753 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; 753 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form;
754 end 754 end
755 755
756 function room_mt:process_form(origin, stanza) 756 function room_mt:process_form(origin, stanza)
757 local query = stanza.tags[1]; 757 local query = stanza.tags[1];
758 local form; 758 local form = query:get_child("x", "jabber:x:data")
759 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end
760 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end 759 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end
761 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end 760 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end
762 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end 761 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end
763 762
764 local fields = self:get_form_layout(stanza.attr.from):data(form); 763 local fields = self:get_form_layout(stanza.attr.from):data(form);
856 local nick = self._jid_nick[item.attr.jid]; 855 local nick = self._jid_nick[item.attr.jid];
857 if nick then item.attr.nick = select(3, jid_split(nick)); end 856 if nick then item.attr.nick = select(3, jid_split(nick)); end
858 end 857 end
859 local actor = stanza.attr.from; 858 local actor = stanza.attr.from;
860 local callback = function() origin.send(st.reply(stanza)); end 859 local callback = function() origin.send(st.reply(stanza)); end
861 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; 860 local reason = item:get_child_text("reason");
862 if item.attr.affiliation and item.attr.jid and not item.attr.role then 861 if item.attr.affiliation and item.attr.jid and not item.attr.role then
863 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason); 862 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason);
864 if not success then origin.send(st.error_reply(stanza, errtype, err)); end 863 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
865 return true; 864 return true;
866 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then 865 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
941 if not child then 940 if not child then
942 origin.send(st.error_reply(stanza, "modify", "bad-request")); 941 origin.send(st.error_reply(stanza, "modify", "bad-request"));
943 return true; 942 return true;
944 elseif child.name == "destroy" then 943 elseif child.name == "destroy" then
945 local newjid = child.attr.jid; 944 local newjid = child.attr.jid;
946 local reason, password; 945 local reason = child:get_child_text("reason");
947 for _,tag in ipairs(child.tags) do 946 local password = child:get_child_text("password");
948 if tag.name == "reason" then
949 reason = #tag.tags == 0 and tag[1];
950 elseif tag.name == "password" then
951 password = #tag.tags == 0 and tag[1];
952 end
953 end
954 self:destroy(newjid, reason, password); 947 self:destroy(newjid, reason, password);
955 origin.send(st.reply(stanza)); 948 origin.send(st.reply(stanza));
956 return true; 949 return true;
957 else 950 else
958 self:process_form(origin, stanza); 951 self:process_form(origin, stanza);
1303 end 1296 end
1304 end 1297 end
1305 end 1298 end
1306 end 1299 end
1307 if muc_child then 1300 if muc_child then
1308 for _, item in pairs(muc_child.tags) do 1301 for item in muc_child:childtags("item") do
1309 if item.name == "item" then 1302 if from_occupant == to_occupant then
1310 if from_occupant == to_occupant then 1303 item.attr.jid = stanza.attr.to;
1311 item.attr.jid = stanza.attr.to; 1304 else
1312 else 1305 item.attr.jid = from_occupant.jid;
1313 item.attr.jid = from_occupant.jid;
1314 end
1315 end 1306 end
1316 end 1307 end
1317 end 1308 end
1318 self:route_stanza(stanza); 1309 self:route_stanza(stanza);
1319 if muc_child then 1310 if muc_child then
1320 for _, item in pairs(muc_child.tags) do 1311 for item in muc_child:childtags("item") do
1321 if item.name == "item" then 1312 item.attr.jid = nil;
1322 item.attr.jid = nil;
1323 end
1324 end 1313 end
1325 end 1314 end
1326 end 1315 end
1327 1316
1328 local _M = {}; -- module "muc" 1317 local _M = {}; -- module "muc"