local jid_prep = require "util.jid".prep;
local jid_join = require "util.jid".join;
local st = require "util.stanza";
-local log = require "util.logger".init("mod_muc");
local base64 = require "util.encodings".base64;
local md5 = require "util.hashes".md5;
+local log = module._log;
+
local occupant_lib = module:require "muc/occupant"
local muc_util = module:require "muc/util";
local is_kickable_error = muc_util.is_kickable_error;
return "MUC room ("..self.jid..")";
end
+function room_mt.save()
+ -- overriden by mod_muc.lua
+end
+
function room_mt:get_occupant_jid(real_jid)
return self._jid_nick[real_jid]
end
local form = dataform.new {
{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" };
};
- module:fire_event("muc-disco#info", {room = self; reply = reply; form = form;});
- reply:add_child(form:form(nil, "result"));
+ local formdata = {};
+ module:fire_event("muc-disco#info", {room = self; reply = reply; form = form, formdata = formdata ;});
+ reply:add_child(form:form(formdata, "result"));
return reply;
end
module:hook("muc-disco#info", function(event)
event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up();
end);
module:hook("muc-disco#info", function(event)
- local count = iterators.count(event.room:each_occupant());
- table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) });
+ table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants" });
+ event.formdata["muc#roominfo_occupants"] = tostring(iterators.count(event.room:each_occupant()));
end);
function room_mt:get_disco_items(stanza)
self:publicise_occupant_status(orig_occupant, orig_x, dest_nick);
if is_last_orig_session then
- module:fire_event("muc-occupant-left", {room = self; nick = orig_occupant.nick; occupant = orig_occupant;});
+ module:fire_event("muc-occupant-left", {
+ room = self;
+ nick = orig_occupant.nick;
+ occupant = orig_occupant;
+ origin = origin;
+ stanza = stanza;
+ });
end
end
if orig_occupant == nil then
if is_first_dest_session then
- module:fire_event("muc-occupant-joined", {room = self; nick = dest_occupant.nick; occupant = dest_occupant;});
+ module:fire_event("muc-occupant-joined", {
+ room = self;
+ nick = dest_occupant.nick;
+ occupant = dest_occupant;
+ stanza = stanza;
+ origin = origin;
+ });
end
- module:fire_event("muc-occupant-session-new", {room = self; nick = dest_occupant.nick; occupant = dest_occupant; stanza = stanza; jid = real_jid;});
+ module:fire_event("muc-occupant-session-new", {
+ room = self;
+ nick = dest_occupant.nick;
+ occupant = dest_occupant;
+ stanza = stanza;
+ origin = origin;
+ jid = real_jid;
+ });
end
end
elseif type ~= 'result' then -- bad type
end
event.field, event.value = nil, nil;
- if self.save then self:save(true); end
+ self:save(true);
origin.send(st.reply(stanza));
if next(event.status_codes) then
occupants_updated[occupant] = true;
end
for occupant in pairs(occupants_updated) do
+ occupant:set_session(occupant.jid, st.presence({type="unavailable"}), true);
self:publicise_occupant_status(occupant, x);
module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;});
end
else
success, errtype, err = nil, "cancel", "bad-request";
end
+ room:save();
if not success then
origin.send(st.error_reply(stanza, errtype, err));
else
end
end
- if self.save then self:save(); end
+ self:save(true);
module:fire_event("muc-set-affiliation", {
room = self;
local _M = {}; -- module "muc"
-function _M.new_room(jid, config) -- luacheck: ignore 212
- -- TODO use config?
+function _M.new_room(jid, config)
return setmetatable({
jid = jid;
_jid_nick = {};
_occupants = {};
- _data = {
- };
+ _data = config or {};
_affiliations = {};
}, room_mt);
end
+function room_mt:freeze()
+ return {
+ jid = self.jid;
+ _data = self._data;
+ _affiliations = self._affiliations;
+ }
+end
+
_M.room_mt = room_mt;
return _M;