Software /
code /
prosody
Comparison
core/moduleapi.lua @ 5412:a5fcda77c6b1
moduleapi: have get_host_items wrap on get_items from modulemanager, also add has_{feature/identity} to the API.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Mon, 01 Apr 2013 23:44:28 +0000 |
parent | 5377:898454038524 |
child | 5434:9dd36e20c1e3 |
comparison
equal
deleted
inserted
replaced
5411:82b3ddba0ec7 | 5412:a5fcda77c6b1 |
---|---|
59 function api:add_identity(category, type, name) | 59 function api:add_identity(category, type, name) |
60 self:add_item("identity", {category = category, type = type, name = name}); | 60 self:add_item("identity", {category = category, type = type, name = name}); |
61 end | 61 end |
62 function api:add_extension(data) | 62 function api:add_extension(data) |
63 self:add_item("extension", data); | 63 self:add_item("extension", data); |
64 end | |
65 function api:has_feature(xmlns) | |
66 for _, feature in ipairs(self:get_host_items("feature")) do | |
67 if feature == xmlns then return true; end | |
68 end | |
69 return false; | |
70 end | |
71 function api:has_identity(category, type, name) | |
72 for _, id in ipairs(self:get_host_items("identity")) do | |
73 if id.category == category and id.type == type and id.name == name then | |
74 return true; | |
75 end | |
76 end | |
77 return false; | |
64 end | 78 end |
65 | 79 |
66 function api:fire_event(...) | 80 function api:fire_event(...) |
67 return (hosts[self.host] or prosody).events.fire_event(...); | 81 return (hosts[self.host] or prosody).events.fire_event(...); |
68 end | 82 end |
269 end | 283 end |
270 end | 284 end |
271 end | 285 end |
272 | 286 |
273 function api:get_host_items(key) | 287 function api:get_host_items(key) |
274 local result = {}; | 288 local result = modulemanager.get_items(key, self.host) or {}; |
275 for mod_name, module in pairs(modulemanager.get_modules(self.host)) do | |
276 module = module.module; | |
277 if module.items then | |
278 for _, item in ipairs(module.items[key] or NULL) do | |
279 t_insert(result, item); | |
280 end | |
281 end | |
282 end | |
283 for mod_name, module in pairs(modulemanager.get_modules("*")) do | |
284 module = module.module; | |
285 if module.items then | |
286 for _, item in ipairs(module.items[key] or NULL) do | |
287 t_insert(result, item); | |
288 end | |
289 end | |
290 end | |
291 return result; | 289 return result; |
292 end | 290 end |
293 | 291 |
294 function api:handle_items(type, added_cb, removed_cb, existing) | 292 function api:handle_items(type, added_cb, removed_cb, existing) |
295 self:hook("item-added/"..type, added_cb); | 293 self:hook("item-added/"..type, added_cb); |