From 22b05b6d11b73cc090f29d2588824b82cff826ca Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Tue, 23 Aug 2022 13:37:48 -0400 Subject: [PATCH] Clear stories notification after visiting stories view --- ts/state/ducks/stories.ts | 5 +++++ ts/state/selectors/stories.ts | 8 +++++--- ts/state/smart/MainHeader.tsx | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ts/state/ducks/stories.ts b/ts/state/ducks/stories.ts index 3158efe2d1..d3536719d4 100644 --- a/ts/state/ducks/stories.ts +++ b/ts/state/ducks/stories.ts @@ -84,6 +84,7 @@ export type SelectedStoryDataType = { // State export type StoriesStateType = { + readonly lastOpenedAtTimestamp: number | undefined; readonly openedAtTimestamp: number | undefined; readonly replyState?: { messageId: string; @@ -1099,6 +1100,7 @@ export function getEmptyState( overrideState: Partial = {} ): StoriesStateType { return { + lastOpenedAtTimestamp: undefined, openedAtTimestamp: undefined, stories: [], ...overrideState, @@ -1114,6 +1116,9 @@ export function reducer( return { ...state, + lastOpenedAtTimestamp: !isShowingStoriesView + ? state.openedAtTimestamp || Date.now() + : state.lastOpenedAtTimestamp, openedAtTimestamp: isShowingStoriesView ? undefined : Date.now(), replyState: undefined, sendStoryModalData: undefined, diff --git a/ts/state/selectors/stories.ts b/ts/state/selectors/stories.ts index 35125b7529..a8b28a874b 100644 --- a/ts/state/selectors/stories.ts +++ b/ts/state/selectors/stories.ts @@ -350,14 +350,16 @@ export const getStories = createSelector( } ); -export const getUnreadStorySenderCount = createSelector( +export const getStoriesNotificationCount = createSelector( getStoriesState, - ({ stories }): number => { + ({ lastOpenedAtTimestamp, stories }): number => { return new Set( stories .filter( story => - story.readStatus === ReadStatus.Unread && !story.deletedForEveryone + story.readStatus === ReadStatus.Unread && + !story.deletedForEveryone && + story.timestamp > (lastOpenedAtTimestamp || 0) ) .map(story => story.conversationId) ).size; diff --git a/ts/state/smart/MainHeader.tsx b/ts/state/smart/MainHeader.tsx index c6f784fc3f..79f050e67c 100644 --- a/ts/state/smart/MainHeader.tsx +++ b/ts/state/smart/MainHeader.tsx @@ -17,7 +17,7 @@ import { } from '../selectors/user'; import { getMe } from '../selectors/conversations'; import { getStoriesEnabled } from '../selectors/items'; -import { getUnreadStorySenderCount } from '../selectors/stories'; +import { getStoriesNotificationCount } from '../selectors/stories'; const mapStateToProps = (state: StateType) => { const me = getMe(state); @@ -32,7 +32,7 @@ const mapStateToProps = (state: StateType) => { badge: getPreferredBadgeSelector(state)(me.badges), theme: getTheme(state), i18n: getIntl(state), - unreadStoriesCount: getUnreadStorySenderCount(state), + unreadStoriesCount: getStoriesNotificationCount(state), }; };