Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): show 25 unread messages per channel in the inbox (#1729)

Hampusd148b4e5b780
diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.json
index f08c3e25e..eb7876bbd 100644
--- a/fluxer_api/src/api/openapi/openapi.json
+++ b/fluxer_api/src/api/openapi/openapi.json
@@ -27402,9 +27402,9 @@
"limit": {
"type": "integer",
"minimum": 1,
- "maximum": 25,
+ "maximum": 50,
"format": "int32",
- "description": "Number of messages to return for this channel (1-25)"
+ "description": "Number of messages to return for this channel (1-50)"
},
"before": {"$ref": "#/components/schemas/SnowflakeType"},
"after": {"$ref": "#/components/schemas/SnowflakeType"},
diff --git a/fluxer_app/src/features/app/components/floating/UnreadChannelsContent.tsx b/fluxer_app/src/features/app/components/floating/UnreadChannelsContent.tsx
index 33fdbdf21..ce5cdf7de 100644
--- a/fluxer_app/src/features/app/components/floating/UnreadChannelsContent.tsx
+++ b/fluxer_app/src/features/app/components/floating/UnreadChannelsContent.tsx
@@ -3,6 +3,10 @@
import Accessibility from '@app/features/accessibility/state/Accessibility';
import {mergeFrozenUnreadOrder} from '@app/features/app/components/floating/UnreadChannelOrder';
import styles from '@app/features/app/components/floating/UnreadChannelsContent.module.css';
+import {
+ BULK_PREVIEW_CHANNEL_BATCH_SIZE,
+ UNREAD_PREVIEW_MESSAGE_LIMIT,
+} from '@app/features/app/components/floating/UnreadPreviewBudget';
import previewStyles from '@app/features/app/components/shared/MessagePreview.module.css';
import {Endpoints} from '@app/features/app/constants/Endpoints';
import {renderChannelStream} from '@app/features/channel/components/ChannelMessageStream';
@@ -131,8 +135,6 @@ interface ChannelPreviewData {
const INITIAL_VISIBLE_CHANNELS = 10;
const LOAD_MORE_CHUNK = 10;
-const UNREAD_PREVIEW_MESSAGE_LIMIT = 5;
-const BULK_PREVIEW_CHANNEL_BATCH_SIZE = 10;
interface CacheEntry {
cacheKey: string;
diff --git a/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.test.ts b/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.test.ts
new file mode 100644
index 000000000..d083f5ef8
--- /dev/null
+++ b/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.test.ts
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {
+ BULK_PREVIEW_CHANNEL_BATCH_SIZE,
+ UNREAD_PREVIEW_MESSAGE_LIMIT,
+} from '@app/features/app/components/floating/UnreadPreviewBudget';
+import {BulkMessageFetchRequest} from '@fluxer/schema/src/domains/message/MessageRequestSchemas';
+import {describe, expect, it} from 'vitest';
+
+const buildBatch = (limit: number) => ({
+ requests: Array.from({length: BULK_PREVIEW_CHANNEL_BATCH_SIZE}, (_, index) => ({
+ channel_id: String(1000000000000000000n + BigInt(index)),
+ limit,
+ })),
+});
+
+describe('unread preview fetch budget', () => {
+ it('keeps the anchored window inside the bulk fetch schema', () => {
+ expect(() => BulkMessageFetchRequest.parse(buildBatch(UNREAD_PREVIEW_MESSAGE_LIMIT * 2))).not.toThrow();
+ });
+
+ it('keeps the unanchored window inside the bulk fetch schema', () => {
+ expect(() => BulkMessageFetchRequest.parse(buildBatch(UNREAD_PREVIEW_MESSAGE_LIMIT))).not.toThrow();
+ });
+
+ it('rejects a batch one channel wider than the client sends', () => {
+ const oversized = buildBatch(UNREAD_PREVIEW_MESSAGE_LIMIT * 2);
+ oversized.requests.push({channel_id: '1000000000000000099', limit: UNREAD_PREVIEW_MESSAGE_LIMIT * 2});
+ expect(() => BulkMessageFetchRequest.parse(oversized)).toThrow();
+ });
+});
diff --git a/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.ts b/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.ts
new file mode 100644
index 000000000..6affc98f4
--- /dev/null
+++ b/fluxer_app/src/features/app/components/floating/UnreadPreviewBudget.ts
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+export const UNREAD_PREVIEW_MESSAGE_LIMIT = 25;
+export const BULK_PREVIEW_CHANNEL_BATCH_SIZE = 5;
diff --git a/packages/schema/src/domains/message/MessageRequestSchemas.ts b/packages/schema/src/domains/message/MessageRequestSchemas.ts
index 05f2a4bfc..0a4c21e78 100644
--- a/packages/schema/src/domains/message/MessageRequestSchemas.ts
+++ b/packages/schema/src/domains/message/MessageRequestSchemas.ts
@@ -401,7 +401,7 @@ export type MessagesQuery = z.infer<typeof MessagesQuery>;
const BulkMessageFetchEntryRequest = z.object({
channel_id: SnowflakeType.describe('The ID of the channel to fetch messages from'),
- limit: z.number().int().min(1).max(25).describe('Number of messages to return for this channel (1-25)'),
+ limit: z.number().int().min(1).max(50).describe('Number of messages to return for this channel (1-50)'),
before: SnowflakeType.optional().describe('Get messages before this message ID'),
after: SnowflakeType.optional().describe('Get messages after this message ID'),
around: SnowflakeType.optional().describe('Get messages around this message ID'),