Skip to content

Commit

Permalink
Repair old unexpired stories
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-signal committed Jun 23, 2022
1 parent a66c9f1 commit 0a0a254
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ts/services/storyLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { pick } from 'lodash';
import type { MessageAttributesType } from '../model-types.d';
import type { StoryDataType } from '../state/ducks/stories';
import * as durations from '../util/durations';
import * as log from '../logging/log';
import dataInterface from '../sql/Client';
import { getAttachmentsForMessage } from '../state/selectors/message';
Expand Down Expand Up @@ -65,14 +66,25 @@ export function getStoriesForRedux(): Array<StoryDataType> {
async function repairUnexpiredStories(): Promise<void> {
strictAssert(storyData, 'Could not load stories');

const DAY_AS_SECONDS = durations.DAY / 1000;

const storiesWithExpiry = storyData
.filter(story => !story.expirationStartTimestamp)
.filter(
story =>
!story.expirationStartTimestamp ||
!story.expireTimer ||
story.expireTimer > DAY_AS_SECONDS
)
.map(story => ({
...story,
expirationStartTimestamp: Math.min(
story.serverTimestamp || story.timestamp,
Date.now()
),
expireTimer: Math.min(
Math.floor((story.timestamp + durations.DAY - Date.now()) / 1000),
DAY_AS_SECONDS
),
}));

if (!storiesWithExpiry.length) {
Expand Down

0 comments on commit 0a0a254

Please sign in to comment.