MUC: Assign occupants unavailable presence on room destruction, fixes destruction...
[prosody.git] / core / moduleapi.lua
index bb8021958219bc74537864336d86ed26e207f8a7..9b773f89c5314ba7e9a0771722869cf69d79d8c3 100644 (file)
@@ -7,7 +7,6 @@
 --
 
 local config = require "core.configmanager";
-local modulemanager; -- This gets set from modulemanager
 local array = require "util.array";
 local set = require "util.set";
 local it = require "util.iterators";
@@ -24,7 +23,7 @@ local ipairs, pairs, select = ipairs, pairs, select;
 local tonumber, tostring = tonumber, tostring;
 local require = require;
 local pack = table.pack or function(...) return {n=select("#",...), ...}; end -- table.pack is only in 5.2
-local unpack = table.unpack or unpack; -- renamed in 5.2
+local unpack = table.unpack or unpack; --luacheck: ignore 113 -- renamed in 5.2
 
 local prosody = prosody;
 local hosts = prosody.hosts;
@@ -138,15 +137,13 @@ function api:wrap_global(event, handler)
 end
 
 function api:require(lib)
-       local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment);
-       if not f then
-               f, n = pluginloader.load_code(lib, lib..".lib.lua", self.environment);
-       end
+       local f, n = pluginloader.load_code_ext(self.name, lib, "lib.lua", self.environment);
        if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message
        return f();
 end
 
 function api:depends(name)
+       local modulemanager = require"core.modulemanager";
        if not self.dependencies then
                self.dependencies = {};
                self:hook("module-reloaded", function (event)
@@ -306,6 +303,20 @@ function api:get_option_inherited_set(name, ...)
        return value;
 end
 
+function api:get_option_path(name, default, parent)
+       if parent == nil then
+               parent = parent or self:get_directory();
+       elseif prosody.paths[parent] then
+               parent = prosody.paths[parent];
+       end
+       local value = self:get_option_string(name, default);
+       if value == nil then
+               return nil;
+       end
+       return resolve_relative_path(parent, value);
+end
+
+
 function api:context(host)
        return setmetatable({host=host or "*"}, {__index=self,__newindex=self});
 end
@@ -328,6 +339,7 @@ function api:remove_item(key, value)
 end
 
 function api:get_host_items(key)
+       local modulemanager = require"core.modulemanager";
        local result = modulemanager.get_items(key, self.host) or {};
        return result;
 end
@@ -363,8 +375,8 @@ function api:provides(name, item)
        self:add_item(name.."-provider", item);
 end
 
-function api:send(stanza)
-       return core_post_stanza(hosts[self.host], stanza);
+function api:send(stanza, origin)
+       return core_post_stanza(origin or hosts[self.host], stanza);
 end
 
 function api:broadcast(jids, stanza, iter)
@@ -387,7 +399,7 @@ function timer_methods:reschedule(delay)
        timer.reschedule(self.id, delay)
 end
 
-local function timer_callback(now, id, t)
+local function timer_callback(now, id, t) --luacheck: ignore 212/id
        if t.module_env.loaded == false then return; end
        return t.callback(now, unpack(t, 1, t.n));
 end
@@ -437,9 +449,4 @@ function api:measure_global_event(event_name, stat_name)
        return self:measure_object_event(prosody.events.wrappers, event_name, stat_name);
 end
 
-function api.init(mm)
-       modulemanager = mm;
-       return api;
-end
-
 return api;