Преглед на файлове

Creates util for modules and adds method get_room_from_jid in it.

master
damencho преди 8 години
родител
ревизия
2b1e8cdeff
променени са 2 файла, в които са добавени 26 реда и са изтрити 18 реда
  1. 1
    18
      resources/prosody-plugins/mod_muc_size.lua
  2. 25
    0
      resources/prosody-plugins/util.lib.lua

+ 1
- 18
resources/prosody-plugins/mod_muc_size.lua Целия файл

@@ -19,6 +19,7 @@ local enableTokenVerification
19 19
     = module:get_option_boolean("enable_roomsize_token_verification", false);
20 20
 
21 21
 local token_util = module:require "token/util".new(module);
22
+local get_room_from_jid = module:require "util".get_room_from_jid;
22 23
 
23 24
 -- no token configuration but required
24 25
 if token_util == nil and enableTokenVerification then
@@ -31,26 +32,6 @@ end
31 32
 local muc_domain_prefix
32 33
     = module:get_option_string("muc_mapper_domain_prefix", "conference");
33 34
 
34
---- Finds and returns room by its jid
35
-function get_room_from_jid(room_jid)
36
-	local _, host = jid.split(room_jid);
37
-	local component = hosts[host];
38
-	if component then
39
-		local muc = component.modules.muc
40
-		if muc and rawget(muc,"rooms") then
41
-			-- We're running 0.9.x or 0.10 (old MUC API)
42
-			return muc.rooms[room_jid];
43
-		elseif muc and rawget(muc,"get_room_from_jid") then
44
-			-- We're running >0.10 (new MUC API)
45
-			return muc.get_room_from_jid(room_jid);
46
-		else
47
-			return
48
-		end
49
-	end
50
-end
51
-
52 35
 --- Verifies room name, domain name with the values in the token
53 36
 -- @param token the token we received
54 37
 -- @param room_address the full room address jid

+ 25
- 0
resources/prosody-plugins/util.lib.lua Целия файл

@@ -0,0 +1,25 @@
1
+local jid = require "util.jid";
2
+
3
+--- Finds and returns room by its jid
4
+-- @param room_jid the room jid to search in the muc component
5
+-- @return returns room if found or nil
6
+function get_room_from_jid(room_jid)
7
+    local _, host = jid.split(room_jid);
8
+    local component = hosts[host];
9
+    if component then
10
+        local muc = component.modules.muc
11
+        if muc and rawget(muc,"rooms") then
12
+            -- We're running 0.9.x or 0.10 (old MUC API)
13
+            return muc.rooms[room_jid];
14
+        elseif muc and rawget(muc,"get_room_from_jid") then
15
+            -- We're running >0.10 (new MUC API)
16
+            return muc.get_room_from_jid(room_jid);
17
+        else
18
+            return
19
+        end
20
+    end
21
+end
22
+
23
+return {
24
+    get_room_from_jid = get_room_from_jid;
25
+};

Loading…
Отказ
Запис