Skip to content

Commit

Permalink
fix: added missing collectionCreator prop to GroupChannelListFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Sep 10, 2022
1 parent ebe03e0 commit d06d60e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
queryCreator,
sortComparator,
onChannelDeleted,
enableCollectionWithoutLocalCache: true,
enableCollectionWithoutLocalCache: !queryCreator,
});

const _renderMessage: GroupChannelProps['MessageList']['renderMessage'] = useFreshCallback((props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
onPressChannel,
onPressCreateChannel,
queryCreator,
collectionCreator,
sortComparator = channelComparator,
renderGroupChannelPreview,
// skipTypeSelection = true,
Expand All @@ -30,8 +31,9 @@ const createGroupChannelListFragment = (initModule?: Partial<GroupChannelListMod
const { sdk, currentUser, features, markAsDeliveredWithChannel } = useSendbirdChat();
const { groupChannels, next, loading } = useGroupChannelList(sdk, currentUser?.userId, {
queryCreator,
collectionCreator,
sortComparator,
enableCollectionWithoutLocalCache: true,
enableCollectionWithoutLocalCache: !queryCreator,
});

if (features.deliveryReceiptEnabled) {
Expand Down

0 comments on commit d06d60e

Please sign in to comment.