From 38f064138ad54324a74a77a42b317018a7719f11 Mon Sep 17 00:00:00 2001 From: VelikovPetar Date: Thu, 9 Jul 2026 15:25:16 +0200 Subject: [PATCH 1/2] fix(persistence): treat thread reply pagination limit of 0 as unset `getThreadMessagesByParentId` moved thread reply pagination into SQL, which turned a `limit` of 0 into `LIMIT 0` (zero rows). The pre-SQL implementation treated 0 as "unlimited" and returned every reply, and both the backend `getReplies` endpoint (0 -> default page) and the iOS SDK (`fetchLimit` 0 -> all rows) treat 0 as unset rather than empty. Only apply the SQL `LIMIT` for a positive limit so a limit of 0 keeps returning all matching replies. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../lib/src/dao/message_dao.dart | 2 +- .../test/src/dao/message_dao_test.dart | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/stream_chat_persistence/lib/src/dao/message_dao.dart b/packages/stream_chat_persistence/lib/src/dao/message_dao.dart index dbd81aef8..691991c06 100644 --- a/packages/stream_chat_persistence/lib/src/dao/message_dao.dart +++ b/packages/stream_chat_persistence/lib/src/dao/message_dao.dart @@ -283,7 +283,7 @@ class MessageDao extends DatabaseAccessor with _$MessageDaoMi ); } - if (options != null) { + if (options != null && options.limit > 0) { query.limit(options.limit); } diff --git a/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart index bafbac2f8..93b8eff0c 100644 --- a/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart @@ -343,6 +343,26 @@ void main() { expect(replies.last.id, threadId(29)); }); + test('limit of 0 is treated as unset and returns all replies', () async { + await _prepareTestData( + cid, + threads: true, + mapAllThreadToFirstMessage: true, + count: 30, + ); + + final replies = await messageDao.getThreadMessagesByParentId( + parentId, + options: const PaginationParams(limit: 0), + ); + + // limit: 0 is treated as "unset" → no SQL LIMIT is applied → all 30 + // replies are returned in ASC order: id0..id29. + expect(replies.length, 30); + expect(replies.first.id, threadId(0)); + expect(replies.last.id, threadId(29)); + }); + test('lessThan only excludes the cursor', () async { await _prepareTestData( cid, From 776cd81912875ea9873496fe66d8f97211ee3341 Mon Sep 17 00:00:00 2001 From: VelikovPetar Date: Thu, 9 Jul 2026 15:28:52 +0200 Subject: [PATCH 2/2] docs(persistence): add changelog entry for limit=0 thread pagination fix Co-Authored-By: Claude Opus 4.8 (1M context) --- packages/stream_chat_persistence/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index 8352945c7..11a61a813 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -5,6 +5,10 @@ - Add indices on the `channel_cid` column on the `Messages`, `Members`, and `Reads` tables to improve read times on large databases. - Add indices on the `message_id` column on the `Reactions` table to improve read times on large databases. +🐞 Fixed + +- `MessageDao.getThreadMessagesByParentId` now treats a `PaginationParams.limit` of `0` as "unset" and returns all matching replies, instead of returning none. + ## 10.1.0 ✅ Added