Skip to content

Commit

Permalink
Only start the task to get updated chats after all chats have been re…
Browse files Browse the repository at this point in the history
…trieved (#77)
  • Loading branch information
hpeebles authored Jan 15, 2021
1 parent e1d00e8 commit 01f2256
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/website/public/backgroundTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Timestamp>, dispatch: Dispatch<any>) : () => void {
Expand Down
9 changes: 6 additions & 3 deletions src/website/public/reducers/chatsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ import {
export type ChatsState = {
chats: Chat[],
selectedChatIndex: Option<number>,
chatsSyncedUpTo: Option<Timestamp>
chatsSyncedUpTo: Option<Timestamp>,
runUpdateChatsTask: boolean
}

const initialState: ChatsState = {
chats: [],
selectedChatIndex: null,
chatsSyncedUpTo: null
chatsSyncedUpTo: null,
runUpdateChatsTask: false
};

type Event =
Expand Down Expand Up @@ -141,7 +143,8 @@ export default produce((state: ChatsState, event: Event) => {
return {
chats,
selectedChatIndex: chats.length ? 0 : null,
chatsSyncedUpTo: latestUpdateTimestamp
chatsSyncedUpTo: latestUpdateTimestamp,
runUpdateChatsTask: true
};
}

Expand Down

0 comments on commit 01f2256

Please sign in to comment.