diff --git a/ts/state/selectors/expiration.ts b/ts/state/selectors/expiration.ts index fbc67fc99..332c26525 100644 --- a/ts/state/selectors/expiration.ts +++ b/ts/state/selectors/expiration.ts @@ -18,12 +18,17 @@ const SIXTY_DAYS = 60 * DAY; export const getExpiration = (state: StateType): ExpirationStateType => state.expiration; -export const getExpirationTimestamp = createSelector( +const getPackagedBuildExpiration = createSelector( getExpiration, + ({ buildExpiration }) => buildExpiration +); + +export const getExpirationTimestamp = createSelector( + getPackagedBuildExpiration, getRemoteBuildExpiration, getAutoDownloadUpdate, ( - { buildExpiration }: Readonly, + buildExpiration: number, remoteBuildExpiration: number | undefined, autoDownloadUpdate: boolean ): number => { @@ -31,11 +36,19 @@ export const getExpirationTimestamp = createSelector( ? buildExpiration : buildExpiration - SIXTY_DAYS; - if (remoteBuildExpiration) { - return Math.min(remoteBuildExpiration, localBuildExpiration); + // Log the expiration date in this selector because it invalidates only + // if one of the arguments changes. + let result: number; + let type: string; + if (remoteBuildExpiration && remoteBuildExpiration < localBuildExpiration) { + type = 'remote'; + result = remoteBuildExpiration; + } else { + type = 'local'; + result = localBuildExpiration; } - - return localBuildExpiration; + log.info(`Build expires (${type}): ${new Date(result).toISOString()}`); + return result; } ); @@ -52,8 +65,6 @@ export const hasExpired = createSelector( return false; } - log.info('Build expires: ', new Date(buildExpiration).toISOString()); - if (isInPast(buildExpiration)) { return true; } diff --git a/ts/state/selectors/items.ts b/ts/state/selectors/items.ts index ece824756..56578922f 100644 --- a/ts/state/selectors/items.ts +++ b/ts/state/selectors/items.ts @@ -193,7 +193,9 @@ export const getHasStoryViewReceiptSetting = createSelector( export const getRemoteBuildExpiration = createSelector( getItems, (state: ItemsStateType): number | undefined => - Number(state.remoteBuildExpiration) + state.remoteBuildExpiration === undefined + ? undefined + : Number(state.remoteBuildExpiration) ); export const getAutoDownloadUpdate = createSelector(