Software /
code /
prosody
Changeset
13604:a4217361c1c6
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 08 Jan 2025 08:33:34 +0100 |
parents | 13603:6e5124f72e9a |
children | 13605:74a8006ee7f6 |
files | core/moduleapi.lua |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/core/moduleapi.lua Wed Jan 08 08:11:02 2025 +0100 +++ b/core/moduleapi.lua Wed Jan 08 08:33:34 2025 +0100 @@ -431,8 +431,16 @@ 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