From d06d60e76639eb1f68bfef8d63ed1f79e1d3069d Mon Sep 17 00:00:00 2001 From: bang9 Date: Sat, 10 Sep 2022 10:34:09 +0900 Subject: [PATCH] fix: added missing collectionCreator prop to GroupChannelListFragment --- .../useGroupChannelListWithCollection.ts | 17 ++++++++++++++--- .../src/channel/useGroupChannelListWithQuery.ts | 9 ++++++++- .../src/domain/groupChannelList/types.ts | 2 ++ .../fragments/createGroupChannelFragment.tsx | 2 +- .../createGroupChannelListFragment.tsx | 4 +++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithCollection.ts b/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithCollection.ts index 3e3df9875..028c6be02 100644 --- a/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithCollection.ts +++ b/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithCollection.ts @@ -22,9 +22,20 @@ const createGroupChannelListCollection = ( const passedCollection = collectionCreator?.(); if (passedCollection) return passedCollection; - const defaultCollection = sdk.GroupChannel.createGroupChannelCollection(); - const filter = new sdk.GroupChannelFilter(); - return defaultCollection.setLimit(20).setFilter(filter).build(); + const defaultOptions = { + includeEmpty: false, + limit: 20, + order: sdk.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE, + }; + const collectionBuilder = sdk.GroupChannel.createGroupChannelCollection(); + const groupChannelFilter = new sdk.GroupChannelFilter(); + groupChannelFilter.includeEmpty = defaultOptions.includeEmpty; + + return collectionBuilder + .setFilter(groupChannelFilter) + .setLimit(defaultOptions.limit) + .setOrder(defaultOptions.order) + .build(); }; export const useGroupChannelListWithCollection: UseGroupChannelList = (sdk, userId, options) => { diff --git a/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithQuery.ts b/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithQuery.ts index 86600c573..74b855d7c 100644 --- a/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithQuery.ts +++ b/packages/uikit-chat-hooks/src/channel/useGroupChannelListWithQuery.ts @@ -18,8 +18,15 @@ const createGroupChannelListQuery = ( const passedQuery = queryCreator?.(); if (passedQuery) return passedQuery; + const defaultOptions = { + includeEmpty: false, + limit: 20, + order: sdk.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE, + }; const defaultQuery = sdk.GroupChannel.createMyGroupChannelListQuery(); - defaultQuery.limit = 20; + defaultQuery.limit = defaultOptions.limit; + defaultQuery.order = defaultOptions.order; + defaultQuery.includeEmpty = defaultOptions.includeEmpty; return defaultQuery; }; diff --git a/packages/uikit-react-native/src/domain/groupChannelList/types.ts b/packages/uikit-react-native/src/domain/groupChannelList/types.ts index f87cef43d..380aa4811 100644 --- a/packages/uikit-react-native/src/domain/groupChannelList/types.ts +++ b/packages/uikit-react-native/src/domain/groupChannelList/types.ts @@ -27,6 +27,8 @@ export interface GroupChannelListProps { // skipTypeSelection?: boolean; /** Custom Query creator for channels query **/ queryCreator?: UseGroupChannelListOptions['queryCreator']; + /** Custom Collection creator for group channel collection **/ + collectionCreator?: UseGroupChannelListOptions['collectionCreator']; /** Sort comparator for sort channels **/ sortComparator?: UseGroupChannelListOptions['sortComparator']; /** FlatList props for GroupChannelList.List **/ diff --git a/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx b/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx index 730232637..ed92aa576 100644 --- a/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx +++ b/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx @@ -55,7 +55,7 @@ const createGroupChannelFragment = (initModule?: Partial): G queryCreator, sortComparator, onChannelDeleted, - enableCollectionWithoutLocalCache: true, + enableCollectionWithoutLocalCache: !queryCreator, }); const _renderMessage: GroupChannelProps['MessageList']['renderMessage'] = useFreshCallback((props) => { diff --git a/packages/uikit-react-native/src/fragments/createGroupChannelListFragment.tsx b/packages/uikit-react-native/src/fragments/createGroupChannelListFragment.tsx index 03768075d..af9ded815 100644 --- a/packages/uikit-react-native/src/fragments/createGroupChannelListFragment.tsx +++ b/packages/uikit-react-native/src/fragments/createGroupChannelListFragment.tsx @@ -21,6 +21,7 @@ const createGroupChannelListFragment = (initModule?: Partial