From 27dadfc964cfad4dd514754fed01d31948af0089 Mon Sep 17 00:00:00 2001 From: bang9 Date: Mon, 22 Jan 2024 12:33:36 +0900 Subject: [PATCH] chore: replaced useGroupChannelMessages --- docs-validation/package.json | 2 +- package.json | 2 +- .../channel/useGroupChannelMessages/index.ts | 3 +++ packages/uikit-chat-hooks/src/types.ts | 2 ++ packages/uikit-react-native/package.json | 4 +-- .../components/ChannelMessageList/index.tsx | 2 +- .../component/GroupChannelMessageList.tsx | 13 +++++----- .../src/domain/groupChannel/types.ts | 4 +-- .../fragments/createGroupChannelFragment.tsx | 26 ++++++++++--------- packages/uikit-utils/package.json | 2 +- sample/package.json | 2 +- yarn.lock | 16 ++++++------ 12 files changed, 43 insertions(+), 35 deletions(-) diff --git a/docs-validation/package.json b/docs-validation/package.json index 8d2aaf6f4..ebefb7770 100644 --- a/docs-validation/package.json +++ b/docs-validation/package.json @@ -15,7 +15,7 @@ "@react-native-firebase/messaging": "^14.7.0", "@react-navigation/native": "^6.0.6", "@react-navigation/native-stack": "^6.7.0", - "@sendbird/chat": "^4.9.8", + "@sendbird/chat": "^4.10.7", "react": "17.0.2", "react-native": "0.67.5", "react-native-create-thumbnail": "^1.5.1", diff --git a/package.json b/package.json index 04a384bd6..bbbf1a4ad 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ ] }, "resolutions": { - "@sendbird/chat": "4.9.10", + "@sendbird/chat": "4.10.7", "@types/react": "^18", "@types/react-native": "^0.67" } diff --git a/packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/index.ts b/packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/index.ts index 1301469d6..dfa3445c8 100644 --- a/packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/index.ts +++ b/packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/index.ts @@ -4,6 +4,9 @@ import type { UseGroupChannelMessages } from '../../types'; import { useGroupChannelMessagesWithCollection } from './useGroupChannelMessagesWithCollection'; import { useGroupChannelMessagesWithQuery } from './useGroupChannelMessagesWithQuery'; +/** + * @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package. + * */ export const useGroupChannelMessages: UseGroupChannelMessages = (sdk, channel, userId, options) => { if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) { if (options?.queryCreator) printIgnoredWarning(); diff --git a/packages/uikit-chat-hooks/src/types.ts b/packages/uikit-chat-hooks/src/types.ts index 28fe261ad..6272d0ea2 100644 --- a/packages/uikit-chat-hooks/src/types.ts +++ b/packages/uikit-chat-hooks/src/types.ts @@ -73,6 +73,8 @@ export type UseGroupChannelListOptions = { }; /** + * @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package. + * * @interface UseGroupChannelMessages * @description interface for group channel messages hook * - Receive new messages from other users & should count new messages -> append to state(newMessages) diff --git a/packages/uikit-react-native/package.json b/packages/uikit-react-native/package.json index b5f25088c..398cd17e8 100644 --- a/packages/uikit-react-native/package.json +++ b/packages/uikit-react-native/package.json @@ -61,7 +61,7 @@ "dependencies": { "@sendbird/uikit-chat-hooks": "3.3.0", "@sendbird/uikit-react-native-foundation": "3.3.0", - "@sendbird/uikit-tools": "0.0.1-alpha.42", + "@sendbird/uikit-tools": "0.0.1-alpha.57", "@sendbird/uikit-utils": "3.3.0" }, "devDependencies": { @@ -107,7 +107,7 @@ "@react-native-clipboard/clipboard": ">=1.8.5", "@react-native-community/netinfo": ">=9.3.0", "@react-native-firebase/messaging": ">=14.4.0", - "@sendbird/chat": "^4.9.8", + "@sendbird/chat": "^4.10.7", "@sendbird/react-native-scrollview-enhancer": "*", "date-fns": ">=2.28.0", "expo-av": ">=12.0.4", diff --git a/packages/uikit-react-native/src/components/ChannelMessageList/index.tsx b/packages/uikit-react-native/src/components/ChannelMessageList/index.tsx index 98315300a..c1ce82b6a 100644 --- a/packages/uikit-react-native/src/components/ChannelMessageList/index.tsx +++ b/packages/uikit-react-native/src/components/ChannelMessageList/index.tsx @@ -59,7 +59,7 @@ export type ChannelMessageListProps void; onReplyMessage?: (message: HandleableMessage) => void; // only available on group channel onDeleteMessage: (message: HandleableMessage) => Promise; - onResendFailedMessage: (failedMessage: HandleableMessage) => Promise; + onResendFailedMessage: (failedMessage: HandleableMessage) => Promise; onPressParentMessage?: (parentMessage: SendbirdMessage) => void; onPressMediaMessage?: (message: SendbirdFileMessage, deleteMessage: () => Promise, uri: string) => void; diff --git a/packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx b/packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx index d6ec55b67..b8502a325 100644 --- a/packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx +++ b/packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx @@ -34,7 +34,9 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => { lazyScrollToIndex({ index: foundMessageIndex, animated: true, timeout }); } else { if (props.channel.messageOffsetTimestamp <= createdAt) { - if (focusAnimated) props.onUpdateSearchItem({ startingPoint: createdAt }); + if (focusAnimated) { + props.onUpdateSearchItem({ startingPoint: createdAt }); + } props.onResetMessageListWithStartingPoint(createdAt); } else { return false; @@ -44,15 +46,14 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => { }, ); - const scrollToBottom = useFreshCallback((animated = false) => { + const scrollToBottom = useFreshCallback(async (animated = false) => { if (props.hasNext()) { props.onUpdateSearchItem(undefined); props.onScrolledAwayFromBottom(false); - props.onResetMessageList(() => { - props.onScrolledAwayFromBottom(false); - lazyScrollToBottom({ animated }); - }); + await props.onResetMessageList(); + props.onScrolledAwayFromBottom(false); + lazyScrollToBottom({ animated }); } else { lazyScrollToBottom({ animated }); } diff --git a/packages/uikit-react-native/src/domain/groupChannel/types.ts b/packages/uikit-react-native/src/domain/groupChannel/types.ts index 5510409c2..124f1b7a6 100644 --- a/packages/uikit-react-native/src/domain/groupChannel/types.ts +++ b/packages/uikit-react-native/src/domain/groupChannel/types.ts @@ -73,8 +73,8 @@ export interface GroupChannelProps { | 'hasNext' | 'searchItem' > & { - onResetMessageList: (callback?: () => void) => void; - onResetMessageListWithStartingPoint: (startingPoint: number, callback?: () => void) => void; + onResetMessageList: () => Promise; + onResetMessageListWithStartingPoint: (startingPoint: number) => Promise; // Changing the search item will trigger the focus animation on messages. onUpdateSearchItem: (searchItem?: GroupChannelProps['MessageList']['searchItem']) => void; diff --git a/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx b/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx index 853d1d15d..3bddaebfd 100644 --- a/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx +++ b/packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx @@ -1,14 +1,15 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { ReplyType } from '@sendbird/chat/message'; -import { useGroupChannelMessages } from '@sendbird/uikit-chat-hooks'; import { Box } from '@sendbird/uikit-react-native-foundation'; +import { useGroupChannelMessages } from '@sendbird/uikit-tools'; import { NOOP, PASS, SendbirdFileMessage, SendbirdGroupChannel, SendbirdUserMessage, + confirmAndMarkAsRead, messageComparator, useFreshCallback, useIIFE, @@ -75,8 +76,8 @@ const createGroupChannelFragment = (initModule?: Partial): G messages, newMessages, resetNewMessages, - next, - prev, + loadNext, + loadPrevious, hasNext, sendFileMessage, sendUserMessage, @@ -85,7 +86,7 @@ const createGroupChannelFragment = (initModule?: Partial): G resendMessage, deleteMessage, resetWithStartingPoint, - } = useGroupChannelMessages(sdk, channel, currentUser?.userId, { + } = useGroupChannelMessages(sdk, channel, { shouldCountNewMessages: () => scrolledAwayFromBottomRef.current, onMessagesReceived(messages) { groupChannelPubSub.publish({ type: 'MESSAGES_RECEIVED', data: { messages } }); @@ -93,12 +94,13 @@ const createGroupChannelFragment = (initModule?: Partial): G onMessagesUpdated(messages) { groupChannelPubSub.publish({ type: 'MESSAGES_UPDATED', data: { messages } }); }, + onChannelDeleted, + onCurrentUserBanned: onChannelDeleted, collectionCreator, sortComparator, - onChannelDeleted, + markAsRead: confirmAndMarkAsRead, replyType, startingPoint: internalSearchItem?.startingPoint, - enableCollectionWithoutLocalCache: true, }); const onBlurFragment = () => { @@ -144,12 +146,12 @@ const createGroupChannelFragment = (initModule?: Partial): G [flatListProps], ); - const onResetMessageList = useCallback((callback?: () => void) => { - resetWithStartingPoint(Number.MAX_SAFE_INTEGER, callback); + const onResetMessageList = useCallback(async () => { + return await resetWithStartingPoint(Number.MAX_SAFE_INTEGER); }, []); - const onResetMessageListWithStartingPoint = useCallback((startingPoint: number, callback?: () => void) => { - resetWithStartingPoint(startingPoint, callback); + const onResetMessageListWithStartingPoint = useCallback(async (startingPoint: number) => { + return await resetWithStartingPoint(startingPoint); }, []); // Changing the search item will trigger the focus animation on messages. @@ -224,8 +226,8 @@ const createGroupChannelFragment = (initModule?: Partial): G renderMessage={renderItem} messages={messages} newMessages={newMessages} - onTopReached={prev} - onBottomReached={next} + onTopReached={loadPrevious} + onBottomReached={loadNext} hasNext={hasNext} scrolledAwayFromBottom={scrolledAwayFromBottom} onScrolledAwayFromBottom={onScrolledAwayFromBottom} diff --git a/packages/uikit-utils/package.json b/packages/uikit-utils/package.json index a640f5cd4..38be05a72 100644 --- a/packages/uikit-utils/package.json +++ b/packages/uikit-utils/package.json @@ -56,7 +56,7 @@ "typescript": "5.2.2" }, "peerDependencies": { - "@sendbird/chat": "^4.9.8", + "@sendbird/chat": "^4.10.7", "react": ">=17.0.2", "react-native": ">=0.65.0" }, diff --git a/sample/package.json b/sample/package.json index bc10cafbb..9241fe930 100644 --- a/sample/package.json +++ b/sample/package.json @@ -28,7 +28,7 @@ "@react-navigation/bottom-tabs": "^6.2.0", "@react-navigation/native": "^6.0.6", "@react-navigation/native-stack": "^6.7.0", - "@sendbird/chat": "^4.9.8", + "@sendbird/chat": "^4.10.7", "@sendbird/react-native-scrollview-enhancer": "^0.2.1", "@storybook/addon-actions": "^6.4.19", "@storybook/addon-controls": "^6.4.19", diff --git a/yarn.lock b/yarn.lock index 3682bd4d7..6f940fddb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3372,20 +3372,20 @@ dependencies: nanoid "^3.1.23" -"@sendbird/chat@4.9.10", "@sendbird/chat@^4.9.8": - version "4.9.10" - resolved "https://registry.yarnpkg.com/@sendbird/chat/-/chat-4.9.10.tgz#b92a3f5d4ec895acd5c2ebbadf4fa10aa0ebda10" - integrity sha512-WR2DoFu190/8Z6UhSjeNNQE6vIhrfBgwH5hdL0Jb4mVQNm8bSBd9jbwlDzvBAZCAqHxvXwNU+rH2VlKvaw84wQ== +"@sendbird/chat@4.10.7", "@sendbird/chat@^4.10.7", "@sendbird/chat@^4.9.8": + version "4.10.7" + resolved "https://registry.yarnpkg.com/@sendbird/chat/-/chat-4.10.7.tgz#45b23849a854273811c36a072044e64c6a0bc4bd" + integrity sha512-68h9sj5mMaBzYMfcX0G7TU91JMrGRz0rbUJj6pSLet911pRMBpUi0f6smS8XtUJMNdXtwFh56TyMyAZQM6TcCQ== "@sendbird/react-native-scrollview-enhancer@^0.2.1": version "0.2.1" resolved "https://registry.yarnpkg.com/@sendbird/react-native-scrollview-enhancer/-/react-native-scrollview-enhancer-0.2.1.tgz#25de4af78293978a4c0ef6fddee25d822a364c46" integrity sha512-LN+Tm+ZUkE2MBVreg/JI8SVr8SOKRteZN0YFpGzRtbKkP45+pKyPN4JQPf73eFx7qO8zDL+TUVyzz/1MOnIK7g== -"@sendbird/uikit-tools@0.0.1-alpha.42": - version "0.0.1-alpha.42" - resolved "https://registry.yarnpkg.com/@sendbird/uikit-tools/-/uikit-tools-0.0.1-alpha.42.tgz#dc4bdedd8a08c8681524cd5d27e68f813a40a52a" - integrity sha512-4XGuw5qbFbPSnpM6SdXoX9UKHwFD0cXKHS7BSfdnmJ7oF+6slpj5TthigWL8/+rhlYb/RLbwE7gqCOllnr+l2w== +"@sendbird/uikit-tools@0.0.1-alpha.57": + version "0.0.1-alpha.57" + resolved "https://registry.yarnpkg.com/@sendbird/uikit-tools/-/uikit-tools-0.0.1-alpha.57.tgz#ee356f0603bd3fdf580ab61ded2a3a5a9e89290a" + integrity sha512-7RWTvXHp54EbJARc4wo4IvYxYuvPiZYuSXEGQJwOPFCh1LcnOiY9yxayPb1kQu2QoqXZLJrNtq9yBQQalbL/HQ== "@sideway/address@^4.1.3": version "4.1.4"