Comparison

plugins/muc/muc.lib.lua @ 6218:bf11910bad5a

plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc/util module
author daurnimator <quae@daurnimator.com>
date Thu, 03 Apr 2014 17:09:04 -0400
parent 6217:657c707d9229
child 6219:a90159cfa530
comparison
equal deleted inserted replaced
6217:657c707d9229 6218:bf11910bad5a
21 local log = require "util.logger".init("mod_muc"); 21 local log = require "util.logger".init("mod_muc");
22 local base64 = require "util.encodings".base64; 22 local base64 = require "util.encodings".base64;
23 local md5 = require "util.hashes".md5; 23 local md5 = require "util.hashes".md5;
24 24
25 local occupant_lib = module:require "muc/occupant" 25 local occupant_lib = module:require "muc/occupant"
26 26 local muc_util = module:require "muc/util";
27 27 local is_kickable_error = muc_util.is_kickable_error;
28 local is_kickable_error do 28 local valid_roles, valid_affiliations = muc_util.valid_roles, muc_util.valid_affiliations;
29 local kickable_error_conditions = {
30 ["gone"] = true;
31 ["internal-server-error"] = true;
32 ["item-not-found"] = true;
33 ["jid-malformed"] = true;
34 ["recipient-unavailable"] = true;
35 ["redirect"] = true;
36 ["remote-server-not-found"] = true;
37 ["remote-server-timeout"] = true;
38 ["service-unavailable"] = true;
39 ["malformed error"] = true;
40 };
41 function is_kickable_error(stanza)
42 local cond = select(2, stanza:get_error()) or "malformed error";
43 return kickable_error_conditions[cond];
44 end
45 end
46 29
47 local room_mt = {}; 30 local room_mt = {};
48 room_mt.__index = room_mt; 31 room_mt.__index = room_mt;
49 32
50 function room_mt:__tostring() 33 function room_mt:__tostring()
52 end 35 end
53 36
54 function room_mt:get_occupant_jid(real_jid) 37 function room_mt:get_occupant_jid(real_jid)
55 return self._jid_nick[real_jid] 38 return self._jid_nick[real_jid]
56 end 39 end
57
58 local valid_affiliations = {
59 outcast = 0;
60 none = 1;
61 member = 2;
62 admin = 3;
63 owner = 4;
64 };
65
66 local valid_roles = {
67 none = 0;
68 visitor = 1;
69 participant = 2;
70 moderator = 3;
71 };
72 40
73 function room_mt:get_default_role(affiliation) 41 function room_mt:get_default_role(affiliation)
74 if affiliation == "owner" or affiliation == "admin" then 42 if affiliation == "owner" or affiliation == "admin" then
75 return "moderator"; 43 return "moderator";
76 elseif affiliation == "member" then 44 elseif affiliation == "member" then