Skip to content

Commit fe48fc6

Browse files
authored
[UIKIT-1882] Fix/war room (#27)
* fix(core): usePushTokenRegistration param * fix(core): changed onPressImageMessage prop of GroupChannel as optional * fix(core): added channel no members string * fix(sample): auto sign-in without screen transition * enhancement(core): added action menu error toast * fix(core): cannot detect proper scroll position on the GroupChannel message list * fix(core): receive new messages separately * fix(core): scroll to bottom without animation * fix(uikit): file message layout * fix(chat-hook): use collection default options * fix(chat-hooks): always use active channel on business logic * chore(uikit): SendbirdUIKitContainer provider re-ordered * fix(utils): sort messages by sending status * fix(core): GroupChannel typing indicator status * fix(uikit): changed default create params in GroupChannelCreate * fix(uikit): ui styles * fix(core): remove openLimitedPhotoLibraryPicker from NativeFileService * fix(foundation): show default Avatar when image uri is invalid * fix(uikit): changed default long press delay * fix(uikit): remove currentUser from user list of GroupChannelCreate * chore: update peer dependencies * fix(uikit): read receipt component * enhancement(core): improvement cover url logic, implement chat helper funcs * fix(core): update strings * fix(core): clear cache on leave channel temporary * fix(core): send button display with trim * feat(core): implement status module component * feat(foundation): added pared text url regex cases * fix(core): scroll error on UserListList * fix(core): changed NativeFileService file system module * skip: apply lint * skip: fix build issue * skip: update README.md
1 parent 41bae55 commit fe48fc6

File tree

78 files changed

+933
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+933
-476
lines changed

packages/uikit-chat-hooks/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949
"react": ">=16.13.1",
5050
"sendbird": "^3.1.16"
5151
},
52-
"peerDependenciesMeta": {
53-
"sendbird": {
54-
"optional": false
55-
}
56-
},
5752
"react-native-builder-bob": {
5853
"source": "src",
5954
"output": "lib",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useEffect, useState } from 'react';
2+
import type Sendbird from 'sendbird';
3+
4+
import type { SendbirdChatSDK } from '@sendbird/uikit-utils';
5+
6+
export const useActiveGroupChannel = (sdk: SendbirdChatSDK, staleChannel: Sendbird.GroupChannel) => {
7+
const [activeChannel, setActiveChannel] = useState(() => staleChannel);
8+
9+
useEffect(() => {
10+
sdk.GroupChannel.getChannel(staleChannel.url).then(setActiveChannel);
11+
}, [staleChannel.url]);
12+
13+
return { activeChannel, setActiveChannel };
14+
};

packages/uikit-chat-hooks/src/channel/useGroupChannelListWithCollection.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ const createGroupChannelListCollection = (
2020

2121
const defaultCollection = sdk.GroupChannel.createGroupChannelCollection();
2222
const filter = new sdk.GroupChannelFilter();
23-
filter.includeEmpty = true;
24-
filter.memberStateFilter = sdk.GroupChannelFilter.MemberStateFilter.ALL;
25-
return defaultCollection
26-
.setLimit(20)
27-
.setFilter(filter)
28-
.setOrder(sdk.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE)
29-
.build();
23+
return defaultCollection.setLimit(20).setFilter(filter).build();
3024
};
3125

