Comparison

plugins/muc/muc.lib.lua @ 4528:875b90d5ce0f

muc - implement per channel history limits - allow configuration via channel settings - store the settings for permanent channels - honor muc max_history_messages from the config as upper limit - only broadcast_message with historic = true if history_length is > 0
author Markus Kötter <koetter@rrzn-hiwi.uni-hannover.de>
date Fri, 13 Apr 2012 21:23:26 +0200
parent 4424:1cbf3744300c
child 4766:1d2646b63084
comparison
equal deleted inserted replaced
4517:2e274e088ddc 4528:875b90d5ce0f
136 local chars = #tostring(stanza); 136 local chars = #tostring(stanza);
137 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203 137 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203
138 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) 138 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
139 local entry = { stanza = stanza, stamp = stamp }; 139 local entry = { stanza = stanza, stamp = stamp };
140 t_insert(history, entry); 140 t_insert(history, entry);
141 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end 141 while #history > self._data.history_length do t_remove(history, 1) end
142 end 142 end
143 end 143 end
144 function room_mt:broadcast_except_nick(stanza, nick) 144 function room_mt:broadcast_except_nick(stanza, nick)
145 for rnick, occupant in pairs(self._occupants) do 145 for rnick, occupant in pairs(self._occupants) do
146 if rnick ~= nick then 146 if rnick ~= nick then
337 end 337 end
338 end 338 end
339 function room_mt:get_changesubject() 339 function room_mt:get_changesubject()
340 return self._data.changesubject; 340 return self._data.changesubject;
341 end 341 end
342 function room_mt:get_historylength()
343 return self._data.history_length
344 end
345 function room_mt:set_historylength(length)
346 if tonumber(length) == nil then
347 return
348 end
349 length = tonumber(length);
350 log("debug", "max_history_length %s", self._data.max_history_length or "nil");
351 if self._data.max_history_length and length > self._data.max_history_length then
352 length = self._data.max_history_length
353 end
354 self._data.history_length = length;
355 end
356
342 357
343 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc 358 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc
344 local from, to = stanza.attr.from, stanza.attr.to; 359 local from, to = stanza.attr.from, stanza.attr.to;
345 local room = jid_bare(to); 360 local room = jid_bare(to);
346 local current_nick = self._jid_nick[from]; 361 local current_nick = self._jid_nick[from];
606 { 621 {
607 name = 'muc#roomconfig_membersonly', 622 name = 'muc#roomconfig_membersonly',
608 type = 'boolean', 623 type = 'boolean',
609 label = 'Make Room Members-Only?', 624 label = 'Make Room Members-Only?',
610 value = self:is_members_only() 625 value = self:is_members_only()
626 },
627 {
628 name = 'muc#roomconfig_historylength',
629 type = 'text-single',
630 label = 'Maximum Number of History Messages Returned by Room',
631 value = tostring(self:get_historylength())
611 } 632 }
612 }); 633 });
613 end 634 end
614 635
615 local valid_whois = { 636 local valid_whois = {
657 678
658 local changesubject = fields['muc#roomconfig_changesubject']; 679 local changesubject = fields['muc#roomconfig_changesubject'];
659 dirty = dirty or (self:get_changesubject() ~= (not changesubject and true or nil)) 680 dirty = dirty or (self:get_changesubject() ~= (not changesubject and true or nil))
660 module:log('debug', 'changesubject=%s', changesubject and "true" or "false") 681 module:log('debug', 'changesubject=%s', changesubject and "true" or "false")
661 682
683 local historylength = fields['muc#roomconfig_historylength'];
684 dirty = dirty or (self:get_historylength() ~= (historylength and true or nil))
685 module:log('debug', 'historylength=%s', historylength)
686
687
662 local whois = fields['muc#roomconfig_whois']; 688 local whois = fields['muc#roomconfig_whois'];
663 if not valid_whois[whois] then 689 if not valid_whois[whois] then
664 origin.send(st.error_reply(stanza, 'cancel', 'bad-request', "Invalid value for 'whois'")); 690 origin.send(st.error_reply(stanza, 'cancel', 'bad-request', "Invalid value for 'whois'"));
665 return; 691 return;
666 end 692 end
675 self:set_moderated(moderated); 701 self:set_moderated(moderated);
676 self:set_members_only(membersonly); 702 self:set_members_only(membersonly);
677 self:set_persistent(persistent); 703 self:set_persistent(persistent);
678 self:set_hidden(not public); 704 self:set_hidden(not public);
679 self:set_changesubject(changesubject); 705 self:set_changesubject(changesubject);
706 self:set_historylength(historylength);
680 707
681 if self.save then self:save(true); end 708 if self.save then self:save(true); end
682 origin.send(st.reply(stanza)); 709 origin.send(st.reply(stanza));
683 710
684 if dirty or whois_changed then 711 if dirty or whois_changed then
846 else 873 else
847 stanza.attr.from = from; 874 stanza.attr.from = from;
848 origin.send(st.error_reply(stanza, "cancel", "forbidden")); 875 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
849 end 876 end
850 else 877 else
851 self:broadcast_message(stanza, true); 878 self:broadcast_message(stanza, self:get_historylength() > 0);
852 end 879 end
853 stanza.attr.from = from; 880 stanza.attr.from = from;
854 end 881 end
855 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then 882 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
856 local current_nick = self._jid_nick[stanza.attr.from]; 883 local current_nick = self._jid_nick[stanza.attr.from];
1100 jid = jid; 1127 jid = jid;
1101 _jid_nick = {}; 1128 _jid_nick = {};
1102 _occupants = {}; 1129 _occupants = {};
1103 _data = { 1130 _data = {
1104 whois = 'moderators'; 1131 whois = 'moderators';
1105 history_length = (config and config.history_length); 1132 history_length = (config and config.max_history_length) or default_history_length;
1133 max_history_length = (config and config.max_history_length) or default_history_length;
1106 }; 1134 };
1107 _affiliations = {}; 1135 _affiliations = {};
1108 }, room_mt); 1136 }, room_mt);
1109 end 1137 end
1110 1138