add: added limit param to message get url to send fewer messages

This commit is contained in:
Lukian 2025-05-11 21:32:19 +02:00
parent 9052a99972
commit bd3cbc528c
3 changed files with 19 additions and 10 deletions

View file

@ -335,7 +335,7 @@ function deleteChannelMessages(connection, channel_id) {
});
}
function getMessages(connection, channel_id) {
function getMessages(connection, channel_id, limit) {
return new Promise((resolve, reject) => {
connection.query(
`SELECT messages.id, user_id, username, content, date, channels.name AS channel_name, has_replies
@ -343,8 +343,9 @@ function getMessages(connection, channel_id) {
JOIN users ON messages.user_id = users.id
JOIN channels ON messages.channel_id = channels.id
WHERE channel_id = ? AND reply_to_id IS NULL
ORDER BY date DESC`,
[channel_id],
ORDER BY date DESC
LIMIT ?`,
[channel_id, limit],
(error, result) => {
if (error) {
reject(new Error(error));