From 7b1cb23429fe5c39e85ab37ead2e21f073eeff54 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Fri, 19 Aug 2022 12:28:53 +0300 Subject: [PATCH] feat: increase and support overriding jump to message limit --- e2e/jump-to-message.test.ts | 4 ++-- package.json | 4 ++-- src/components/Channel/Channel.tsx | 8 +++----- src/context/ChannelActionContext.tsx | 2 +- yarn.lock | 10 +++++----- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/e2e/jump-to-message.test.ts b/e2e/jump-to-message.test.ts index 014976a49f..ce7994d494 100644 --- a/e2e/jump-to-message.test.ts +++ b/e2e/jump-to-message.test.ts @@ -40,7 +40,7 @@ suiteArray.forEach(([mode, story]) => { }); }); -test.describe('jump to messsage - dataset', () => { +test.describe('jump to message - dataset', () => { test('only the current message set is loaded', async ({ controller, page, user }) => { await controller.openStory( 'jump-to-message--jump-in-regular-message-list', @@ -52,6 +52,6 @@ test.describe('jump to messsage - dataset', () => { page.click(controlsButtonSelector), ]); - await user.sees(MessageList).hasLength(26); + await user.sees(MessageList).hasLength(100 + 1); }); }); diff --git a/package.json b/package.json index e548b17553..7efa9162af 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "peerDependencies": { "react": "^18.0.0 || ^17.0.0 || ^16.8.0", "react-dom": "^18.0.0 || ^17.0.0 || ^16.8.0", - "stream-chat": "^6.7.3" + "stream-chat": "^6.9.0" }, "files": [ "dist", @@ -167,7 +167,7 @@ "rollup-plugin-visualizer": "^4.2.0", "semantic-release": "^19.0.2", "semantic-release-cli": "^5.4.4", - "stream-chat": "^6.7.3", + "stream-chat": "^6.9.0", "style-loader": "^2.0.0", "ts-jest": "^26.5.1", "tslib": "2.3.0", diff --git a/src/components/Channel/Channel.tsx b/src/components/Channel/Channel.tsx index d17819eac1..525a3756c8 100644 --- a/src/components/Channel/Channel.tsx +++ b/src/components/Channel/Channel.tsx @@ -190,8 +190,6 @@ export type ChannelProps< VirtualMessage?: ComponentContextValue['VirtualMessage']; }; -const JUMP_MESSAGE_PAGE_SIZE = 25; - const UnMemoizedChannel = < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, V extends CustomTrigger = CustomTrigger @@ -526,16 +524,16 @@ const ChannelInner = < return queryResponse.messages.length; }; - const jumpToMessage = async (messageId: string) => { + const jumpToMessage = async (messageId: string, messageLimit = 100) => { dispatch({ loadingMore: true, type: 'setLoadingMore' }); - await channel.state.loadMessageIntoState(messageId); + await channel.state.loadMessageIntoState(messageId, undefined, messageLimit); /** * if the message we are jumping to has less than half of the page size older messages, * we have jumped to the beginning of the channel. */ const indexOfMessage = channel.state.messages.findIndex((message) => message.id === messageId); - const hasMoreMessages = indexOfMessage >= Math.floor(JUMP_MESSAGE_PAGE_SIZE / 2); + const hasMoreMessages = indexOfMessage >= Math.floor(messageLimit / 2); loadMoreFinished(hasMoreMessages, channel.state.messages); dispatch({ diff --git a/src/context/ChannelActionContext.tsx b/src/context/ChannelActionContext.tsx index 45d2e9e65d..793bf65050 100644 --- a/src/context/ChannelActionContext.tsx +++ b/src/context/ChannelActionContext.tsx @@ -49,7 +49,7 @@ export type ChannelActionContextValue< message: UpdatedMessage, ) => Promise | void>; jumpToLatestMessage: () => Promise; - jumpToMessage: (messageId: string) => Promise; + jumpToMessage: (messageId: string, limit?: number) => Promise; loadMore: (limit?: number) => Promise; loadMoreNewer: (limit?: number) => Promise; loadMoreThread: () => Promise; diff --git a/yarn.lock b/yarn.lock index 221441b40f..a78b34c585 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3207,7 +3207,7 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008" integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q== -"@types/mdast@^3.0.0", "@types/mdast@^3.0.3", "@types/mdast@^3.0.10": +"@types/mdast@^3.0.0", "@types/mdast@^3.0.10", "@types/mdast@^3.0.3": version "3.0.10" resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.10.tgz#4724244a82a4598884cbbe9bcfd73dff927ee8af" integrity sha512-W864tg/Osz1+9f4lrGTZpCSO5/z4608eUp19tbozkq2HJK6i3z1kT0H9tlADXuYIb1YYOBByU4Jsqkk75q48qA== @@ -16050,10 +16050,10 @@ stream-browserify@^2.0.1: inherits "~2.0.1" readable-stream "^2.0.2" -stream-chat@^6.7.3: - version "6.7.3" - resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-6.7.3.tgz#5d3a0f1678c5bcac6241e15882230bf71b56d06d" - integrity sha512-O2gBocLG4rgAMOHq4PlXDkexfgkXFp1ZEGF+W3lllFXBC2/e52KbbojQNMhyoQPv82n2JQCGpkychUP4jdpn9Q== +stream-chat@^6.9.0: + version "6.9.0" + resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-6.9.0.tgz#cc5c8e68849b36a891178b6b39cd150fc8a69ddf" + integrity sha512-GERt6ohbMucs1mOFY6xoU3p9gl0oEQieod09hSiaRnHG++LP//SQafYlSyE9v2n368VQcc6OSiP5tAinBWafJw== dependencies: "@babel/runtime" "^7.16.3" "@types/jsonwebtoken" "^8.5.6"