local select = select;
local pairs, ipairs = pairs, ipairs;
-local datamanager = require "util.datamanager";
local datetime = require "util.datetime";
local dataform = require "util.dataforms";
local jid_prep = require "util.jid".prep;
local st = require "util.stanza";
local log = require "util.logger".init("mod_muc");
-local multitable_new = require "util.multitable".new;
local t_insert, t_remove = table.insert, table.remove;
local setmetatable = setmetatable;
local base64 = require "util.encodings".base64;
stanza = st.clone(stanza);
stanza.attr.to = "";
local stamp = datetime.datetime();
- local chars = #tostring(stanza);
stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203
stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
local entry = { stanza = stanza, stamp = stamp };
t_insert(history, entry);
- while #history > self._data.history_length do t_remove(history, 1) end
+ while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end
end
end
function room_mt:broadcast_except_nick(stanza, nick)
local n = 0;
local charcount = 0;
- local stanzacount = 0;
for i=#history,1,-1 do
local entry = history[i];
return self._data.changesubject;
end
function room_mt:get_historylength()
- return self._data.history_length
+ return self._data.history_length or default_history_length;
end
function room_mt:set_historylength(length)
- if tonumber(length) == nil then
- return
- end
- length = tonumber(length);
- log("debug", "max_history_length %s", self._data.max_history_length or "nil");
- if self._data.max_history_length and length > self._data.max_history_length then
- length = self._data.max_history_length
+ length = math.min(tonumber(length) or default_history_length, self._data_max_history_length or math.huge);
+ if length == default_history_length then
+ length = nil;
end
self._data.history_length = length;
end
dirty = dirty or (self:get_changesubject() ~= (not changesubject and true or nil))
module:log('debug', 'changesubject=%s', changesubject and "true" or "false")
- local historylength = fields['muc#roomconfig_historylength'];
- dirty = dirty or (self:get_historylength() ~= (historylength and true or nil))
+ local historylength = tonumber(fields['muc#roomconfig_historylength']);
+ dirty = dirty or (historylength and (self:get_historylength() ~= historylength));
module:log('debug', 'historylength=%s', historylength)
local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
if stanza.name == "iq" then
if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
- origin.send(self:get_disco_info(stanza));
+ if stanza.tags[1].attr.node then
+ origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented"));
+ else
+ origin.send(self:get_disco_info(stanza));
+ end
elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
origin.send(self:get_disco_items(stanza));
elseif xmlns == "http://jabber.org/protocol/muc#admin" then
end
elseif stanza.name == "message" and type == "groupchat" then
local from, to = stanza.attr.from, stanza.attr.to;
- local room = jid_bare(to);
local current_nick = self._jid_nick[from];
local occupant = self._occupants[current_nick];
if not occupant then -- not in room
origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
elseif occupant.role == "visitor" then
- origin.send(st.error_reply(stanza, "cancel", "forbidden"));
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
else
local from = stanza.attr.from;
stanza.attr.from = current_nick;
self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
else
stanza.attr.from = from;
- origin.send(st.error_reply(stanza, "cancel", "forbidden"));
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
end
else
self:broadcast_message(stanza, self:get_historylength() > 0);