stream-chat-react-native-core 6.6.8-beta.1 → 6.6.8-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Avatar/Avatar.js +26 -13
- package/lib/commonjs/components/Avatar/Avatar.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js +3 -14
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +7 -18
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js +8 -34
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js +6 -5
- package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +3 -15
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Avatar/Avatar.js +26 -13
- package/lib/module/components/Avatar/Avatar.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js +3 -14
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +7 -18
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js +8 -34
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js +6 -5
- package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +3 -15
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewData.d.ts +10 -2
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewData.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayName.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useIsChannelMuted.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts +9 -1
- package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Avatar/Avatar.tsx +33 -19
- package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.ts +4 -13
- package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayName.ts +10 -16
- package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.ts +6 -33
- package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +7 -1
- package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +19 -36
- package/src/version.json +1 -1
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { Channel, StreamChat } from 'stream-chat';
|
|
1
|
+
import type { Channel } from 'stream-chat';
|
|
4
2
|
|
|
5
3
|
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
6
4
|
|
|
7
5
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
8
6
|
|
|
9
|
-
const getChannelPreviewDisplayPresence = <
|
|
10
|
-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
11
|
-
>(
|
|
12
|
-
channel: Channel<StreamChatGenerics>,
|
|
13
|
-
client: StreamChat<StreamChatGenerics>,
|
|
14
|
-
) => {
|
|
15
|
-
const currentUserId = client.userID;
|
|
16
|
-
|
|
17
|
-
if (currentUserId) {
|
|
18
|
-
const members = Object.values(channel.state.members);
|
|
19
|
-
const otherMembers = members.filter((member) => member.user?.id !== currentUserId);
|
|
20
|
-
|
|
21
|
-
if (otherMembers.length === 1) {
|
|
22
|
-
return !!otherMembers[0].user?.online;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
7
|
/**
|
|
29
8
|
* Hook to set the display avatar presence for channel preview
|
|
30
9
|
* @param {*} channel
|
|
@@ -37,18 +16,12 @@ export const useChannelPreviewDisplayPresence = <
|
|
|
37
16
|
channel: Channel<StreamChatGenerics>,
|
|
38
17
|
) => {
|
|
39
18
|
const { client } = useChatContext<StreamChatGenerics>();
|
|
19
|
+
const members = channel.state.members;
|
|
20
|
+
const membersCount = Object.keys(members).length;
|
|
40
21
|
|
|
41
|
-
|
|
42
|
-
const members = Object.values(channel.state.members).filter(
|
|
43
|
-
(member) => !!member.user?.id && !!currentUserId && member.user?.id !== currentUserId,
|
|
44
|
-
);
|
|
45
|
-
const channelMemberOnline = members.some((member) => member.user?.online);
|
|
46
|
-
|
|
47
|
-
const [displayPresence, setDisplayPresence] = useState(false);
|
|
22
|
+
if (membersCount !== 2) return false;
|
|
48
23
|
|
|
49
|
-
|
|
50
|
-
setDisplayPresence(getChannelPreviewDisplayPresence(channel, client));
|
|
51
|
-
}, [channel, channelMemberOnline, client]);
|
|
24
|
+
const otherMember = Object.values(members).find((member) => member.user?.id !== client.userID);
|
|
52
25
|
|
|
53
|
-
return
|
|
26
|
+
return otherMember?.user?.online ?? false;
|
|
54
27
|
};
|
|
@@ -6,6 +6,12 @@ import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
|
6
6
|
|
|
7
7
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
8
8
|
|
|
9
|
+
const defaultMuteStatus = {
|
|
10
|
+
createdAt: null,
|
|
11
|
+
expiresAt: null,
|
|
12
|
+
muted: false,
|
|
13
|
+
};
|
|
14
|
+
|
|
9
15
|
export const useIsChannelMuted = <
|
|
10
16
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
11
17
|
>(
|
|
@@ -24,5 +30,5 @@ export const useIsChannelMuted = <
|
|
|
24
30
|
return () => client.off('notification.channel_mutes_updated', handleEvent);
|
|
25
31
|
}, [channel, client, muted]);
|
|
26
32
|
|
|
27
|
-
return muted
|
|
33
|
+
return muted ?? defaultMuteStatus;
|
|
28
34
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { TFunction } from 'i18next';
|
|
4
4
|
import type {
|
|
@@ -286,19 +286,6 @@ export const useLatestMessagePreview = <
|
|
|
286
286
|
: '';
|
|
287
287
|
|
|
288
288
|
const [readEvents, setReadEvents] = useState(true);
|
|
289
|
-
const [latestMessagePreview, setLatestMessagePreview] = useState<
|
|
290
|
-
LatestMessagePreview<StreamChatGenerics>
|
|
291
|
-
>({
|
|
292
|
-
created_at: '',
|
|
293
|
-
messageObject: undefined,
|
|
294
|
-
previews: [
|
|
295
|
-
{
|
|
296
|
-
bold: false,
|
|
297
|
-
text: '',
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
status: MessageReadStatus.NOT_SENT_BY_CURRENT_USER,
|
|
301
|
-
});
|
|
302
289
|
|
|
303
290
|
const readStatus = getLatestMessageReadStatus(channel, client, translatedLastMessage, readEvents);
|
|
304
291
|
|
|
@@ -319,29 +306,25 @@ export const useLatestMessagePreview = <
|
|
|
319
306
|
useStateStore(poll?.state, selector) ?? {};
|
|
320
307
|
const { createdBy, latestVotesByOption, name } = pollState;
|
|
321
308
|
|
|
322
|
-
|
|
323
|
-
(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
lastMessage: translatedLastMessage,
|
|
329
|
-
pollState,
|
|
330
|
-
readEvents,
|
|
331
|
-
t,
|
|
332
|
-
}),
|
|
333
|
-
),
|
|
334
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
335
|
-
[
|
|
336
|
-
channelLastMessageString,
|
|
337
|
-
forceUpdate,
|
|
309
|
+
const latestMessagePreview = useMemo(() => {
|
|
310
|
+
return getLatestMessagePreview({
|
|
311
|
+
channel,
|
|
312
|
+
client,
|
|
313
|
+
lastMessage: translatedLastMessage,
|
|
314
|
+
pollState,
|
|
338
315
|
readEvents,
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
316
|
+
t,
|
|
317
|
+
});
|
|
318
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
319
|
+
}, [
|
|
320
|
+
channelLastMessageString,
|
|
321
|
+
forceUpdate,
|
|
322
|
+
readEvents,
|
|
323
|
+
readStatus,
|
|
324
|
+
latestVotesByOption,
|
|
325
|
+
createdBy,
|
|
326
|
+
name,
|
|
327
|
+
]);
|
|
345
328
|
|
|
346
329
|
return latestMessagePreview;
|
|
347
330
|
};
|
package/src/version.json
CHANGED