3226
export const useGroupChannelListWithCollection = (

packages/uikit-chat-hooks/src/channel/useGroupChannelListWithQuery.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const createGroupChannelListQuery = (
2020

2121
const defaultQuery = sdk.GroupChannel.createMyGroupChannelListQuery();
2222
defaultQuery.limit = 20;
23-
defaultQuery.includeEmpty = true;
24-
defaultQuery.memberStateFilter = 'all';
25-
defaultQuery.order = 'latest_last_message';
2623
return defaultQuery;
2724
};
2825

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { useCallback, useEffect, useRef, useState } from 'react';
1+
import { useCallback, useEffect, useRef } from 'react';
22
import type Sendbird from 'sendbird';
33

4-
import type { SendbirdChatSDK } from '@sendbird/uikit-utils';
4+
import type { SendbirdChannel, SendbirdChatSDK } from '@sendbird/uikit-utils';
55
import { Logger, NOOP, isDifferentChannel, useForceUpdate, useIsMountedRef } from '@sendbird/uikit-utils';
66

77
import { useAppFeatures } from '../../common/useAppFeatures';
88
import { useChannelHandler } from '../../handler/useChannelHandler';
99
import type { UseGroupChannelMessages, UseGroupChannelMessagesOptions } from '../../types';
10+
import { useActiveGroupChannel } from '../useActiveGroupChannel';
1011
import { useGroupChannelMessagesReducer } from './reducer';
1112

1213
const createMessageCollection = (
@@ -17,7 +18,7 @@ const createMessageCollection = (
1718
if (creator) return creator();
1819
const collection = channel.createMessageCollection();
1920
const filter = new sdk.MessageFilter();
20-
return collection.setLimit(100).setStartingPoint(Date.now()).setFilter(filter).build();
21+
return collection.setLimit(100).setFilter(filter).build();
2122
};
2223

2324
const HOOK_NAME = 'useGroupChannelMessagesWithCollection';
@@ -38,14 +39,10 @@ export const useGroupChannelMessagesWithCollection = (
3839

3940
const collectionRef = useRef<Sendbird.MessageCollection>();
4041

41-
// NOTE: We cannot determine the channel object of Sendbird SDK is stale or not, so force update after setActiveChannel
42-
const [activeChannel, setActiveChannel] = useState(() => staleChannel);
42+
// NOTE: We cannot determine the channel object of Sendbird SDK is stale or not, so force update af
43+
const { activeChannel, setActiveChannel } = useActiveGroupChannel(sdk, staleChannel);
4344
const forceUpdate = useForceUpdate();
4445

45-
useEffect(() => {
46-
setActiveChannel(staleChannel);
47-
}, [staleChannel.url]);
48-
4946
const {
5047
loading,
5148
refreshing,
@@ -73,8 +70,15 @@ export const useGroupChannelMessagesWithCollection = (
7370
}
7471
};
7572

73+
const updateChannel = (channel: SendbirdChannel) => {
74+
if (channel.isGroupChannel() && !isDifferentChannel(channel, activeChannel)) {
75+
setActiveChannel(channel);
76+
forceUpdate();
77+
}
78+
};
79+
7680
const init = useCallback(
77-
async (uid?: string) => {
81+
async (uid?: string, callback?: () => void) => {
7882
if (collectionRef.current) collectionRef.current?.dispose();
7983

8084
if (uid) {
@@ -91,6 +95,7 @@ export const useGroupChannelMessagesWithCollection = (
9195
updateMessages(messages, true, sdk.currentUser.userId);
9296
updateMessages(collectionRef.current?.pendingMessages ?? [], false, sdk.currentUser.userId);
9397
updateMessages(collectionRef.current?.failedMessages ?? [], false, sdk.currentUser.userId);
98+
if (messages?.length) callback?.();
9499
}
95100
})
96101
.onApiResult((err, messages) => {
@@ -103,19 +108,22 @@ export const useGroupChannelMessagesWithCollection = (
103108
updateMessages(collectionRef.current?.failedMessages ?? [], false, sdk.currentUser.userId);
104109
}
105110
}
111+
callback?.();
106112
});
107113

108114
collectionRef.current.setMessageCollectionHandler({
109-
onMessagesAdded(_, __, messages) {
115+
onMessagesAdded(_, channel, messages) {
110116
disposeManuallyAfterUnmounted();
111117
channelMarkAs();
112118
updateNextMessages(messages, false, sdk.currentUser.userId);
119+
updateChannel(channel);
113120
},
114-
onMessagesUpdated(_, __, messages) {
121+
onMessagesUpdated(_, channel, messages) {
115122
disposeManuallyAfterUnmounted();
116123
updateMessages(messages, false, sdk.currentUser.userId);
124+
updateChannel(channel);
117125
},
118-
onMessagesDeleted(_, __, messages) {
126+
onMessagesDeleted(_, channel, messages) {
119127
disposeManuallyAfterUnmounted();
120128
const msgIds = messages.map((m) => m.messageId);
121129
const reqIds = messages
@@ -124,17 +132,15 @@ export const useGroupChannelMessagesWithCollection = (
124132

125133
deleteMessages(msgIds, reqIds);
126134
deleteNextMessages(msgIds, reqIds);
135+
updateChannel(channel);
127136
},
128137
onChannelDeleted() {
129138
disposeManuallyAfterUnmounted();
130139
options?.onChannelDeleted?.();
131140
},
132141
onChannelUpdated(_, channel) {
133142
disposeManuallyAfterUnmounted();
134-
if (channel.isGroupChannel() && !isDifferentChannel(channel, activeChannel)) {
135-
setActiveChannel(channel);
136-
forceUpdate();
137-
}
143+
updateChannel(channel);
138144
},
139145
onHugeGapDetected() {
140146
disposeManuallyAfterUnmounted();
@@ -169,8 +175,7 @@ export const useGroupChannelMessagesWithCollection = (
169175
// NOTE: Cache read is heavy synchronous task, and it prevents smooth ui transition
170176
setTimeout(async () => {
171177
updateLoading(true);
172-
await init(userId);
173-
updateLoading(false);
178+
init(userId, () => updateLoading(false));
174179
}, 0);
175180
}, [init, userId]);
176181

@@ -182,8 +187,7 @@ export const useGroupChannelMessagesWithCollection = (
182187

183188
const refresh: UseGroupChannelMessages['refresh'] = useCallback(async () => {
184189
updateRefreshing(true);
185-
await init(userId);
186-
updateRefreshing(false);
190+
init(userId, () => updateRefreshing(false));
187191
}, [init, userId]);
188192

189193
const prev: UseGroupChannelMessages['prev'] = useCallback(async () => {

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useRef, useState } from 'react';
1+
import { useCallback, useRef } from 'react';
22
import type Sendbird from 'sendbird';
33

44
import type { SendbirdChatSDK } from '@sendbird/uikit-utils';
@@ -7,6 +7,7 @@ import { Logger, isDifferentChannel, useAsyncEffect, useForceUpdate } from '@sen
77
import { useAppFeatures } from '../../common/useAppFeatures';
88
import { useChannelHandler } from '../../handler/useChannelHandler';
99
import type { UseGroupChannelMessages, UseGroupChannelMessagesOptions } from '../../types';
10+
import { useActiveGroupChannel } from '../useActiveGroupChannel';
1011
import { useGroupChannelMessagesReducer } from './reducer';
1112

1213
const createMessageQuery = (
@@ -32,13 +33,9 @@ export const useGroupChannelMessagesWithQuery = (
3233
const queryRef = useRef<Sendbird.PreviousMessageListQuery>();
3334

3435
// NOTE: We cannot determine the channel object of Sendbird SDK is stale or not, so force update after setActiveChannel
35-
const [activeChannel, setActiveChannel] = useState(() => staleChannel);
36+
const { activeChannel, setActiveChannel } = useActiveGroupChannel(sdk, staleChannel);
3637
const forceUpdate = useForceUpdate();
3738

38-
useEffect(() => {
39-
setActiveChannel(staleChannel);
40-
}, [staleChannel.url]);
41-
4239
const {
4340
loading,
4441
refreshing,
@@ -114,10 +111,7 @@ export const useGroupChannelMessagesWithQuery = (
114111
onChannelHidden: channelUpdater,
115112
onChannelMemberCountChanged(channels) {
116113
const channel = channels.find((c) => !isDifferentChannel(c, activeChannel));
117-
if (channel) {
118-
setActiveChannel(channel);
119-
forceUpdate();
120-
}
114+
if (channel) channelUpdater(channel);
121115
},
122116
onChannelDeleted(channelUrl: string) {
123117
if (activeChannel.url === channelUrl) options?.onChannelDeleted?.();

packages/uikit-chat-hooks/src/common/useUserList.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const useUserList = <
4040
): UseUserList<QueriedUser> => {
4141
const query = useRef<CustomQueryInterface<QueriedUser>>();
4242

43+
const [error, setError] = useState<unknown>(null);
4344
const [loading, setLoading] = useState(false);
4445
const [refreshing, setRefreshing] = useState(false);
4546

@@ -49,47 +50,55 @@ export const useUserList = <
4950
return users;
5051
}, [users, options?.sortComparator]);
5152

52-
// ---------- internal methods ------------ //
5353
const updateUsers = (users: QueriedUser[], clearPrev: boolean) => {
5454
if (clearPrev) setUsers(users);
5555
else setUsers((prev) => prev.concat(users));
5656
};
57+
5758
const init = useCallback(async () => {
5859
query.current = createUserQuery<QueriedUser>(sdk, options?.queryCreator);
5960
if (query.current?.hasNext) {
6061
const users = await query.current?.next();
6162
updateUsers(users, true);
6263
}
6364
}, [sdk, options?.queryCreator]);
64-
// ---------- internal methods ends ------------ //
6565

66-
// ---------- internal hooks ------------ //
6766
useAsyncEffect(async () => {
6867
setLoading(true);
69-
await init();
70-
setLoading(false);
68+
setError(null);
69+
try {
70+
await init();
71+
} catch (e) {
72+
setError(e);
73+
} finally {
74+
setLoading(false);
75+
}
7176
}, [init]);
72-
// ---------- internal hooks ends ------------ //
7377

74-
// ---------- returns methods ---------- //
7578
const refresh = useCallback(async () => {
7679
setRefreshing(true);
77-
await init();
78-
setRefreshing(false);
80+
setError(null);
81+
try {
82+
await init();
83+
} catch (e) {
84+
setError(e);
85+
} finally {
86+
setRefreshing(false);
87+
}
7988
}, [init]);
8089

8190
const next = useCallback(async () => {
8291
if (query.current && query.current?.hasNext) {
8392
updateUsers(await query.current?.next(), false);
8493
}
8594
}, []);
86-
// ---------- returns methods ends ---------- //
8795

8896
return {
8997
loading,
90-
refreshing,
91-
refresh,
98+
error,
9299
users: sortedUsers,
93100
next,
101+
refreshing,
102+
refresh,
94103
};
95104
};

packages/uikit-chat-hooks/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { useGroupChannelList } from './channel/useGroupChannelList';
22
export { useGroupChannelMessages } from './channel/useGroupChannelMessages';
3+
export { useActiveGroupChannel } from './channel/useActiveGroupChannel';
34

45
export { useUserList } from './common/useUserList';
56
export { usePushTrigger } from './common/usePushTrigger';

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ export interface UseUserList<User> {
202202
* */
203203
refreshing: boolean;
204204

205+
/**
206+
* Error state
207+
* */
208+
error: unknown | null;
209+
205210
/**
206211
* Refresh, clear and reload messages from latest
207212
* @return {Promise<void>}

packages/uikit-react-native-core/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ npm install @sendbird/uikit-react-native-core \
1212
react-native-image-picker \
1313
react-native-document-picker \
1414
@react-native-community/cameraroll \
15-
react-native-fs \
15+
react-native-file-access \
16+
react-native-device-info \
1617
@react-native-clipboard/clipboard \
1718
@react-native-firebase/messaging @react-native-firebase/app \
1819
date-fns

0 commit comments

Comments
 (0)