stream-chat-react-native-core 5.15.0-beta.7 → 5.15.0
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/Channel/Channel.js +72 -61
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +72 -61
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/package.json +1 -1
- package/src/components/Channel/Channel.tsx +74 -57
- package/src/version.json +1 -1
package/lib/module/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "5.15.0
|
|
4
|
+
"version": "5.15.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
780
|
-
|
|
781
|
-
|
|
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
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
package/src/version.json
CHANGED