Skip to content

Commit 1bfc44f

Browse files
committed
chore: replaced useGroupChannelMessages
1 parent 6e75382 commit 1bfc44f

File tree

12 files changed

+43
-35
lines changed

12 files changed

+43
-35
lines changed

docs-validation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@react-native-firebase/messaging": "^14.7.0",
1616
"@react-navigation/native": "^6.0.6",
1717
"@react-navigation/native-stack": "^6.7.0",
18-
"@sendbird/chat": "^4.9.8",
18+
"@sendbird/chat": "^4.10.7",
1919
"react": "17.0.2",
2020
"react-native": "0.67.5",
2121
"react-native-create-thumbnail": "^1.5.1",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
]
9999
},
100100
"resolutions": {
101-
"@sendbird/chat": "4.9.10",
101+
"@sendbird/chat": "4.10.7",
102102
"@types/react": "^18",
103103
"@types/react-native": "^0.67"
104104
}

packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import type { UseGroupChannelMessages } from '../../types';
44
import { useGroupChannelMessagesWithCollection } from './useGroupChannelMessagesWithCollection';
55
import { useGroupChannelMessagesWithQuery } from './useGroupChannelMessagesWithQuery';
66

7+
/**
8+
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
9+
* */
710
export const useGroupChannelMessages: UseGroupChannelMessages = (sdk, channel, userId, options) => {
811
if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) {
912
if (options?.queryCreator) printIgnoredWarning();

packages/uikit-chat-hooks/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export type UseGroupChannelListOptions = {
7373
};
7474

7575
/**
76+
* @deprecated This hook is deprecated and will be replaced by the 'uikit-tools' package.
77+
*
7678
* @interface UseGroupChannelMessages
7779
* @description interface for group channel messages hook
7880
* - Receive new messages from other users & should count new messages -> append to state(newMessages)

packages/uikit-react-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"dependencies": {
6262
"@sendbird/uikit-chat-hooks": "3.3.0",
6363
"@sendbird/uikit-react-native-foundation": "3.3.0",
64-
"@sendbird/uikit-tools": "0.0.1-alpha.42",
64+
"@sendbird/uikit-tools": "0.0.1-alpha.57",
6565
"@sendbird/uikit-utils": "3.3.0"
6666
},
6767
"devDependencies": {
@@ -107,7 +107,7 @@
107107
"@react-native-clipboard/clipboard": ">=1.8.5",
108108
"@react-native-community/netinfo": ">=9.3.0",
109109
"@react-native-firebase/messaging": ">=14.4.0",
110-
"@sendbird/chat": "^4.9.8",
110+
"@sendbird/chat": "^4.10.7",
111111
"@sendbird/react-native-scrollview-enhancer": "*",
112112
"date-fns": ">=2.28.0",
113113
"expo-av": ">=12.0.4",

packages/uikit-react-native/src/components/ChannelMessageList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export type ChannelMessageListProps<T extends SendbirdGroupChannel | SendbirdOpe
5959
onEditMessage: (message: HandleableMessage) => void;
6060
onReplyMessage?: (message: HandleableMessage) => void; // only available on group channel
6161
onDeleteMessage: (message: HandleableMessage) => Promise<void>;
62-
onResendFailedMessage: (failedMessage: HandleableMessage) => Promise<void>;
62+
onResendFailedMessage: (failedMessage: HandleableMessage) => Promise<HandleableMessage | void>;
6363
onPressParentMessage?: (parentMessage: SendbirdMessage) => void;
6464
onPressMediaMessage?: (message: SendbirdFileMessage, deleteMessage: () => Promise<void>, uri: string) => void;
6565

packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => {
3434
lazyScrollToIndex({ index: foundMessageIndex, animated: true, timeout });
3535
} else {
3636
if (props.channel.messageOffsetTimestamp <= createdAt) {
37-
if (focusAnimated) props.onUpdateSearchItem({ startingPoint: createdAt });
37+
if (focusAnimated) {
38+
props.onUpdateSearchItem({ startingPoint: createdAt });
39+
}
3840
props.onResetMessageListWithStartingPoint(createdAt);
3941
} else {
4042
return false;
@@ -44,15 +46,14 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => {
4446
},
4547
);
4648

47-
const scrollToBottom = useFreshCallback((animated = false) => {
49+
const scrollToBottom = useFreshCallback(async (animated = false) => {
4850
if (props.hasNext()) {
4951
props.onUpdateSearchItem(undefined);
5052
props.onScrolledAwayFromBottom(false);
5153

52-
props.onResetMessageList(() => {
53-
props.onScrolledAwayFromBottom(false);
54-
lazyScrollToBottom({ animated });
55-
});
54+
await props.onResetMessageList();
55+
props.onScrolledAwayFromBottom(false);
56+
lazyScrollToBottom({ animated });
5657
} else {
5758
lazyScrollToBottom({ animated });
5859
}

packages/uikit-react-native/src/domain/groupChannel/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export interface GroupChannelProps {
7373
| 'hasNext'
7474
| 'searchItem'
7575
> & {
76-
onResetMessageList: (callback?: () => void) => void;
77-
onResetMessageListWithStartingPoint: (startingPoint: number, callback?: () => void) => void;
76+
onResetMessageList: () => Promise<void>;
77+
onResetMessageListWithStartingPoint: (startingPoint: number) => Promise<void>;
7878

7979
// Changing the search item will trigger the focus animation on messages.
8080
onUpdateSearchItem: (searchItem?: GroupChannelProps['MessageList']['searchItem']) => void;

packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
22

33
import { ReplyType } from '@sendbird/chat/message';
4-
import { useGroupChannelMessages } from '@sendbird/uikit-chat-hooks';
54
import { Box } from '@sendbird/uikit-react-native-foundation';
5+
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
66
import {
77
NOOP,
88
PASS,
99
SendbirdFileMessage,
1010
SendbirdGroupChannel,
1111
SendbirdUserMessage,
12+
confirmAndMarkAsRead,
1213
messageComparator,
1314
useFreshCallback,
1415
useIIFE,
@@ -75,8 +76,8 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
7576
messages,
7677
newMessages,
7778
resetNewMessages,
78-
next,
79-
prev,
79+
loadNext,
80+
loadPrevious,
8081
hasNext,
8182
sendFileMessage,
8283
sendUserMessage,
@@ -85,20 +86,21 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
8586
resendMessage,
8687
deleteMessage,
8788
resetWithStartingPoint,
88-
} = useGroupChannelMessages(sdk, channel, currentUser?.userId, {
89+
} = useGroupChannelMessages(sdk, channel, {
8990
shouldCountNewMessages: () => scrolledAwayFromBottomRef.current,
9091
onMessagesReceived(messages) {
9192
groupChannelPubSub.publish({ type: 'MESSAGES_RECEIVED', data: { messages } });
9293
},
9394
onMessagesUpdated(messages) {
9495
groupChannelPubSub.publish({ type: 'MESSAGES_UPDATED', data: { messages } });
9596
},
97+
onChannelDeleted,
98+
onCurrentUserBanned: onChannelDeleted,
9699
collectionCreator,
97100
sortComparator,
98-
onChannelDeleted,
101+
markAsRead: confirmAndMarkAsRead,
99102
replyType,
100103
startingPoint: internalSearchItem?.startingPoint,
101-
enableCollectionWithoutLocalCache: true,
102104
});
103105

104106
const onBlurFragment = () => {
@@ -144,12 +146,12 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
144146
[flatListProps],
145147
);
146148

147-
const onResetMessageList = useCallback((callback?: () => void) => {
148-
resetWithStartingPoint(Number.MAX_SAFE_INTEGER, callback);
149+
const onResetMessageList = useCallback(async () => {
150+
return await resetWithStartingPoint(Number.MAX_SAFE_INTEGER);
149151
}, []);
150152

151-
const onResetMessageListWithStartingPoint = useCallback((startingPoint: number, callback?: () => void) => {
152-
resetWithStartingPoint(startingPoint, callback);
153+
const onResetMessageListWithStartingPoint = useCallback(async (startingPoint: number) => {
154+
return await resetWithStartingPoint(startingPoint);
153155
}, []);
154156

155157
// Changing the search item will trigger the focus animation on messages.
@@ -224,8 +226,8 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
224226
renderMessage={renderItem}
225227
messages={messages}
226228
newMessages={newMessages}
227-
onTopReached={prev}
228-
onBottomReached={next}
229+
onTopReached={loadPrevious}
230+
onBottomReached={loadNext}
229231
hasNext={hasNext}
230232
scrolledAwayFromBottom={scrolledAwayFromBottom}
231233
onScrolledAwayFromBottom={onScrolledAwayFromBottom}

packages/uikit-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"typescript": "5.2.2"
5757
},
5858
"peerDependencies": {
59-
"@sendbird/chat": "^4.9.8",
59+
"@sendbird/chat": "^4.10.7",
6060
"react": ">=17.0.2",
6161
"react-native": ">=0.65.0"
6262
},

0 commit comments

Comments
 (0)