Prosody modules: fix lua 5.3/5.4 compatibility:

Lua 5.3 comes with new integers type, and can fail if floats are used
where integers are wanted.
This commit is contained in:
John Livingston 2024-09-10 17:58:12 +02:00
parent 5018d04b78
commit 5566f4b6cf
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
2 changed files with 7 additions and 7 deletions

View File

@ -88,7 +88,7 @@ local function handle_broadcast_message(event)
end end
local id = stanza.attr.id; local id = stanza.attr.id;
if not id then if not id then
-- message should alway have an id, but just in case... -- message should always have an id, but just in case...
module:log("warn", "Message has no id, wont delay it."); module:log("warn", "Message has no id, wont delay it.");
return; return;
end end
@ -106,7 +106,7 @@ local function handle_broadcast_message(event)
if stanza.attr.from then if stanza.attr.from then
local from_occupant = room:get_occupant_by_nick(stanza.attr.from); local from_occupant = room:get_occupant_by_nick(stanza.attr.from);
if from_occupant and valid_roles[from_occupant.role or "none"] < moderator_role_value then if from_occupant and valid_roles[from_occupant.role or "none"] < moderator_role_value then
module:log("debug", "Message %s / %s must be sent separatly to it initialior %s.", id, stanza_id, delay, stanza.attr.from); module:log("debug", "Message %s / %s must be sent separatly to it initiator %s.", id, stanza_id, delay, stanza.attr.from);
room:route_to_occupant(from_occupant, stanza); room:route_to_occupant(from_occupant, stanza);
end end
end end
@ -114,7 +114,7 @@ local function handle_broadcast_message(event)
-- adding a tag, so that moderators can know that this message is delayed. -- adding a tag, so that moderators can know that this message is delayed.
stanza:tag(moderation_delay_tag, { stanza:tag(moderation_delay_tag, {
delay = "" .. delay; delay = "" .. delay;
waiting = string.format("%i", get_time() + delay); waiting = string.format("%i", math.floor(get_time() + delay));
}):up(); }):up();
-- then, sending to moderators (and only moderators): -- then, sending to moderators (and only moderators):

View File

@ -72,7 +72,7 @@ local function end_current_poll (room)
end end
local function schedule_poll_end (room_jid, timestamp) local function schedule_poll_end (room_jid, timestamp)
local delay = timestamp - get_time(); local delay = timestamp - math.floor(get_time());
if delay <= 0 then if delay <= 0 then
delay = 1; delay = 1;
end end
@ -101,7 +101,7 @@ local function create_poll(room, fields, occupant)
module:log("debug", "Creating a new poll for room %s, by %s", room.jid, occupant.bare_jid); module:log("debug", "Creating a new poll for room %s, by %s", room.jid, occupant.bare_jid);
room._data.current_poll = fields; room._data.current_poll = fields;
room._data.current_poll.poll_id = id.short(); room._data.current_poll.poll_id = id.short();
room._data.current_poll.end_timestamp = get_time() + (60 * fields["muc#roompoll_duration"]); room._data.current_poll.end_timestamp = math.floor(get_time()) + (60 * fields["muc#roompoll_duration"]);
room._data.current_poll.votes_by_occupant = {}; room._data.current_poll.votes_by_occupant = {};
room._data.current_poll.votes_by_choices = {}; room._data.current_poll.votes_by_choices = {};
room._data.current_poll.choices_ordered = {}; -- choices labels with numerical index, so we can have correct order room._data.current_poll.choices_ordered = {}; -- choices labels with numerical index, so we can have correct order
@ -151,7 +151,7 @@ local function handle_groupchat(event)
-- Ok, seems it is a vote. -- Ok, seems it is a vote.
if get_time() >= room._data.current_poll.end_timestamp then if math.floor(get_time()) >= room._data.current_poll.end_timestamp then
module:log("debug", "Got a vote for a finished poll, not counting it."); module:log("debug", "Got a vote for a finished poll, not counting it.");
-- Note: we keep bouncing messages a few seconds/minutes after the poll end -- Note: we keep bouncing messages a few seconds/minutes after the poll end
-- to be sure any user that send the vote too late won't expose his choice. -- to be sure any user that send the vote too late won't expose his choice.
@ -222,7 +222,7 @@ local function room_restored(event)
end end
module:log("info", "Restoring room %s with current ongoing poll.", room.jid); module:log("info", "Restoring room %s with current ongoing poll.", room.jid);
local now = get_time(); local now = math.floor(get_time());
if now >= room._data.current_poll.end_timestamp then if now >= room._data.current_poll.end_timestamp then
module:log("info", "Current poll is over for room %s, ending it", room.jid); module:log("info", "Current poll is over for room %s, ending it", room.jid);
end_current_poll(room); end_current_poll(room);