From 01f2256afc89e1cccf3c83acc217a9f030216514 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Fri, 15 Jan 2021 18:56:27 +0000 Subject: [PATCH] Only start the task to get updated chats after all chats have been retrieved (#77) --- src/website/public/backgroundTasks.ts | 4 ++-- src/website/public/reducers/chatsReducer.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/website/public/backgroundTasks.ts b/src/website/public/backgroundTasks.ts index bf8a001705..518e79e780 100644 --- a/src/website/public/backgroundTasks.ts +++ b/src/website/public/backgroundTasks.ts @@ -79,10 +79,10 @@ export function setupBackgroundTasks() { // Check for new messages at regular intervals useEffect(() => { - if (usersState.me) { + if (chatsState.runUpdateChatsTask) { return updateChatsRegularlyTask(chatsState.chatsSyncedUpTo, dispatch); } - }, [usersState.me]); + }, [chatsState.runUpdateChatsTask]); } function updateChatsRegularlyTask(chatsSyncedUpTo: Option, dispatch: Dispatch) : () => void { diff --git a/src/website/public/reducers/chatsReducer.ts b/src/website/public/reducers/chatsReducer.ts index 1fc5fb3e82..d793c58df5 100644 --- a/src/website/public/reducers/chatsReducer.ts +++ b/src/website/public/reducers/chatsReducer.ts @@ -62,13 +62,15 @@ import { export type ChatsState = { chats: Chat[], selectedChatIndex: Option, - chatsSyncedUpTo: Option + chatsSyncedUpTo: Option, + runUpdateChatsTask: boolean } const initialState: ChatsState = { chats: [], selectedChatIndex: null, - chatsSyncedUpTo: null + chatsSyncedUpTo: null, + runUpdateChatsTask: false }; type Event = @@ -141,7 +143,8 @@ export default produce((state: ChatsState, event: Event) => { return { chats, selectedChatIndex: chats.length ? 0 : null, - chatsSyncedUpTo: latestUpdateTimestamp + chatsSyncedUpTo: latestUpdateTimestamp, + runUpdateChatsTask: true }; }