diff --git a/ts/util/getStoryDuration.ts b/ts/util/getStoryDuration.ts index 02af7f4a2464..f4961ff2923f 100644 --- a/ts/util/getStoryDuration.ts +++ b/ts/util/getStoryDuration.ts @@ -22,6 +22,20 @@ export async function getStoryDuration( return DEFAULT_DURATION; } + if (attachment.textAttachment) { + // Minimum 5 seconds. +1 second for every 15 characters past the first + // 15 characters (round up). + // For text stories that include a link, +2 seconds to the playback time. + const length = attachment.textAttachment.text + ? count(attachment.textAttachment.text) + : 0; + const additionalSeconds = (Math.ceil(length / 15) - 1) * SECOND; + const linkPreviewSeconds = attachment.textAttachment.preview + ? 2 * SECOND + : 0; + return DEFAULT_DURATION + additionalSeconds + linkPreviewSeconds; + } + if (!isDownloaded(attachment) || hasNotResolved(attachment)) { return; } @@ -56,18 +70,6 @@ export async function getStoryDuration( return Math.min(duration, MAX_VIDEO_DURATION); } - if (attachment.textAttachment && attachment.textAttachment.text) { - // Minimum 5 seconds. +1 second for every 15 characters past the first - // 15 characters (round up). - // For text stories that include a link, +2 seconds to the playback time. - const length = count(attachment.textAttachment.text); - const additionalSeconds = (Math.ceil(length / 15) - 1) * SECOND; - const linkPreviewSeconds = attachment.textAttachment.preview - ? 2 * SECOND - : 0; - return DEFAULT_DURATION + additionalSeconds + linkPreviewSeconds; - } - if (attachment.caption) { const length = count(attachment.caption); const additionalSeconds = (Math.ceil(length / 15) - 1) * SECOND;