diff --git a/src/store/channels/saga.ts b/src/store/channels/saga.ts index 9f87f7a35..f57b84f1a 100644 --- a/src/store/channels/saga.ts +++ b/src/store/channels/saga.ts @@ -22,6 +22,7 @@ import { userByMatrixIdSelector } from '../users/selectors'; import { rawChannel } from './selectors'; import cloneDeep from 'lodash/cloneDeep'; import { getHistory } from '../../lib/browser'; +import { startPollingPosts } from '../posts/saga'; export const rawChannelSelector = (channelId) => (state) => { return getDeepProperty(state, `normalized.channels['${channelId}']`, null); @@ -74,6 +75,7 @@ export function* openConversation(conversationId) { yield call(setActiveConversation, conversationId); yield spawn(markConversationAsRead, conversationId); yield call(resetConversationManagement); + yield call(startPollingPosts, conversationId); } export function* unreadCountUpdated(action) { diff --git a/src/store/posts/saga.ts b/src/store/posts/saga.ts index d9b6aaa79..d2414d2e8 100644 --- a/src/store/posts/saga.ts +++ b/src/store/posts/saga.ts @@ -275,7 +275,19 @@ function* pollPosts(action) { } else { yield put(setCount(count)); } - yield delay(5000); + + const activeConversationId = yield select((state) => state.chat.activeConversationId); + // Only continue polling if we're still in the same conversation + if (activeConversationId === channelId) { + yield delay(5000); + yield put({ type: SagaActionTypes.PollPosts, payload: { channelId } }); + } + } +} + +export function* startPollingPosts(channelId: string) { + const channel = yield select(rawChannelSelector(channelId)); + if (channel?.conversationStatus === ConversationStatus.CREATED) { yield put({ type: SagaActionTypes.PollPosts, payload: { channelId } }); } }