diff options
author | Kim Alvefur <zash@zash.se> | 2025-01-08 08:33:34 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2025-01-08 08:33:34 +0100 |
commit | fe2c039c97382c7636b9e1d17ac3f4ee4f0ae342 (patch) | |
tree | 4261d90fe9965febc4b28f6dd281c346fd9496bf /core | |
parent | 63690dd4a04eef9e016558f6b69bab6c64b5473b (diff) | |
download | prosody-fe2c039c97382c7636b9e1d17ac3f4ee4f0ae342.tar.gz prosody-fe2c039c97382c7636b9e1d17ac3f4ee4f0ae342.zip |
core.moduleapi: Include source modules when handling items
This improves consistency. Previously the 'source' field was only
provided in the original event when an item was added. It is used to
report the name of the module providing the item in a few places.
Also considered adding a new API to modulemanager returning a mapping
of items per module and then using that here.
Diffstat (limited to 'core')
-rw-r--r-- | core/moduleapi.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua index fa5086cf..b93536b5 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -431,8 +431,16 @@ function api:handle_items(item_type, added_cb, removed_cb, existing) self:hook("item-added/"..item_type, added_cb); self:hook("item-removed/"..item_type, removed_cb); if existing ~= false then - for _, item in ipairs(self:get_host_items(item_type)) do - added_cb({ item = item }); + local modulemanager = require"prosody.core.modulemanager"; + local modules = modulemanager.get_modules(self.host); + + for _, module in pairs(modules) do + local mod = module.module; + if mod.items and mod.items[item_type] then + for _, item in ipairs(mod.items[item_type]) do + added_cb({ source = mod; item = item }); + end + end end end end |