stream-chat-react-native-core 5.15.0-beta.7 → 5.15.1-beta.1

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 (40) hide show
  1. package/lib/commonjs/components/Channel/Channel.js +72 -61
  2. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  3. package/lib/commonjs/components/ChannelList/ChannelList.js +4 -2
  4. package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
  5. package/lib/commonjs/components/ChannelList/hooks/useCreateChannelsContext.js +2 -0
  6. package/lib/commonjs/components/ChannelList/hooks/useCreateChannelsContext.js.map +1 -1
  7. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js +2 -4
  8. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
  9. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMutedStatus.js +4 -5
  10. package/lib/commonjs/components/ChannelPreview/ChannelPreviewMutedStatus.js.map +1 -1
  11. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +2 -2
  12. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  13. package/lib/commonjs/version.json +1 -1
  14. package/lib/module/components/Channel/Channel.js +72 -61
  15. package/lib/module/components/Channel/Channel.js.map +1 -1
  16. package/lib/module/components/ChannelList/ChannelList.js +4 -2
  17. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  18. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js +2 -0
  19. package/lib/module/components/ChannelList/hooks/useCreateChannelsContext.js.map +1 -1
  20. package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js +2 -4
  21. package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
  22. package/lib/module/components/ChannelPreview/ChannelPreviewMutedStatus.js +4 -5
  23. package/lib/module/components/ChannelPreview/ChannelPreviewMutedStatus.js.map +1 -1
  24. package/lib/module/contexts/channelsContext/ChannelsContext.js +2 -2
  25. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  26. package/lib/module/version.json +1 -1
  27. package/lib/typescript/components/ChannelList/ChannelList.d.ts +1 -1
  28. package/lib/typescript/components/ChannelList/hooks/useCreateChannelsContext.d.ts +1 -1
  29. package/lib/typescript/components/ChannelPreview/ChannelPreviewMutedStatus.d.ts +1 -6
  30. package/lib/typescript/components/Message/hooks/useMessageActionHandlers.d.ts +1 -1
  31. package/lib/typescript/components/Message/hooks/useMessageActions.d.ts +1 -1
  32. package/lib/typescript/contexts/channelsContext/ChannelsContext.d.ts +1 -2
  33. package/package.json +1 -1
  34. package/src/components/Channel/Channel.tsx +74 -57
  35. package/src/components/ChannelList/ChannelList.tsx +3 -0
  36. package/src/components/ChannelList/hooks/useCreateChannelsContext.ts +2 -0
  37. package/src/components/ChannelPreview/ChannelPreviewMessenger.tsx +1 -1
  38. package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx +3 -18
  39. package/src/contexts/channelsContext/ChannelsContext.tsx +1 -3
  40. package/src/version.json +1 -1
@@ -637,7 +637,7 @@ const ChannelWithContext = <
637
637
  } else {
638
638
  setThread(null);
639
639
  }
640
- }, [threadPropsExists]);
640
+ }, [threadPropsExists, shouldSyncChannel]);
641
641
 
642
642
  const handleAppBackground = useCallback(() => {
643
643
  const channelData = channel.data as
@@ -739,70 +739,61 @@ const ChannelWithContext = <
739
739
  ),
740
740
  ).current;
741
741
 
742
- const connectionChangedHandler = () => {
743
- if (shouldSyncChannel) {
744
- resyncChannel();
745
- }
746
- };
747
-
748
- const handleEvent: EventHandler<StreamChatGenerics> = (event) => {
749
- if (shouldSyncChannel) {
750
- if (thread) {
751
- const updatedThreadMessages =
752
- (thread.id && channel && channel.state.threads[thread.id]) || threadMessages;
753
- setThreadMessages(updatedThreadMessages);
754
- }
755
-
756
- if (channel && thread && event.message?.id === thread.id) {
757
- const updatedThread = channel.state.formatMessage(event.message);
758
- setThread(updatedThread);
759
- }
760
-
761
- if (event.type === 'typing.start' || event.type === 'typing.stop') {
762
- copyTypingState();
763
- } else if (event.type === 'message.read') {
764
- copyReadState();
765
- } else if (event.type === 'message.new') {
766
- copyMessagesState();
767
- } else if (channel) {
768
- copyChannelState();
769
- }
770
- }
771
- };
772
-
742
+ // subscribe to specific channel events
773
743
  useEffect(() => {
774
744
  const channelSubscriptions: Array<ReturnType<ChannelType['on']>> = [];
775
- const clientSubscriptions: Array<ReturnType<StreamChat['on']>> = [];
745
+ if (channel && shouldSyncChannel) {
746
+ channelSubscriptions.push(channel.on('message.new', copyMessagesState));
747
+ channelSubscriptions.push(channel.on('message.read', copyReadState));
748
+ channelSubscriptions.push(channel.on('typing.start', copyTypingState));
749
+ channelSubscriptions.push(channel.on('typing.stop', copyTypingState));
750
+ }
751
+ return () => {
752
+ channelSubscriptions.forEach((s) => s.unsubscribe());
753
+ };
754
+ }, [channelId, shouldSyncChannel]);
776
755
 
777
- if (!channel) return;
756
+ // subscribe to the generic all channel event
757
+ useEffect(() => {
758
+ const handleEvent: EventHandler<StreamChatGenerics> = (event) => {
759
+ if (shouldSyncChannel) {
760
+ if (thread) {
761
+ const updatedThreadMessages =
762
+ (thread.id && channel && channel.state.threads[thread.id]) || threadMessages;
763
+ setThreadMessages(updatedThreadMessages);
764
+ }
778
765
 
779
- clientSubscriptions.push(
780
- client.on('channel.deleted', (event) => {
781
- if (event.cid === channel.cid) {
782
- setDeleted(true);
766
+ if (channel && thread && event.message?.id === thread.id) {
767
+ const updatedThread = channel.state.formatMessage(event.message);
768
+ setThread(updatedThread);
783
769
  }
784
- }),
785
- );
786
770
 
787
- if (enableOfflineSupport) {
788
- clientSubscriptions.push(DBSyncManager.onSyncStatusChange(connectionChangedHandler));
789
- } else {
790
- clientSubscriptions.push(
791
- client.on('connection.changed', (event) => {
792
- if (event.online) {
793
- connectionChangedHandler();
794
- }
795
- }),
796
- );
797
- }
771
+ // only update channel state if the events are not the previously subscribed useEffect's subscription events
772
+ if (
773
+ channel &&
774
+ event.type !== 'message.new' &&
775
+ event.type !== 'message.read' &&
776
+ event.type !== 'typing.start' &&
777
+ event.type !== 'typing.stop'
778
+ ) {
779
+ copyChannelState();
780
+ }
781
+ }
782
+ };
783
+ const { unsubscribe } = channel.on(handleEvent);
784
+ return unsubscribe;
785
+ }, [channelId, thread?.id, shouldSyncChannel]);
798
786
 
799
- channelSubscriptions.push(channel.on(handleEvent));
787
+ // subscribe to channel.deleted event
788
+ useEffect(() => {
789
+ const { unsubscribe } = client.on('channel.deleted', (event) => {
790
+ if (event.cid === channel?.cid) {
791
+ setDeleted(true);
792
+ }
793
+ });
800
794
 
801
- return () => {
802
- clientSubscriptions.forEach((s) => s.unsubscribe());
803
- channelSubscriptions.forEach((s) => s.unsubscribe());
804
- };
805
- }, [channelId, connectionChangedHandler, handleEvent]);
795
+ return unsubscribe;
796
+ }, [channelId]);
806
797
 
807
798
  const channelQueryCallRef = useRef(
808
799
  async (
@@ -1076,6 +1067,32 @@ const ChannelWithContext = <
1076
1067
  setSyncingChannel(false);
1077
1068
  };
1078
1069
 
1070
+ // resync channel is added to ref so that it can be used in useEffect without adding it as a dependency
1071
+ const resyncChannelRef = useRef(resyncChannel);
1072
+ resyncChannelRef.current = resyncChannel;
1073
+
1074
+ useEffect(() => {
1075
+ const connectionChangedHandler = () => {
1076
+ if (shouldSyncChannel) {
1077
+ resyncChannelRef.current();
1078
+ }
1079
+ };
1080
+ let connectionChangedSubscription: ReturnType<ChannelType['on']>;
1081
+
1082
+ if (enableOfflineSupport) {
1083
+ connectionChangedSubscription = DBSyncManager.onSyncStatusChange(connectionChangedHandler);
1084
+ } else {
1085
+ connectionChangedSubscription = client.on('connection.changed', (event) => {
1086
+ if (event.online) {
1087
+ connectionChangedHandler();
1088
+ }
1089
+ });
1090
+ }
1091
+ return () => {
1092
+ connectionChangedSubscription.unsubscribe();
1093
+ };
1094
+ }, [enableOfflineSupport, shouldSyncChannel]);
1095
+
1079
1096
  const reloadChannel = () =>
1080
1097
  channelQueryCallRef.current(async () => {
1081
1098
  setLoading(true);
@@ -52,6 +52,7 @@ export type ChannelListProps<
52
52
  | 'onSelect'
53
53
  | 'PreviewAvatar'
54
54
  | 'PreviewMessage'
55
+ | 'PreviewMutedStatus'
55
56
  | 'PreviewStatus'
56
57
  | 'PreviewTitle'
57
58
  | 'PreviewUnreadCount'
@@ -270,6 +271,7 @@ export const ChannelList = <
270
271
  Preview = ChannelPreviewMessenger,
271
272
  PreviewAvatar,
272
273
  PreviewMessage,
274
+ PreviewMutedStatus,
273
275
  PreviewStatus,
274
276
  PreviewTitle,
275
277
  PreviewUnreadCount,
@@ -391,6 +393,7 @@ export const ChannelList = <
391
393
  Preview,
392
394
  PreviewAvatar,
393
395
  PreviewMessage,
396
+ PreviewMutedStatus,
394
397
  PreviewStatus,
395
398
  PreviewTitle,
396
399
  PreviewUnreadCount,
@@ -28,6 +28,7 @@ export const useCreateChannelsContext = <
28
28
  Preview,
29
29
  PreviewAvatar,
30
30
  PreviewMessage,
31
+ PreviewMutedStatus,
31
32
  PreviewStatus,
32
33
  PreviewTitle,
33
34
  PreviewUnreadCount,
@@ -69,6 +70,7 @@ export const useCreateChannelsContext = <
69
70
  Preview,
70
71
  PreviewAvatar,
71
72
  PreviewMessage,
73
+ PreviewMutedStatus,
72
74
  PreviewStatus,
73
75
  PreviewTitle,
74
76
  PreviewUnreadCount,
@@ -156,7 +156,7 @@ const ChannelPreviewMessengerWithContext = <
156
156
  <View style={[styles.row, row]}>
157
157
  <PreviewTitle channel={channel} displayName={displayName} />
158
158
  <View style={[styles.statusContainer, row]}>
159
- <PreviewMutedStatus channel={channel} muted={isChannelMuted} />
159
+ {isChannelMuted && <PreviewMutedStatus />}
160
160
  <PreviewUnreadCount channel={channel} maxUnreadCount={maxUnreadCount} unread={unread} />
161
161
  </View>
162
162
  </View>
@@ -2,11 +2,8 @@ import React from 'react';
2
2
 
3
3
  import { StyleSheet } from 'react-native';
4
4
 
5
- import type { ChannelPreviewProps } from './ChannelPreview';
6
-
7
5
  import { useTheme } from '../../contexts/themeContext/ThemeContext';
8
6
  import { Mute } from '../../icons';
9
- import type { DefaultStreamChatGenerics } from '../../types/types';
10
7
 
11
8
  const styles = StyleSheet.create({
12
9
  iconStyle: {
@@ -14,22 +11,10 @@ const styles = StyleSheet.create({
14
11
  },
15
12
  });
16
13
 
17
- export type ChannelPreviewMutedStatusProps<
18
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
19
- > = Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'> & {
20
- muted: boolean;
21
- };
22
-
23
14
  /**
24
15
  * This UI component displays an avatar for a particular channel.
25
16
  */
26
- export const ChannelPreviewMutedStatus = <
27
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
28
- >(
29
- props: ChannelPreviewMutedStatusProps<StreamChatGenerics>,
30
- ) => {
31
- const { muted } = props;
32
-
17
+ export const ChannelPreviewMutedStatus = () => {
33
18
  const {
34
19
  theme: {
35
20
  channelPreview: {
@@ -39,12 +24,12 @@ export const ChannelPreviewMutedStatus = <
39
24
  },
40
25
  } = useTheme();
41
26
 
42
- return muted ? (
27
+ return (
43
28
  <Mute
44
29
  height={height}
45
30
  pathFill={grey_dark}
46
31
  style={[styles.iconStyle, iconStyle]}
47
32
  width={width}
48
33
  />
49
- ) : null;
34
+ );
50
35
  };
@@ -3,8 +3,6 @@ import React, { PropsWithChildren, useContext } from 'react';
3
3
  import type { FlatListProps } from 'react-native';
4
4
  import type { FlatList } from 'react-native-gesture-handler';
5
5
 
6
- import type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';
7
-
8
6
  import type { Channel } from 'stream-chat';
9
7
 
10
8
  import type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';
@@ -189,7 +187,7 @@ export type ChannelsContextValue<
189
187
  *
190
188
  * **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)
191
189
  */
192
- PreviewMutedStatus?: React.ComponentType<ChannelPreviewMutedStatusProps<StreamChatGenerics>>;
190
+ PreviewMutedStatus?: React.ComponentType;
193
191
  /**
194
192
  * Custom UI component to render preview avatar.
195
193
  *
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.15.0-beta.7"
2
+ "version": "5.15.1-beta.1"
3
3
  }