Skip to content

Commit

Permalink
chore: replaced useGroupChannelMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Jan 22, 2024
1 parent 08c63bd commit 27dadfc
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
]
},
"resolutions": {
"@sendbird/chat": "4.9.10",
"@sendbird/chat": "4.10.7",
"@types/react": "^18",
"@types/react-native": "^0.67"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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 @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/uikit-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type ChannelMessageListProps<T extends SendbirdGroupChannel | SendbirdOpe
onEditMessage: (message: HandleableMessage) => void;
onReplyMessage?: (message: HandleableMessage) => void; // only available on group channel
onDeleteMessage: (message: HandleableMessage) => Promise<void>;
onResendFailedMessage: (failedMessage: HandleableMessage) => Promise<void>;
onResendFailedMessage: (failedMessage: HandleableMessage) => Promise<HandleableMessage | void>;
onPressParentMessage?: (parentMessage: SendbirdMessage) => void;
onPressMediaMessage?: (message: SendbirdFileMessage, deleteMessage: () => Promise<void>, uri: string) => void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/uikit-react-native/src/domain/groupChannel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export interface GroupChannelProps {
| 'hasNext'
| 'searchItem'
> & {
onResetMessageList: (callback?: () => void) => void;
onResetMessageListWithStartingPoint: (startingPoint: number, callback?: () => void) => void;
onResetMessageList: () => Promise<void>;
onResetMessageListWithStartingPoint: (startingPoint: number) => Promise<void>;

// Changing the search item will trigger the focus animation on messages.
onUpdateSearchItem: (searchItem?: GroupChannelProps['MessageList']['searchItem']) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -75,8 +76,8 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
messages,
newMessages,
resetNewMessages,
next,
prev,
loadNext,
loadPrevious,
hasNext,
sendFileMessage,
sendUserMessage,
Expand All @@ -85,20 +86,21 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
resendMessage,
deleteMessage,
resetWithStartingPoint,
} = useGroupChannelMessages(sdk, channel, currentUser?.userId, {
} = useGroupChannelMessages(sdk, channel, {
shouldCountNewMessages: () => scrolledAwayFromBottomRef.current,
onMessagesReceived(messages) {
groupChannelPubSub.publish({ type: 'MESSAGES_RECEIVED', data: { messages } });
},
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 = () => {
Expand Down Expand Up @@ -144,12 +146,12 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): 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.
Expand Down Expand Up @@ -224,8 +226,8 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
renderMessage={renderItem}
messages={messages}
newMessages={newMessages}
onTopReached={prev}
onBottomReached={next}
onTopReached={loadPrevious}
onBottomReached={loadNext}
hasNext={hasNext}
scrolledAwayFromBottom={scrolledAwayFromBottom}
onScrolledAwayFromBottom={onScrolledAwayFromBottom}
Expand Down
2 changes: 1 addition & 1 deletion packages/uikit-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].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/[email protected].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"
Expand Down

0 comments on commit 27dadfc

Please sign in to comment.