Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6217:657c707d9229
plugins/muc/muc.lib: Use util.iterators to count occupants
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Thu, 03 Apr 2014 16:10:43 -0400 |
parent | 6216:50b8b7caf200 |
child | 6218:bf11910bad5a |
comparison
equal
deleted
inserted
replaced
6216:50b8b7caf200 | 6217:657c707d9229 |
---|---|
11 local pairs, ipairs = pairs, ipairs; | 11 local pairs, ipairs = pairs, ipairs; |
12 local next = next; | 12 local next = next; |
13 local setmetatable = setmetatable; | 13 local setmetatable = setmetatable; |
14 | 14 |
15 local dataform = require "util.dataforms"; | 15 local dataform = require "util.dataforms"; |
16 local iterators = require "util.iterators"; | |
16 local jid_split = require "util.jid".split; | 17 local jid_split = require "util.jid".split; |
17 local jid_bare = require "util.jid".bare; | 18 local jid_bare = require "util.jid".bare; |
18 local jid_prep = require "util.jid".prep; | 19 local jid_prep = require "util.jid".prep; |
19 local st = require "util.stanza"; | 20 local st = require "util.stanza"; |
20 local log = require "util.logger".init("mod_muc"); | 21 local log = require "util.logger".init("mod_muc"); |
311 end); | 312 end); |
312 module:hook("muc-disco#info", function(event) | 313 module:hook("muc-disco#info", function(event) |
313 event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up(); | 314 event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up(); |
314 end); | 315 end); |
315 module:hook("muc-disco#info", function(event) | 316 module:hook("muc-disco#info", function(event) |
316 local count = 0; for _ in event.room:each_occupant() do count = count + 1; end | 317 local count = iterators.count(event.room:each_occupant()); |
317 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); | 318 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); |
318 end); | 319 end); |
319 | 320 |
320 function room_mt:get_disco_items(stanza) | 321 function room_mt:get_disco_items(stanza) |
321 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); | 322 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |