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.
Files changed (43) hide show
  1. package/lib/commonjs/components/Avatar/Avatar.js +26 -13
  2. package/lib/commonjs/components/Avatar/Avatar.js.map +1 -1
  3. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js +3 -14
  4. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js.map +1 -1
  5. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +7 -18
  6. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
  7. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js +8 -34
  8. package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js.map +1 -1
  9. package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js +6 -5
  10. package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
  11. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +3 -15
  12. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  13. package/lib/commonjs/version.json +1 -1
  14. package/lib/module/components/Avatar/Avatar.js +26 -13
  15. package/lib/module/components/Avatar/Avatar.js.map +1 -1
  16. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js +3 -14
  17. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.js.map +1 -1
  18. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +7 -18
  19. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
  20. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js +8 -34
  21. package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.js.map +1 -1
  22. package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js +6 -5
  23. package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
  24. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +3 -15
  25. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  26. package/lib/module/version.json +1 -1
  27. package/lib/typescript/components/Avatar/Avatar.d.ts.map +1 -1
  28. package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewData.d.ts +10 -2
  29. package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewData.d.ts.map +1 -1
  30. package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.d.ts.map +1 -1
  31. package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayName.d.ts.map +1 -1
  32. package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.d.ts.map +1 -1
  33. package/lib/typescript/components/ChannelPreview/hooks/useIsChannelMuted.d.ts.map +1 -1
  34. package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts +9 -1
  35. package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/components/Avatar/Avatar.tsx +33 -19
  38. package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayAvatar.ts +4 -13
  39. package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayName.ts +10 -16
  40. package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayPresence.ts +6 -33
  41. package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +7 -1
  42. package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +19 -36
  43. package/src/version.json +1 -1
@@ -1,30 +1,9 @@
1
- import { useEffect, useState } from 'react';
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
- const currentUserId = client.userID;
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
- useEffect(() => {
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 displayPresence;
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 || { createdAt: null, expiresAt: null, muted: false };
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
- useEffect(
323
- () =>
324
- setLatestMessagePreview(
325
- getLatestMessagePreview({
326
- channel,
327
- client,
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
- readStatus,
340
- latestVotesByOption,
341
- createdBy,
342
- name,
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
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "6.6.8-beta.1"
2
+ "version": "6.6.8-beta.3"
3
3
  }