Skip to content

Commit

Permalink
Merge pull request #161 from sendbird/chore/new-list-params
Browse files Browse the repository at this point in the history
chore(CLNP-2179): introduced new list query params
  • Loading branch information
bang9 authored Feb 2, 2024
2 parents 58c79b3 + ea06673 commit a0f48aa
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { UseGroupChannelList } from '../../types';
import { useGroupChannelListWithCollection } from './useGroupChannelListWithCollection';
import { useGroupChannelListWithQuery } from './useGroupChannelListWithQuery';

/**
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
* */
export const useGroupChannelList: UseGroupChannelList = (sdk, userId, options) => {
if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) {
if (options?.queryCreator) Logger.warn('`queryCreator` is ignored, please use `collectionCreator` instead.');
Expand Down
2 changes: 2 additions & 0 deletions packages/uikit-chat-hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface CustomBidirectionalQueryInterface<Data> {
}

/**
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
*
* @interface UseGroupChannelList
* @description interface for group channel list hook
* */
Expand Down
2 changes: 1 addition & 1 deletion packages/uikit-react-native/__template__/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ export interface __domain__Module {
StatusLoading: CommonComponent;
}

export type __domain__Fragment = CommonComponent<__domain__Props['Fragment']>;
export type __domain__Fragment = React.FC<__domain__Props['Fragment']>;
16 changes: 14 additions & 2 deletions packages/uikit-react-native/src/domain/groupChannel/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type React from 'react';
import type { FlatList } from 'react-native';

import type { MessageCollectionParams, MessageFilterParams } from '@sendbird/chat/groupChannel';
import type { UseGroupChannelMessagesOptions } from '@sendbird/uikit-chat-hooks';
import type {
OnBeforeHandler,
Expand All @@ -20,6 +21,7 @@ import type { ChannelMessageListProps } from '../../components/ChannelMessageLis
import type { CommonComponent } from '../../types';
import type { PubSub } from '../../utils/pubsub';

export type MessageListQueryParamsType = Omit<MessageCollectionParams, 'filter'> & MessageFilterParams;
export interface GroupChannelProps {
Fragment: {
channel: SendbirdGroupChannel;
Expand All @@ -43,9 +45,19 @@ export interface GroupChannelProps {
keyboardAvoidOffset?: GroupChannelProps['Provider']['keyboardAvoidOffset'];
flatListProps?: GroupChannelProps['MessageList']['flatListProps'];
sortComparator?: UseGroupChannelMessagesOptions['sortComparator'];
collectionCreator?: UseGroupChannelMessagesOptions['collectionCreator'];

searchItem?: GroupChannelProps['MessageList']['searchItem'];

/**
* @description You can specify the query parameters for the message list.
* @example
* ```
* <GroupChannelFragment messageListQueryParams={{ prevResultLimit: 20, customTypesFilter: ['filter'] }} />
* ```
* */
messageListQueryParams?: MessageListQueryParamsType;
/** @deprecated Please use `messageListQueryParams` instead */
collectionCreator?: UseGroupChannelMessagesOptions['collectionCreator'];
};
Header: {
shouldHideRight: () => boolean;
Expand Down Expand Up @@ -169,7 +181,7 @@ export interface GroupChannelModule {
StatusLoading: CommonComponent;
}

export type GroupChannelFragment = CommonComponent<GroupChannelProps['Fragment']>;
export type GroupChannelFragment = React.FC<GroupChannelProps['Fragment']>;

export type GroupChannelPubSubContextPayload =
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export interface GroupChannelBannedUsersModule {
StatusError: CommonComponent<GroupChannelBannedUsersProps['StatusError']>;
}

export type GroupChannelBannedUsersFragment = CommonComponent<GroupChannelBannedUsersProps['Fragment']>;
export type GroupChannelBannedUsersFragment = React.FC<GroupChannelBannedUsersProps['Fragment']>;
15 changes: 13 additions & 2 deletions packages/uikit-react-native/src/domain/groupChannelList/types.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import type React from 'react';
import type { FlatListProps } from 'react-native';

import type { GroupChannelCollectionParams, GroupChannelFilterParams } from '@sendbird/chat/groupChannel';
import type { UseGroupChannelListOptions } from '@sendbird/uikit-chat-hooks';
import type { ActionMenuItem } from '@sendbird/uikit-react-native-foundation';
import type { SendbirdGroupChannel } from '@sendbird/uikit-utils';

import type { CommonComponent } from '../../types';

export type ChannelListQueryParamsType = Omit<GroupChannelCollectionParams, 'filter'> & GroupChannelFilterParams;
export interface GroupChannelListProps {
Fragment: {
onPressChannel: GroupChannelListProps['List']['onPressChannel'];
onPressCreateChannel: (channelType: GroupChannelType) => void;
renderGroupChannelPreview?: GroupChannelListProps['List']['renderGroupChannelPreview'];
skipTypeSelection?: boolean;
collectionCreator?: UseGroupChannelListOptions['collectionCreator'];
flatListProps?: GroupChannelListProps['List']['flatListProps'];
menuItemCreator?: GroupChannelListProps['List']['menuItemCreator'];
/**
* @description You can specify the query parameters for the channel list.
* @example
* ```
* <GroupChannelListFragment channelListQueryParams={{ limit: 20, includeEmpty: false }} />
* ```
* */
channelListQueryParams?: ChannelListQueryParamsType;
/** @deprecated Please use `channelListQueryParams` instead */
collectionCreator?: UseGroupChannelListOptions['collectionCreator'];
};
Header: {};
List: {
Expand Down Expand Up @@ -61,5 +72,5 @@ export interface GroupChannelListModule {
StatusLoading: CommonComponent;
}

export type GroupChannelListFragment = CommonComponent<GroupChannelListProps['Fragment']>;
export type GroupChannelListFragment = React.FC<GroupChannelListProps['Fragment']>;
export type GroupChannelType = 'GROUP' | 'SUPER_GROUP' | 'BROADCAST';
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export interface GroupChannelModerationModule {
Menu: CommonComponent<GroupChannelModerationProps['Menu']>;
}

export type GroupChannelModerationFragment = CommonComponent<GroupChannelModerationProps['Fragment']>;
export type GroupChannelModerationFragment = React.FC<GroupChannelModerationProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export interface GroupChannelMutedMembersModule {
StatusError: CommonComponent<GroupChannelMutedMembersProps['StatusError']>;
}

export type GroupChannelMutedMembersFragment = CommonComponent<GroupChannelMutedMembersProps['Fragment']>;
export type GroupChannelMutedMembersFragment = React.FC<GroupChannelMutedMembersProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export interface GroupChannelNotificationsModule {
View: CommonComponent<GroupChannelNotificationsProps['View']>;
}

export type GroupChannelNotificationsFragment = CommonComponent<GroupChannelNotificationsProps['Fragment']>;
export type GroupChannelNotificationsFragment = React.FC<GroupChannelNotificationsProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ export interface GroupChannelOperatorsModule {
StatusError: CommonComponent<GroupChannelOperatorsProps['StatusError']>;
}

export type GroupChannelOperatorsFragment = CommonComponent<GroupChannelOperatorsProps['Fragment']>;
export type GroupChannelOperatorsFragment = React.FC<GroupChannelOperatorsProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ export interface GroupChannelSettingsModule {
Menu: CommonComponent<GroupChannelSettingsProps['Menu']>;
}

export type GroupChannelSettingsFragment = CommonComponent<GroupChannelSettingsProps['Fragment']>;
export type GroupChannelSettingsFragment = React.FC<GroupChannelSettingsProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface GroupChannelMembersProps {
queryCreator?: UseUserListOptions<SendbirdMember>['queryCreator'];
};
}
export type GroupChannelMembersFragment = CommonComponent<GroupChannelMembersProps['Fragment']>;
export type GroupChannelMembersFragment = React.FC<GroupChannelMembersProps['Fragment']>;

export interface GroupChannelRegisterOperatorProps {
Fragment: {
Expand All @@ -64,4 +64,4 @@ export interface GroupChannelRegisterOperatorProps {
queryCreator?: UseUserListOptions<SendbirdMember>['queryCreator'];
};
}
export type GroupChannelRegisterOperatorFragment = CommonComponent<GroupChannelRegisterOperatorProps['Fragment']>;
export type GroupChannelRegisterOperatorFragment = React.FC<GroupChannelRegisterOperatorProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export interface MessageSearchModule {
StatusError: CommonComponent<MessageSearchProps['StatusError']>;
}

export type MessageSearchFragment = CommonComponent<MessageSearchProps['Fragment']>;
export type MessageSearchFragment = React.FC<MessageSearchProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export interface OpenChannelModule {
StatusLoading: CommonComponent;
}

export type OpenChannelFragment = CommonComponent<OpenChannelProps['Fragment']>;
export type OpenChannelFragment = React.FC<OpenChannelProps['Fragment']>;

export type OpenChannelPubSubContextPayload =
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export interface OpenChannelBannedUsersModule {
StatusError: CommonComponent<OpenChannelBannedUsersProps['StatusError']>;
}

export type OpenChannelBannedUsersFragment = CommonComponent<OpenChannelBannedUsersProps['Fragment']>;
export type OpenChannelBannedUsersFragment = React.FC<OpenChannelBannedUsersProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ export interface OpenChannelCreateModule {
StatusLoading: CommonComponent;
}

export type OpenChannelCreateFragment = CommonComponent<OpenChannelCreateProps['Fragment']>;
export type OpenChannelCreateFragment = React.FC<OpenChannelCreateProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ export interface OpenChannelListModule {
StatusError: CommonComponent<OpenChannelListProps['StatusError']>;
}

export type OpenChannelListFragment = CommonComponent<OpenChannelListProps['Fragment']>;
export type OpenChannelListFragment = React.FC<OpenChannelListProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export interface OpenChannelModerationModule {
Menu: CommonComponent<OpenChannelModerationProps['Menu']>;
}

export type OpenChannelModerationFragment = CommonComponent<OpenChannelModerationProps['Fragment']>;
export type OpenChannelModerationFragment = React.FC<OpenChannelModerationProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export interface OpenChannelMutedParticipantsModule {
StatusError: CommonComponent<OpenChannelMutedParticipantsProps['StatusError']>;
}

export type OpenChannelMutedParticipantsFragment = CommonComponent<OpenChannelMutedParticipantsProps['Fragment']>;
export type OpenChannelMutedParticipantsFragment = React.FC<OpenChannelMutedParticipantsProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ export interface OpenChannelOperatorsModule {
StatusError: CommonComponent<OpenChannelOperatorsProps['StatusError']>;
}

export type OpenChannelOperatorsFragment = CommonComponent<OpenChannelOperatorsProps['Fragment']>;
export type OpenChannelOperatorsFragment = React.FC<OpenChannelOperatorsProps['Fragment']>;
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ export interface OpenChannelSettingsModule {
Menu: CommonComponent<OpenChannelSettingsProps['Menu']>;
}

export type OpenChannelSettingsFragment = CommonComponent<OpenChannelSettingsProps['Fragment']>;
export type OpenChannelSettingsFragment = React.FC<OpenChannelSettingsProps['Fragment']>;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type React from 'react';

import type { UseUserListOptions } from '@sendbird/uikit-chat-hooks';
import type { SendbirdOpenChannel, SendbirdParticipant, SendbirdUser } from '@sendbird/uikit-utils';

import type { CommonComponent } from '../../types';
import type { UserListProps } from '../userList/types';

export interface OpenChannelParticipantsProps {
Expand All @@ -14,7 +15,7 @@ export interface OpenChannelParticipantsProps {
sortComparator?: UseUserListOptions<SendbirdUser | SendbirdParticipant>['sortComparator'];
};
}
export type OpenChannelParticipantsFragment = CommonComponent<OpenChannelParticipantsProps['Fragment']>;
export type OpenChannelParticipantsFragment = React.FC<OpenChannelParticipantsProps['Fragment']>;

export interface OpenChannelRegisterOperatorProps {
Fragment: {
Expand All @@ -27,4 +28,4 @@ export interface OpenChannelRegisterOperatorProps {
sortComparator?: UseUserListOptions<SendbirdUser | SendbirdParticipant>['sortComparator'];
};
}
export type OpenChannelRegisterOperatorFragment = CommonComponent<OpenChannelRegisterOperatorProps['Fragment']>;
export type OpenChannelRegisterOperatorFragment = React.FC<OpenChannelRegisterOperatorProps['Fragment']>;
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { MessageCollection, MessageFilter } from '@sendbird/chat/groupChannel';
import { ReplyType } from '@sendbird/chat/message';
import { Box } from '@sendbird/uikit-react-native-foundation';
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
import type { SendbirdFileMessage, SendbirdGroupChannel, SendbirdUserMessage } from '@sendbird/uikit-utils';
import {
NOOP,
PASS,
SendbirdFileMessage,
SendbirdGroupChannel,
SendbirdUserMessage,
confirmAndMarkAsRead,
messageComparator,
useFreshCallback,
Expand Down Expand Up @@ -52,9 +51,10 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
onBeforeUpdateFileMessage = PASS,
channel,
keyboardAvoidOffset,
collectionCreator,
sortComparator = messageComparator,
flatListProps,
messageListQueryParams,
collectionCreator,
}) => {
const { playerService, recorderService } = usePlatformService();
const { sdk, currentUser, sbOptions } = useSendbirdChat();
Expand Down Expand Up @@ -96,7 +96,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
},
onChannelDeleted,
onCurrentUserBanned: onChannelDeleted,
collectionCreator,
collectionCreator: getCollectionCreator(channel, messageListQueryParams, collectionCreator),
sortComparator,
markAsRead: confirmAndMarkAsRead,
replyType,
Expand Down Expand Up @@ -260,4 +260,20 @@ function shouldRenderInput(channel: SendbirdGroupChannel) {
return true;
}

function getCollectionCreator(
channel: SendbirdGroupChannel,
messageListQueryParams?: GroupChannelProps['Fragment']['messageListQueryParams'],
deprecatedCreatorProp?: () => MessageCollection,
) {
if (!messageListQueryParams && deprecatedCreatorProp) return deprecatedCreatorProp;

return (defaultParams: GroupChannelProps['Fragment']['messageListQueryParams']) => {
const params = { ...defaultParams, ...messageListQueryParams };
return channel.createMessageCollection({
...params,
filter: new MessageFilter(params),
});
};
}

export default createGroupChannelFragment;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';

import { useGroupChannelList } from '@sendbird/uikit-chat-hooks';
import { PASS, useAppState, useFreshCallback } from '@sendbird/uikit-utils';
import { GroupChannelCollection, GroupChannelFilter } from '@sendbird/chat/groupChannel';
import { useGroupChannelList } from '@sendbird/uikit-tools';
import { PASS, SendbirdChatSDK, confirmAndMarkAsDelivered, useAppState, useFreshCallback } from '@sendbird/uikit-utils';

import StatusComposition from '../components/StatusComposition';
import GroupChannelPreviewContainer from '../containers/GroupChannelPreviewContainer';
Expand All @@ -18,16 +19,17 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
return ({
onPressChannel,
onPressCreateChannel,
collectionCreator,
renderGroupChannelPreview,
skipTypeSelection = false,
flatListProps = {},
menuItemCreator = PASS,
channelListQueryParams,
collectionCreator,
}) => {
const { sdk, currentUser, sbOptions, markAsDeliveredWithChannel } = useSendbirdChat();
const { groupChannels, next, loading } = useGroupChannelList(sdk, currentUser?.userId, {
collectionCreator,
enableCollectionWithoutLocalCache: true,
const { sdk, sbOptions, markAsDeliveredWithChannel } = useSendbirdChat();
const { groupChannels, loadMore, initialized } = useGroupChannelList(sdk, {
collectionCreator: getCollectionCreator(sdk, channelListQueryParams, collectionCreator),
markAsDelivered: confirmAndMarkAsDelivered,
});

if (sbOptions.appInfo.deliveryReceiptEnabled) {
Expand All @@ -49,13 +51,13 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
return (
<GroupChannelListModule.Provider>
<GroupChannelListModule.Header />
<StatusComposition loading={loading} LoadingComponent={<GroupChannelListModule.StatusLoading />}>
<StatusComposition loading={!initialized} LoadingComponent={<GroupChannelListModule.StatusLoading />}>
<GroupChannelListModule.List
onPressChannel={onPressChannel}
menuItemCreator={menuItemCreator}
renderGroupChannelPreview={_renderGroupChannelPreview}
groupChannels={groupChannels}
onLoadNext={next}
onLoadNext={loadMore}
flatListProps={{
ListEmptyComponent: <GroupChannelListModule.StatusEmpty />,
contentContainerStyle: { flexGrow: 1 },
Expand All @@ -72,4 +74,20 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
};
};

function getCollectionCreator(
sdk: SendbirdChatSDK,
channelListQueryParams?: GroupChannelListProps['Fragment']['channelListQueryParams'],
deprecatedCreatorProp?: () => GroupChannelCollection,
) {
if (!channelListQueryParams && deprecatedCreatorProp) return deprecatedCreatorProp;

return (defaultParams: GroupChannelListProps['Fragment']['channelListQueryParams']) => {
const params = { ...defaultParams, ...channelListQueryParams };
return sdk.groupChannel.createGroupChannelCollection({
...params,
filter: new GroupChannelFilter(params),
});
};
}

export default createGroupChannelListFragment;
4 changes: 4 additions & 0 deletions sample/src/screens/uikit/groupChannel/GroupChannelScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const GroupChannelScreen = () => {
// Navigate to group channel settings
navigation.push(Routes.GroupChannelSettings, params);
}}
// messageListQueryParams={{
// prevResultLimit: 20,
// customTypesFilter: ['filter'],
// }}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const GroupChannelListScreen = () => {
onPressChannel={(channel) => {
navigation.navigate(Routes.GroupChannel, { channelUrl: channel.url });
}}
// channelListQueryParams={{
// includeEmpty: true,
// includeFrozen: false,
// }}
/>
);
};
Expand Down

0 comments on commit a0f48aa

Please sign in to comment.