From 7d342d43836a342cfd6ac519806623c044da9d27 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 18 Jul 2020 18:17:36 -0500 Subject: [PATCH] fix: unread --- src/common/state/user.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 */