Comparison

plugins/muc/muc.lib.lua @ 6196:e73bb1568d87

plugins/muc/muc.lib: Update declines to be more like invites
author daurnimator <quae@daurnimator.com>
date Mon, 31 Mar 2014 14:06:35 -0400
parent 6195:9f6a003baf2e
child 6197:1ee4d8953544
comparison
equal deleted inserted replaced
6195:9f6a003baf2e 6196:e73bb1568d87
1277 room:set_affiliation(from, invitee, "member", "Invited by " .. current_nick) 1277 room:set_affiliation(from, invitee, "member", "Invited by " .. current_nick)
1278 end 1278 end
1279 end); 1279 end);
1280 1280
1281 function room_mt:handle_mediated_decline(origin, stanza) 1281 function room_mt:handle_mediated_decline(origin, stanza)
1282 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline") 1282 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline");
1283 local declinee = jid_prep(payload.attr.to); 1283 local declinee = jid_prep(payload.attr.to);
1284 if declinee then 1284 if not declinee then
1285 local from, to = stanza.attr.from, stanza.attr.to; 1285 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
1286 -- TODO: Validate declinee 1286 return true;
1287 local reason = payload:get_child_text("reason") 1287 elseif not module:fire_event("muc-pre-decline", {room = self, origin = origin, stanza = stanza}) then
1288 local decline = st.message({from = to, to = declinee, id = stanza.attr.id}) 1288 return true;
1289 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) 1289 end
1290 :tag('decline', {from=from}) 1290 local decline = st.message({from = self.jid, to = declinee, id = stanza.attr.id})
1291 :tag('reason'):text(reason or ""):up() 1291 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
1292 :up() 1292 :tag("decline", {from = stanza.attr.from})
1293 :tag("reason"):text(payload:get_child_text("reason")):up()
1293 :up() 1294 :up()
1294 :tag('body') -- Add a plain message for clients which don't support declines 1295 :up();
1295 :text(from..' declined your invite to the room '..to..(reason and (' ('..reason..')') or "")) 1296 if not module:fire_event("muc-decline", {room = self, stanza = decline, origin = origin, incoming = stanza}) then
1296 :up(); 1297 local occupant = self:get_occupant_by_real_jid(decline.attr.to);
1297 module:fire_event("muc-decline", { room = self, stanza = decline, origin = origin, incoming = stanza }); 1298 if occupant then
1298 return true; 1299 self:route_to_occupant(occupant, decline);
1299 else 1300 else
1300 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); 1301 self:route_stanza(decline);
1301 return true; 1302 end
1302 end 1303 end
1303 end 1304 return true;
1304 1305 end
1306
1307 -- Add a plain message for clients which don't support declines
1305 module:hook("muc-decline", function(event) 1308 module:hook("muc-decline", function(event)
1306 local room, stanza = event.room, event.stanza 1309 local room, stanza = event.room, event.stanza;
1307 local occupant = room:get_occupant_by_real_jid(stanza.attr.to); 1310 local decline = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline");
1308 if occupant then 1311 local reason = decline:get_child_text("reason") or "";
1309 room:route_to_occupant(occupant, stanza) 1312 stanza:tag("body")
1310 else 1313 :text(decline.attr.from.." declined your invite to the room "..room.jid..(reason == "" and (" ("..reason..")") or ""))
1311 room:route_stanza(stanza); 1314 :up();
1312 end 1315 end);
1313 return true;
1314 end, -1)
1315 1316
1316 function room_mt:handle_message_to_room(origin, stanza) 1317 function room_mt:handle_message_to_room(origin, stanza)
1317 local type = stanza.attr.type; 1318 local type = stanza.attr.type;
1318 if type == "groupchat" then 1319 if type == "groupchat" then
1319 return self:handle_groupchat_to_room(origin, stanza) 1320 return self:handle_groupchat_to_room(origin, stanza)