Skip to content

Commit

Permalink
fix: message list connection reconciliation (#2896)
Browse files Browse the repository at this point in the history
* fix: connection recovery reconciliation in message list

* fix: use top level state for user presence
  • Loading branch information
isekovanic authored Jan 17, 2025
1 parent 7e50994 commit 020cecc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AIState, Channel, Event } from 'stream-chat';

import { useChatContext } from '../../../contexts';
import type { DefaultStreamChatGenerics } from '../../../types/types';
import { useIsOnline } from '../../Chat/hooks/useIsOnline';

export const AIStates = {
Error: 'AI_STATE_ERROR',
Expand All @@ -24,8 +23,7 @@ export const useAIState = <
>(
channel?: Channel<StreamChatGenerics>,
): { aiState: AIState } => {
const { client } = useChatContext<StreamChatGenerics>();
const { isOnline } = useIsOnline<StreamChatGenerics>(client);
const { isOnline } = useChatContext<StreamChatGenerics>();

const [aiState, setAiState] = useState<AIState>(AIStates.Idle);

Expand Down
11 changes: 10 additions & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,14 @@ const ChannelWithContext = <
syncingChannelRef.current = true;
setError(false);

if (channelMessagesState?.messages) {
await channel?.watch({
messages: {
limit: channelMessagesState.messages.length + 30,
},
});
}

const parseMessage = (message: FormatMessageResponse<StreamChatGenerics>) =>
({
...message,
Expand All @@ -1003,6 +1011,7 @@ const ChannelWithContext = <
if (failedMessages?.length) {
channel.state.addMessagesSorted(failedMessages);
}
channel.state.setIsUpToDate(true);
} else {
await reloadThread();

Expand Down Expand Up @@ -1042,7 +1051,7 @@ const ChannelWithContext = <
if (enableOfflineSupport) {
connectionChangedSubscription = DBSyncManager.onSyncStatusChange((statusChanged) => {
if (statusChanged) {
copyChannelState();
connectionChangedHandler();
}
});
} else {
Expand Down

0 comments on commit 020cecc

Please sign in to comment.