diff --git a/src/api/routes/users/#user_id/messages.ts b/src/api/routes/users/#user_id/messages.ts index 9ce0b3699..717bca96d 100644 --- a/src/api/routes/users/#user_id/messages.ts +++ b/src/api/routes/users/#user_id/messages.ts @@ -19,7 +19,7 @@ import { route } from "@spacebar/api"; import { Config, Message, User } from "@spacebar/util"; import { Request, Response, Router } from "express"; -import { DmMessagesResponseSchema } from "@spacebar/schemas" +import { DmMessagesResponseSchema } from "@spacebar/schemas"; const router = Router({ mergeParams: true }); router.get( @@ -42,7 +42,7 @@ router.get( await Message.find({ where: { channel_id: channel?.id }, order: { timestamp: "DESC" }, - take: Math.clamp(req.query.limit ? Number(req.query.limit) : 50, 1, Config.get().limits.message.maxPreloadCount), + take: Math.min(Math.max(req.query.limit ? Number(req.query.limit) : 50, 1), Config.get().limits.message.maxPreloadCount), }) ).filter((x) => x !== null) as Message[]; diff --git a/src/util/util/extensions/Math.test.ts b/src/util/util/extensions/Math.test.ts index 5f112dc0a..e69de29bb 100644 --- a/src/util/util/extensions/Math.test.ts +++ b/src/util/util/extensions/Math.test.ts @@ -1,19 +0,0 @@ -import moduleAlias from "module-alias"; -moduleAlias(); -import './Math'; -import { describe, it } from 'node:test'; -import assert from 'node:assert/strict'; - -describe("Math extensions", () => { - - it("clamp", async () => { - assert.strictEqual(Math.clamp(5, 1, 10), 5); - assert.strictEqual(Math.clamp(0, 1, 10), 1); - assert.strictEqual(Math.clamp(15, 1, 10), 10); - assert.strictEqual(Math.clamp(-5, -10, -1), -5); - assert.strictEqual(Math.clamp(-15, -10, -1), -10); - assert.strictEqual(Math.clamp(-0.5, -1, 0), -0.5); - assert.strictEqual(Math.clamp(1.5, 1, 2), 1.5); - }); - -}); \ No newline at end of file diff --git a/src/util/util/extensions/Math.ts b/src/util/util/extensions/Math.ts index a5bd80c30..e69de29bb 100644 --- a/src/util/util/extensions/Math.ts +++ b/src/util/util/extensions/Math.ts @@ -1,31 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2025 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -declare global { - interface Math { - clamp(value: number, min: number, max: number): number; - } -} - -export function mathClamp(value: number, min: number, max: number): number { - return Math.min(Math.max(value, min), max); -} - -// register extensions -if (!Math.clamp) - Math.clamp = mathClamp; \ No newline at end of file diff --git a/src/util/util/extensions/index.ts b/src/util/util/extensions/index.ts index 6d9ed8de1..afd6c0b35 100644 --- a/src/util/util/extensions/index.ts +++ b/src/util/util/extensions/index.ts @@ -1,4 +1,3 @@ export * from "./Array"; -export * from "./Math"; export * from "./Url"; export * from "./String";