plugins/muc: Move valid_roles, valid_affiliations and is_kickable_error to new muc...
authordaurnimator <quae@daurnimator.com>
Thu, 3 Apr 2014 21:09:04 +0000 (17:09 -0400)
committerdaurnimator <quae@daurnimator.com>
Thu, 3 Apr 2014 21:09:04 +0000 (17:09 -0400)
plugins/muc/muc.lib.lua
plugins/muc/util.lib.lua [new file with mode: 0644]

index 59069caed8b08b1c415be3681da8c937134e935a..6f19cd53d5b32894148d04a04f072de21833ce5c 100644 (file)
@@ -23,26 +23,9 @@ local base64 = require "util.encodings".base64;
 local md5 = require "util.hashes".md5;
 
 local occupant_lib = module:require "muc/occupant"
-
-
-local is_kickable_error do
-       local kickable_error_conditions = {
-               ["gone"] = true;
-               ["internal-server-error"] = true;
-               ["item-not-found"] = true;
-               ["jid-malformed"] = true;
-               ["recipient-unavailable"] = true;
-               ["redirect"] = true;
-               ["remote-server-not-found"] = true;
-               ["remote-server-timeout"] = true;
-               ["service-unavailable"] = true;
-               ["malformed error"] = true;
-       };
-       function is_kickable_error(stanza)
-               local cond = select(2, stanza:get_error()) or "malformed error";
-               return kickable_error_conditions[cond];
-       end
-end
+local muc_util = module:require "muc/util";
+local is_kickable_error = muc_util.is_kickable_error;
+local valid_roles, valid_affiliations = muc_util.valid_roles, muc_util.valid_affiliations;
 
 local room_mt = {};
 room_mt.__index = room_mt;
@@ -55,21 +38,6 @@ function room_mt:get_occupant_jid(real_jid)
        return self._jid_nick[real_jid]
 end
 
-local valid_affiliations = {
-       outcast = 0;
-       none = 1;
-       member = 2;
-       admin = 3;
-       owner = 4;
-};
-
-local valid_roles = {
-       none = 0;
-       visitor = 1;
-       participant = 2;
-       moderator = 3;
-};
-
 function room_mt:get_default_role(affiliation)
        if affiliation == "owner" or affiliation == "admin" then
                return "moderator";
diff --git a/plugins/muc/util.lib.lua b/plugins/muc/util.lib.lua
new file mode 100644 (file)
index 0000000..90a3a18
--- /dev/null
@@ -0,0 +1,44 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+-- Copyright (C) 2014 Daurnimator
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local _M = {};
+
+_M.valid_affiliations = {
+       outcast = -1;
+       none = 0;
+       member = 1;
+       admin = 2;
+       owner = 3;
+};
+
+_M.valid_roles = {
+       none = 0;
+       visitor = 1;
+       participant = 2;
+       moderator = 3;
+};
+
+local kickable_error_conditions = {
+       ["gone"] = true;
+       ["internal-server-error"] = true;
+       ["item-not-found"] = true;
+       ["jid-malformed"] = true;
+       ["recipient-unavailable"] = true;
+       ["redirect"] = true;
+       ["remote-server-not-found"] = true;
+       ["remote-server-timeout"] = true;
+       ["service-unavailable"] = true;
+       ["malformed error"] = true;
+};
+function _M.is_kickable_error(stanza)
+       local cond = select(2, stanza:get_error()) or "malformed error";
+       return kickable_error_conditions[cond];
+end
+
+return _M;