Software /
code /
prosody
Comparison
core/moduleapi.lua @ 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 |
parent | 13514:a1bc6533bbba |
child | 13719:4309c934e813 |
comparison
equal
deleted
inserted
replaced
13603:6e5124f72e9a | 13604:a4217361c1c6 |
---|---|
429 | 429 |
430 function api:handle_items(item_type, added_cb, removed_cb, existing) | 430 function api:handle_items(item_type, added_cb, removed_cb, existing) |
431 self:hook("item-added/"..item_type, added_cb); | 431 self:hook("item-added/"..item_type, added_cb); |
432 self:hook("item-removed/"..item_type, removed_cb); | 432 self:hook("item-removed/"..item_type, removed_cb); |
433 if existing ~= false then | 433 if existing ~= false then |
434 for _, item in ipairs(self:get_host_items(item_type)) do | 434 local modulemanager = require"prosody.core.modulemanager"; |
435 added_cb({ item = item }); | 435 local modules = modulemanager.get_modules(self.host); |
436 | |
437 for _, module in pairs(modules) do | |
438 local mod = module.module; | |
439 if mod.items and mod.items[item_type] then | |
440 for _, item in ipairs(mod.items[item_type]) do | |
441 added_cb({ source = mod; item = item }); | |
442 end | |
443 end | |
436 end | 444 end |
437 end | 445 end |
438 end | 446 end |
439 | 447 |
440 function api:provides(name, item) | 448 function api:provides(name, item) |