Drop expired stories from selector

This commit is contained in:
Alvaro 2022-10-14 15:47:14 -06:00 committed by GitHub
parent 538a809395
commit 449a9a701a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,6 +36,7 @@ import { getDistributionListSelector } from './storyDistributionLists';
import { getStoriesEnabled } from './items';
import { calculateExpirationTimestamp } from '../../util/expirationTimer';
import { getMessageIdForLogging } from '../../util/idForLogging';
import * as log from '../../logging/log';
export const getStoriesState = (state: StateType): StoriesStateType =>
state.stories;
@ -343,6 +344,21 @@ export const getStories = createSelector(
return;
}
// if for some reason this story is already experied (bug)
// log it and skip it
if ((calculateExpirationTimestamp(story) ?? 0) < Date.now()) {
const messageIdForLogging = getMessageIdForLogging({
...pick(story, 'type', 'sourceUuid', 'sourceDevice'),
sent_at: story.timestamp,
});
log.warn('selectors/getStories: story already expired', {
message: messageIdForLogging,
expireTimer: story.expireTimer,
expirationStartTimestamp: story.expirationStartTimestamp,
});
return;
}
const conversationStory = getConversationStory(
conversationSelector,
ourConversationId,