Browse Source

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.
j8
damencho 5 years ago
parent
commit
b4be1bcd05

+ 7
- 0
resources/prosody-plugins/mod_muc_poltergeist.lua View File

@@ -4,6 +4,13 @@ local jid = require "util.jid";
4 4
 local neturl = require "net.url";
5 5
 local parse = neturl.parseQuery;
6 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 14
 local wrap_async_run = module:require "util".wrap_async_run;
8 15
 
9 16
 -- Options

+ 7
- 0
resources/prosody-plugins/mod_muc_size.lua View File

@@ -7,6 +7,13 @@ local it = require "util.iterators";
7 7
 local json = require "util.json";
8 8
 local iterators = require "util.iterators";
9 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 17
 local wrap_async_run = module:require "util".wrap_async_run;
11 18
 
12 19
 local tostring = tostring;

+ 8
- 1
resources/prosody-plugins/mod_speakerstats_component.lua View File

@@ -6,6 +6,13 @@ local st = require "util.stanza";
6 6
 local socket = require "socket";
7 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 16
 local muc_component_host = module:get_option_string("muc_component");
10 17
 if muc_component_host == nil then
11 18
     log("error", "No muc_component specified. No muc to operate on!");
@@ -204,4 +211,4 @@ if prosody.hosts[muc_component_host] == nil then
204 211
     prosody.events.add_handler("host-activated", process_host);
205 212
 else
206 213
     process_host(muc_component_host);
207
-end
214
+end

+ 8
- 2
resources/prosody-plugins/util.lib.lua View File

@@ -1,6 +1,5 @@
1 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 3
 local muc_domain_prefix
5 4
     = module:get_option_string("muc_mapper_domain_prefix", "conference");
6 5
 
@@ -62,6 +61,13 @@ end
62 61
 
63 62
 
64 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 71
     -- Grab a local response so that we can send the http response when
66 72
     -- the handler is done.
67 73
     local response = event.response;

Loading…
Cancel
Save