Skip to content

Commit ea06673

Browse files
committed
chore: introduced a new messageListQueryParams
1 parent 2a8966e commit ea06673

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

packages/uikit-react-native/src/domain/groupChannel/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type React from 'react';
22
import type { FlatList } from 'react-native';
33

4+
import type { MessageCollectionParams, MessageFilterParams } from '@sendbird/chat/groupChannel';
45
import type { UseGroupChannelMessagesOptions } from '@sendbird/uikit-chat-hooks';
56
import type {
67
OnBeforeHandler,
@@ -20,6 +21,7 @@ import type { ChannelMessageListProps } from '../../components/ChannelMessageLis
2021
import type { CommonComponent } from '../../types';
2122
import type { PubSub } from '../../utils/pubsub';
2223

24+
export type MessageListQueryParamsType = Omit<MessageCollectionParams, 'filter'> & MessageFilterParams;
2325
export interface GroupChannelProps {
2426
Fragment: {
2527
channel: SendbirdGroupChannel;
@@ -43,9 +45,19 @@ export interface GroupChannelProps {
4345
keyboardAvoidOffset?: GroupChannelProps['Provider']['keyboardAvoidOffset'];
4446
flatListProps?: GroupChannelProps['MessageList']['flatListProps'];
4547
sortComparator?: UseGroupChannelMessagesOptions['sortComparator'];
46-
collectionCreator?: UseGroupChannelMessagesOptions['collectionCreator'];
4748

4849
searchItem?: GroupChannelProps['MessageList']['searchItem'];
50+
51+
/**
52+
* @description You can specify the query parameters for the message list.
53+
* @example
54+
* ```
55+
* <GroupChannelFragment messageListQueryParams={{ prevResultLimit: 20, customTypesFilter: ['filter'] }} />
56+
* ```
57+
* */
58+
messageListQueryParams?: MessageListQueryParamsType;
59+
/** @deprecated Please use `messageListQueryParams` instead */
60+
collectionCreator?: UseGroupChannelMessagesOptions['collectionCreator'];
4961
};
5062
Header: {
5163
shouldHideRight: () => boolean;

packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
22

3+
import { MessageCollection, MessageFilter } from '@sendbird/chat/groupChannel';
34
import { ReplyType } from '@sendbird/chat/message';
45
import { Box } from '@sendbird/uikit-react-native-foundation';
56
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
7+
import type { SendbirdFileMessage, SendbirdGroupChannel, SendbirdUserMessage } from '@sendbird/uikit-utils';
68
import {
79
NOOP,
810
PASS,
9-
SendbirdFileMessage,
10-
SendbirdGroupChannel,
11-
SendbirdUserMessage,
1211
confirmAndMarkAsRead,
1312
messageComparator,
1413
useFreshCallback,
@@ -52,9 +51,10 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
5251
onBeforeUpdateFileMessage = PASS,
5352
channel,
5453
keyboardAvoidOffset,
55-
collectionCreator,
5654
sortComparator = messageComparator,
5755
flatListProps,
56+
messageListQueryParams,
57+
collectionCreator,
5858
}) => {
5959
const { playerService, recorderService } = usePlatformService();
6060
const { sdk, currentUser, sbOptions } = useSendbirdChat();
@@ -96,7 +96,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
9696
},
9797
onChannelDeleted,
9898
onCurrentUserBanned: onChannelDeleted,
99-
collectionCreator,
99+
collectionCreator: getCollectionCreator(channel, messageListQueryParams, collectionCreator),
100100
sortComparator,
101101
markAsRead: confirmAndMarkAsRead,
102102
replyType,
@@ -260,4 +260,20 @@ function shouldRenderInput(channel: SendbirdGroupChannel) {
260260
return true;
261261
}
262262

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+
263279
export default createGroupChannelFragment;

sample/src/screens/uikit/groupChannel/GroupChannelScreen.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ const GroupChannelScreen = () => {
9797
// Navigate to group channel settings
9898
navigation.push(Routes.GroupChannelSettings, params);
9999
}}
100+
// messageListQueryParams={{
101+
// prevResultLimit: 20,
102+
// customTypesFilter: ['filter'],
103+
// }}
100104
/>
101105
);
102106
};

0 commit comments

Comments
 (0)