Skip to content

Commit

Permalink
Fix flakey inbox count update on marking item(s) read (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Sep 8, 2024
1 parent f8867f3 commit e4a46fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/features/inbox/inboxSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const totalUnreadSelector = (state: RootState) =>
state.inbox.counts.replies;

export const getInboxCounts =
() => async (dispatch: AppDispatch, getState: () => RootState) => {
(force = false) =>
async (dispatch: AppDispatch, getState: () => RootState) => {
const jwt = jwtSelector(getState());

if (!jwt) {
Expand All @@ -118,7 +119,7 @@ export const getInboxCounts =

const lastUpdatedCounts = getState().inbox.lastUpdatedCounts;

if (Date.now() - lastUpdatedCounts < 3_000) return;
if (!force && Date.now() - lastUpdatedCounts < 3_000) return;

const result = await clientSelector(getState()).getUnreadCount();

Expand Down Expand Up @@ -190,7 +191,7 @@ export const markAllRead =
await clientSelector(getState()).markAllAsRead();

dispatch(markAllReadInCache());
dispatch(getInboxCounts());
dispatch(getInboxCounts(true));
};

export const conversationsByPersonIdSelector = createSelector(
Expand Down Expand Up @@ -284,5 +285,5 @@ export const markRead =
throw error;
}

dispatch(getInboxCounts());
dispatch(getInboxCounts(true));
};
2 changes: 1 addition & 1 deletion src/features/inbox/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function Message({ message, first }: MessageProps) {
}

await dispatch(receivedMessages([response.private_message_view]));
await dispatch(getInboxCounts());
await dispatch(getInboxCounts(true));
}

return (
Expand Down

0 comments on commit e4a46fa

Please sign in to comment.