diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-07-17 10:29:16 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-07-17 10:29:16 +0100 |
commit | 045262aca5a651b0ea966cff8af48ae26c9a5377 (patch) | |
tree | 0cf7d725712b042b556b08572fbc1bf75200a931 /plugins | |
parent | 260930853663e88d5abfe33858fc69800610da31 (diff) | |
download | prosody-045262aca5a651b0ea966cff8af48ae26c9a5377.tar.gz prosody-045262aca5a651b0ea966cff8af48ae26c9a5377.zip |
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/muc/mod_muc.lua | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index 066d1608..5ee328f5 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -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 @@ function delete_room(room) 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 @@ function create_room(room_jid, config) 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 @@ function each_room(live_only) 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 @@ module:hook("host-disco-items", function(event) 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 @@ for event_name, method in pairs { 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 @@ do -- Ad-hoc commands }; 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 = {}; |