|
1 | 1 | import React, { useCallback, useEffect, useMemo, useState } from 'react'; |
2 | 2 |
|
| 3 | +import { MessageCollection, MessageFilter } from '@sendbird/chat/groupChannel'; |
3 | 4 | import { ReplyType } from '@sendbird/chat/message'; |
4 | 5 | import { Box } from '@sendbird/uikit-react-native-foundation'; |
5 | 6 | import { useGroupChannelMessages } from '@sendbird/uikit-tools'; |
| 7 | +import type { SendbirdFileMessage, SendbirdGroupChannel, SendbirdUserMessage } from '@sendbird/uikit-utils'; |
6 | 8 | import { |
7 | 9 | NOOP, |
8 | 10 | PASS, |
9 | | - SendbirdFileMessage, |
10 | | - SendbirdGroupChannel, |
11 | | - SendbirdUserMessage, |
12 | 11 | confirmAndMarkAsRead, |
13 | 12 | messageComparator, |
14 | 13 | useFreshCallback, |
@@ -52,9 +51,10 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G |
52 | 51 | onBeforeUpdateFileMessage = PASS, |
53 | 52 | channel, |
54 | 53 | keyboardAvoidOffset, |
55 | | - collectionCreator, |
56 | 54 | sortComparator = messageComparator, |
57 | 55 | flatListProps, |
| 56 | + messageListQueryParams, |
| 57 | + collectionCreator, |
58 | 58 | }) => { |
59 | 59 | const { playerService, recorderService } = usePlatformService(); |
60 | 60 | const { sdk, currentUser, sbOptions } = useSendbirdChat(); |
@@ -96,7 +96,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G |
96 | 96 | }, |
97 | 97 | onChannelDeleted, |
98 | 98 | onCurrentUserBanned: onChannelDeleted, |
99 | | - collectionCreator, |
| 99 | + collectionCreator: getCollectionCreator(channel, messageListQueryParams, collectionCreator), |
100 | 100 | sortComparator, |
101 | 101 | markAsRead: confirmAndMarkAsRead, |
102 | 102 | replyType, |
@@ -260,4 +260,20 @@ function shouldRenderInput(channel: SendbirdGroupChannel) { |
260 | 260 | return true; |
261 | 261 | } |
262 | 262 |
|
| 263 | +function getCollectionCreator( |
| 264 | + channel: SendbirdGroupChannel, |
| 265 | + messageListQueryParams?: GroupChannelProps['Fragment']['messageListQueryParams'], |
| 266 | + deprecatedCreatorProp?: () => MessageCollection, |
| 267 | +) { |
| 268 | + if (!messageListQueryParams && deprecatedCreatorProp) return deprecatedCreatorProp; |
| 269 | + |
| 270 | + return (defaultParams: GroupChannelProps['Fragment']['messageListQueryParams']) => { |
| 271 | + const params = { ...defaultParams, ...messageListQueryParams }; |
| 272 | + return channel.createMessageCollection({ |
| 273 | + ...params, |
| 274 | + filter: new MessageFilter(params), |
| 275 | + }); |
| 276 | + }; |
| 277 | +} |
| 278 | + |
263 | 279 | export default createGroupChannelFragment; |
0 commit comments