# HG changeset patch # User daurnimator # Date 1396564588 14400 # Node ID 4e7d205f49f746acf572c46369d5d05b53cfe9ed # Parent a90159cfa53077b33d3df9e6be6d6c032a295d66 plugins/muc/muc.lib: Turn get_default_role into an event diff -r a90159cfa530 -r 4e7d205f49f7 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Thu Apr 03 18:10:16 2014 -0400 +++ b/plugins/muc/muc.lib.lua Thu Apr 03 18:36:28 2014 -0400 @@ -39,16 +39,30 @@ end function room_mt:get_default_role(affiliation) - if affiliation == "owner" or affiliation == "admin" then + local role = module:fire_event("muc-get-default-role", { + room = self; + affiliation = affiliation; + affiliation_rank = valid_affiliations[affiliation or "none"]; + }); + return role, valid_roles[role or "none"]; +end +module:hook("muc-get-default-role", function(event) + if event.affiliation_rank >= valid_affiliations.admin then return "moderator"; - elseif affiliation == "member" then + elseif event.affiliation_rank >= valid_affiliations.member then return "participant"; - elseif not affiliation then - if not self:get_members_only() then - return self:get_moderated() and "visitor" or "participant"; - end + end +end); +module:hook("muc-get-default-role", function(event) + if not event.affiliation and event.room:get_members_only() then + return false; end -end +end); +module:hook("muc-get-default-role", function(event) + if not event.affiliation then + return event.room:get_moderated() and "visitor" or "participant"; + end +end, -1); --- Occupant functions function room_mt:new_occupant(bare_real_jid, nick)