From fe2c039c97382c7636b9e1d17ac3f4ee4f0ae342 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 8 Jan 2025 08:33:34 +0100 Subject: 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. --- core/moduleapi.lua | 12 ++++++++++-- 1 file 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 -- cgit v1.2.3