Comparison

plugins/muc/mod_muc.lua @ 6234:cc8a6ca2d7c5

plugins/muc/mod_muc: Move affiliation monkey patch into own scope
author daurnimator <quae@daurnimator.com>
date Mon, 28 Apr 2014 16:30:53 -0400
parent 6222:355b29881117
child 6235:d433db49e353
comparison
equal deleted inserted replaced
6231:bc12a8253f94 6234:cc8a6ca2d7c5
24 end 24 end
25 end 25 end
26 26
27 local muclib = module:require "muc"; 27 local muclib = module:require "muc";
28 local muc_new_room = muclib.new_room; 28 local muc_new_room = muclib.new_room;
29 room_mt = muclib.room_mt; -- Yes, global.
29 local persistent = module:require "muc/persistent"; 30 local persistent = module:require "muc/persistent";
30 local jid_split = require "util.jid".split; 31 local jid_split = require "util.jid".split;
31 local jid_bare = require "util.jid".bare; 32 local jid_bare = require "util.jid".bare;
32 local st = require "util.stanza"; 33 local st = require "util.stanza";
33 local um_is_admin = require "core.usermanager".is_admin; 34 local um_is_admin = require "core.usermanager".is_admin;
50 51
51 local function is_admin(jid) 52 local function is_admin(jid)
52 return um_is_admin(jid, module.host); 53 return um_is_admin(jid, module.host);
53 end 54 end
54 55
55 room_mt = muclib.room_mt; -- Yes, global. 56 do -- Monkey patch to make server admins room owners
56 local _set_affiliation = room_mt.set_affiliation; 57 local _get_affiliation = room_mt.get_affiliation;
57 local _get_affiliation = room_mt.get_affiliation; 58 function room_mt:get_affiliation(jid)
58 function muclib.room_mt:get_affiliation(jid) 59 if is_admin(jid) then return "owner"; end
59 if is_admin(jid) then return "owner"; end 60 return _get_affiliation(self, jid);
60 return _get_affiliation(self, jid); 61 end
61 end 62
62 function muclib.room_mt:set_affiliation(actor, jid, affiliation, callback, reason) 63 local _set_affiliation = room_mt.set_affiliation;
63 if is_admin(jid) then return nil, "modify", "not-acceptable"; end 64 function room_mt:set_affiliation(actor, jid, ...)
64 return _set_affiliation(self, actor, jid, affiliation, callback, reason); 65 if is_admin(jid) then return nil, "modify", "not-acceptable"; end
66 return _set_affiliation(self, actor, jid, ...);
67 end
65 end 68 end
66 69
67 local function room_save(room, forced) 70 local function room_save(room, forced)
68 local node = jid_split(room.jid); 71 local node = jid_split(room.jid);
69 local is_persistent = persistent.get(room); 72 local is_persistent = persistent.get(room);