Comparison

plugins/muc/muc.lib.lua @ 11907:0dc2c3530d64

MUC: Add 'muc-pre-set-affiliation' event, allowing to block change or modify data
author Matthew Wild <mwild1@gmail.com>
date Tue, 16 Nov 2021 11:41:08 +0000
parent 11806:6f7d6712e250
child 11908:624c14b77bb4
comparison
equal deleted inserted replaced
11906:ba3344926e18 11907:0dc2c3530d64
1421 -- Can't demote owners or other admins 1421 -- Can't demote owners or other admins
1422 return nil, "cancel", "not-allowed"; 1422 return nil, "cancel", "not-allowed";
1423 end 1423 end
1424 end 1424 end
1425 1425
1426 local event_data = {
1427 room = self;
1428 actor = actor;
1429 jid = jid;
1430 affiliation = affiliation or "none";
1431 reason = reason;
1432 previous_affiliation = target_affiliation;
1433 data = data and data or nil; -- coerce false to nil
1434 };
1435 if not module:fire_event("muc-pre-set-affiliation", event_data) then
1436 local err = event_data.error or { type = "cancel", condition = "not-allowed" };
1437 return nil, err.type, err.condition;
1438 end
1439 if affiliation and not data and event_data.data then
1440 -- Allow handlers to add data when none was going to be set
1441 data = event_data.data;
1442 end
1443
1426 -- Set in 'database' 1444 -- Set in 'database'
1427 self._affiliations[jid] = affiliation; 1445 self._affiliations[jid] = affiliation;
1428 if not affiliation or data == false or (data ~= nil and next(data) == nil) then 1446 if not affiliation or data == false or (data ~= nil and next(data) == nil) then
1429 module:log("debug", "Clearing affiliation data for %s", jid); 1447 module:log("debug", "Clearing affiliation data for %s", jid);
1430 self._affiliation_data[jid] = nil; 1448 self._affiliation_data[jid] = nil;
1495 self:broadcast(announce_msg, muc_util.only_with_min_role(min_role)); 1513 self:broadcast(announce_msg, muc_util.only_with_min_role(min_role));
1496 end 1514 end
1497 1515
1498 self:save(true); 1516 self:save(true);
1499 1517
1500 module:fire_event("muc-set-affiliation", { 1518 event_data.in_room = next(occupants_updated) ~= nil;
1501 room = self; 1519 module:fire_event("muc-set-affiliation", event_data);
1502 actor = actor;
1503 jid = jid;
1504 affiliation = affiliation or "none";
1505 reason = reason;
1506 previous_affiliation = target_affiliation;
1507 data = data and data or nil; -- coerce false to nil
1508 in_room = next(occupants_updated) ~= nil;
1509 });
1510 1520
1511 return true; 1521 return true;
1512 end 1522 end
1513 1523
1514 function room_mt:get_affiliation_data(jid, key) 1524 function room_mt:get_affiliation_data(jid, key)