diff --git a/src/common/state/user.js b/src/common/state/user.js index 73f5da3..0aa9de9 100644 --- a/src/common/state/user.js +++ b/src/common/state/user.js @@ -77,14 +77,18 @@ const slice = createSlice({ extraReducers: { [addMessage]: ({focus, unread}, {payload: {channel}}) => { if (focus !== channel) { - unread[channel] += 1; + unread[channel] = (unread[channel] || 0) + 1; } }, [leave]: ({unread}, {payload: {channel}}) => { delete unread[channel]; }, [LOCATION_CHANGE]: (state, {payload: {location: {pathname}}}) => { + const {unread} = state; state.focus = pathname.match(/^\/chat\//) ? pathname.substr('/chat'.length) : ''; + if (unread[state.focus]) { + delete unread[state.focus]; + } }, }, /* eslint-enable no-param-reassign */