Software /
code /
prosody
Changeset
9050:f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 10:29:16 +0100 |
parents | 9049:5870a0a6d4b6 |
children | 9051:68386f7b9fc9 |
files | plugins/muc/mod_muc.lua |
diffstat | 1 files changed, 20 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua Tue Jul 17 10:01:19 2018 +0100 +++ b/plugins/muc/mod_muc.lua Tue Jul 17 10:29:16 2018 +0100 @@ -13,7 +13,9 @@ -- delete_room(room) -- forget_room(room) -- get_room_from_jid(jid) -> room --- each_room(live_only) -> () -> room +-- each_room(live_only) -> () -> room [DEPRECATED] +-- all_rooms() -> room +-- live_rooms() -> room -- shutdown_component() if module:get_host_type() ~= "component" then @@ -220,7 +222,7 @@ end function module.unload() - for room in rooms:values() do + for room in live_rooms() do room:save(nil, true); forget_room(room); end @@ -249,13 +251,10 @@ return track_room(room); end -function each_room(live_only) - if live_only then - return rooms:values(); - end +function all_rooms() return coroutine.wrap(function () local seen = {}; -- Don't iterate over persistent rooms twice - for room in rooms:values() do + for room in live_rooms() do coroutine.yield(room); seen[room.jid] = true; end @@ -280,6 +279,17 @@ end); end +function live_rooms() + return rooms:values(); +end + +function each_room(live_only) + if live_only then + return live_rooms(); + end + return all_rooms(); +end + module:hook("host-disco-items", function(event) local reply = event.reply; module:log("debug", "host-disco-items called"); @@ -288,7 +298,7 @@ reply:tag("item", { jid = jid, name = room_name }):up(); end else - for room in each_room() do + for room in all_rooms() do if not room:get_hidden() then local jid, room_name = room.jid, room:get_name(); room_items_cache[jid] = room_name; @@ -433,7 +443,7 @@ end function shutdown_component() - for room in each_room(true) do + for room in live_rooms() do room:save(nil, true); end end @@ -456,7 +466,7 @@ }; local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() - return { rooms = array.collect(each_room()):pluck("jid"):sort(); }; + return { rooms = array.collect(all_rooms()):pluck("jid"):sort(); }; end, function(fields, errors) if errors then local errmsg = {};