浏览代码

Adds some checks about async.

There are modules that will not work with prosody 0.10 as they depend on util.async. Adds a safeguard and print error about it in the logs.
And others that just do not work because of the muc module API that they use.
master
damencho 5 年前
父节点
当前提交
b4be1bcd05

+ 7
- 0
resources/prosody-plugins/mod_muc_poltergeist.lua 查看文件

4
 local neturl = require "net.url";
4
 local neturl = require "net.url";
5
 local parse = neturl.parseQuery;
5
 local parse = neturl.parseQuery;
6
 local poltergeist = module:require "poltergeist";
6
 local poltergeist = module:require "poltergeist";
7
+
8
+local have_async = pcall(require, "util.async");
9
+if not have_async then
10
+    module:log("error", "requires a version of Prosody with util.async");
11
+    return;
12
+end
13
+
7
 local wrap_async_run = module:require "util".wrap_async_run;
14
 local wrap_async_run = module:require "util".wrap_async_run;
8
 
15
 
9
 -- Options
16
 -- Options

+ 7
- 0
resources/prosody-plugins/mod_muc_size.lua 查看文件

7
 local json = require "util.json";
7
 local json = require "util.json";
8
 local iterators = require "util.iterators";
8
 local iterators = require "util.iterators";
9
 local array = require"util.array";
9
 local array = require"util.array";
10
+
11
+local have_async = pcall(require, "util.async");
12
+if not have_async then
13
+    module:log("error", "requires a version of Prosody with util.async");
14
+    return;
15
+end
16
+
10
 local wrap_async_run = module:require "util".wrap_async_run;
17
 local wrap_async_run = module:require "util".wrap_async_run;
11
 
18
 
12
 local tostring = tostring;
19
 local tostring = tostring;

+ 8
- 1
resources/prosody-plugins/mod_speakerstats_component.lua 查看文件

6
 local socket = require "socket";
6
 local socket = require "socket";
7
 local json = require "util.json";
7
 local json = require "util.json";
8
 
8
 
9
+-- we use async to detect Prosody 0.10 and earlier
10
+local have_async = pcall(require, "util.async");
11
+if not have_async then
12
+    module:log("warn", "speaker stats will not work with Prosody version 0.10 or less.");
13
+    return;
14
+end
15
+
9
 local muc_component_host = module:get_option_string("muc_component");
16
 local muc_component_host = module:get_option_string("muc_component");
10
 if muc_component_host == nil then
17
 if muc_component_host == nil then
11
     log("error", "No muc_component specified. No muc to operate on!");
18
     log("error", "No muc_component specified. No muc to operate on!");
204
     prosody.events.add_handler("host-activated", process_host);
211
     prosody.events.add_handler("host-activated", process_host);
205
 else
212
 else
206
     process_host(muc_component_host);
213
     process_host(muc_component_host);
207
-end
214
+end

+ 8
- 2
resources/prosody-plugins/util.lib.lua 查看文件

1
 local jid = require "util.jid";
1
 local jid = require "util.jid";
2
-local runner, waiter = require "util.async".runner, require "util.async".waiter;
3
-
2
+local have_async, async = pcall(require, "util.async");
4
 local muc_domain_prefix
3
 local muc_domain_prefix
5
     = module:get_option_string("muc_mapper_domain_prefix", "conference");
4
     = module:get_option_string("muc_mapper_domain_prefix", "conference");
6
 
5
 
62
 
61
 
63
 
62
 
64
 function wrap_async_run(event,handler)
63
 function wrap_async_run(event,handler)
64
+    local have_async = pcall(require, "util.async");
65
+    if not have_async then
66
+        module:log("error", "requires a version of Prosody with util.async");
67
+        return nil;
68
+    end
69
+
70
+    local runner = async.runner;
65
     -- Grab a local response so that we can send the http response when
71
     -- Grab a local response so that we can send the http response when
66
     -- the handler is done.
72
     -- the handler is done.
67
     local response = event.response;
73
     local response = event.response;

正在加载...
取消
保存