Comparison

plugins/muc/muc.lib.lua @ 8793:05a3275b6873

MUC: Allow the number of messages sent by default to be configured (fixes #397)
author Matthew Wild <mwild1@gmail.com>
date Wed, 16 May 2018 12:17:06 +0100
parent 8792:c2b99fa134b3
child 8794:0e2c1c4d4f78
child 8795:aaff40ec7001
comparison
equal deleted inserted replaced
8792:c2b99fa134b3 8793:05a3275b6873
169 169
170 local maxchars = history_tag and tonumber(history_tag.attr.maxchars); 170 local maxchars = history_tag and tonumber(history_tag.attr.maxchars);
171 if maxchars then maxchars = math.floor(maxchars); end 171 if maxchars then maxchars = math.floor(maxchars); end
172 172
173 local maxstanzas = math.floor(history_tag and tonumber(history_tag.attr.maxstanzas) or #history); 173 local maxstanzas = math.floor(history_tag and tonumber(history_tag.attr.maxstanzas) or #history);
174 if not history_tag then maxstanzas = 20; end 174 if not history_tag then maxstanzas = self._data.default_history_messages; end
175 175
176 local seconds = history_tag and tonumber(history_tag.attr.seconds); 176 local seconds = history_tag and tonumber(history_tag.attr.seconds);
177 if seconds then seconds = datetime.datetime(os.time() - math.floor(seconds)); end 177 if seconds then seconds = datetime.datetime(os.time() - math.floor(seconds)); end
178 178
179 local since = history_tag and history_tag.attr.since; 179 local since = history_tag and history_tag.attr.since;
356 if length == default_history_length then 356 if length == default_history_length then
357 length = nil; 357 length = nil;
358 end 358 end
359 self._data.history_length = length; 359 self._data.history_length = length;
360 end 360 end
361
362 -- Fix for clients who don't support XEP-0045 correctly
363 -- Default number of history messages the room returns
364 function room_mt:get_defaulthistorymessages()
365 return self._data.default_history_messages or default_history_length;
366 end
367 function room_mt:set_defaulthistorymessages(number)
368 number = math.min(tonumber(number) or default_history_length, self._data.history_length);
369 if number == default_history_length then
370 number = nil;
371 end
372 self._data.default_history_messages = number;
373 end
374
361 375
362 376
363 local valid_whois = { moderators = true, anyone = true }; 377 local valid_whois = { moderators = true, anyone = true };
364 378
365 function room_mt:set_whois(whois) 379 function room_mt:set_whois(whois)
696 { 710 {
697 name = 'muc#roomconfig_historylength', 711 name = 'muc#roomconfig_historylength',
698 type = 'text-single', 712 type = 'text-single',
699 label = 'Maximum Number of History Messages Returned by Room', 713 label = 'Maximum Number of History Messages Returned by Room',
700 value = tostring(self:get_historylength()) 714 value = tostring(self:get_historylength())
715 },
716 {
717 name = 'muc#roomconfig_defaulthistorymessages',
718 type = 'text-single',
719 label = 'Default Number of History Messages Returned by Room',
720 value = tostring(self:get_defaulthistorymessages())
701 } 721 }
702 }); 722 });
703 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; 723 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form;
704 end 724 end
705 725
744 handle_option("moderated", "muc#roomconfig_moderatedroom"); 764 handle_option("moderated", "muc#roomconfig_moderatedroom");
745 handle_option("members_only", "muc#roomconfig_membersonly"); 765 handle_option("members_only", "muc#roomconfig_membersonly");
746 handle_option("public", "muc#roomconfig_publicroom"); 766 handle_option("public", "muc#roomconfig_publicroom");
747 handle_option("changesubject", "muc#roomconfig_changesubject"); 767 handle_option("changesubject", "muc#roomconfig_changesubject");
748 handle_option("historylength", "muc#roomconfig_historylength"); 768 handle_option("historylength", "muc#roomconfig_historylength");
769 handle_option("defaulthistorymessages", "muc#roomconfig_defaulthistorymessages");
749 handle_option("whois", "muc#roomconfig_whois", valid_whois); 770 handle_option("whois", "muc#roomconfig_whois", valid_whois);
750 handle_option("password", "muc#roomconfig_roomsecret"); 771 handle_option("password", "muc#roomconfig_roomsecret");
751 772
752 if self.save then self:save(true); end 773 if self.save then self:save(true); end
753 if self.locked then 774 if self.locked then