Adds logic around downloading stories

This commit is contained in:
Josh Perez 2022-03-28 21:10:08 -04:00 committed by GitHub
parent 9d3f0072a5
commit 3b5cc26fec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 645 additions and 149 deletions

View file

@ -0,0 +1,23 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationAttributesType } from '../model-types.d';
import dataInterface from '../sql/Client';
const MAX_NUM_STORIES_TO_PREFETCH = 5;
export async function shouldDownloadStory(
conversation: ConversationAttributesType
): Promise<boolean> {
if (!conversation.hasPostedStory) {
return true;
}
const [storyReads, storyCounts] = await Promise.all([
dataInterface.countStoryReadsByConversation(conversation.id),
dataInterface.getStoryCount(conversation.id),
]);
return storyReads > 0 && storyCounts <= MAX_NUM_STORIES_TO_PREFETCH;
}