Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 6220:4e7d205f49f7
plugins/muc/muc.lib: Turn get_default_role into an event
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Thu, 03 Apr 2014 18:36:28 -0400 |
| parents | a90159cfa530 |
| children | f321536afeec |
comparison
equal
deleted
inserted
replaced
| 6219:a90159cfa530 | 6220:4e7d205f49f7 |
|---|---|
| 37 function room_mt:get_occupant_jid(real_jid) | 37 function room_mt:get_occupant_jid(real_jid) |
| 38 return self._jid_nick[real_jid] | 38 return self._jid_nick[real_jid] |
| 39 end | 39 end |
| 40 | 40 |
| 41 function room_mt:get_default_role(affiliation) | 41 function room_mt:get_default_role(affiliation) |
| 42 if affiliation == "owner" or affiliation == "admin" then | 42 local role = module:fire_event("muc-get-default-role", { |
| 43 room = self; | |
| 44 affiliation = affiliation; | |
| 45 affiliation_rank = valid_affiliations[affiliation or "none"]; | |
| 46 }); | |
| 47 return role, valid_roles[role or "none"]; | |
| 48 end | |
| 49 module:hook("muc-get-default-role", function(event) | |
| 50 if event.affiliation_rank >= valid_affiliations.admin then | |
| 43 return "moderator"; | 51 return "moderator"; |
| 44 elseif affiliation == "member" then | 52 elseif event.affiliation_rank >= valid_affiliations.member then |
| 45 return "participant"; | 53 return "participant"; |
| 46 elseif not affiliation then | 54 end |
| 47 if not self:get_members_only() then | 55 end); |
| 48 return self:get_moderated() and "visitor" or "participant"; | 56 module:hook("muc-get-default-role", function(event) |
| 49 end | 57 if not event.affiliation and event.room:get_members_only() then |
| 50 end | 58 return false; |
| 51 end | 59 end |
| 60 end); | |
| 61 module:hook("muc-get-default-role", function(event) | |
| 62 if not event.affiliation then | |
| 63 return event.room:get_moderated() and "visitor" or "participant"; | |
| 64 end | |
| 65 end, -1); | |
| 52 | 66 |
| 53 --- Occupant functions | 67 --- Occupant functions |
| 54 function room_mt:new_occupant(bare_real_jid, nick) | 68 function room_mt:new_occupant(bare_real_jid, nick) |
| 55 local occupant = occupant_lib.new(bare_real_jid, nick); | 69 local occupant = occupant_lib.new(bare_real_jid, nick); |
| 56 local affiliation = self:get_affiliation(bare_real_jid); | 70 local affiliation = self:get_affiliation(bare_real_jid); |
