Files
discord-decomp/modules/quests/utils/VideoQuestUtils.tsx
T
2026-11-01 12:12:55 +02:00

108 lines
4.0 KiB
TypeScript

// Metro module 10500 (f10501).
import NetworkStore from "../../../stores/NetworkStore";
import QuestStore from "../QuestStore";
import VideoQuestUIStore from "../VideoQuestUIStore";
import { AnalyticEvents } from "../../../Constants";
import { isQuestExpired } from "./QuestDataUtils";
import { updateVideoProgress } from "../QuestActionCreators";
import { getRemainingTaskTime, hasWatchVideoTasks } from "./QuestTaskUtils";
import { intl, t } from "../../../intl/index.native";
import { trackQuestEvent } from "../lib/analytics/AnalyticsActions";
import { isModalOpen } from "../../main_tabs_v2/helpers/NavigationRouteUtils.native";
import * as _MobileQuestVideoWatchCtaCopy from "./MobileQuestVideoWatchCtaCopy";
let c7045_6 = "portrait";
export const getVideoQuestWatchCtaText = _MobileQuestVideoWatchCtaCopy.getVideoQuestWatchCtaText;
export function sendVideoProgress(a0, a1) {
if (!(isQuestExpired(a0) || a0.userStatus?.enrolledAt == null || a0.userStatus?.completedAt != null)) {
updateVideoProgress(a0.id, a1);
}
}
export function getVideoOrientation(a0) {
let r9;
L7: {
const video = a0.assets.video;
if (video != null && (video.width != null && video.height != null)) {
const r8 = video.width > video.height;
r9 = "portrait";
if (!r8) {
break L7;
}
r9 = "landscape";
} else {
r9 = c7045_6;
}
}
return r9;
}
export function getVideoQuestProgressRemainingAccessibilityLabel(a0, a1) {
if (a1) {
return intl.string(t["ij5E/5"]);
}
const remainingTaskTime = getRemainingTaskTime(a0);
const { minutes, seconds } = remainingTaskTime;
return intl.formatToPlainString(t.nzYZrt, {
remainingTime: minutes > 0 && seconds > 0 ? intl.formatToPlainString(t["lW/66D"], {
minutes,
seconds
}) : minutes > 0 ? intl.formatToPlainString(t["SxnF/O"], {
count: minutes
}) : intl.formatToPlainString(t["0BZpdi"], {
count: seconds
})
});
}
export function formatVideoProgressRatio(a0, a1) {
return a0 <= 0 ? 0 : a1 <= 0 ? 0 : a0 >= a1 ? 1 : Math.min(1, Math.round(a0 / a1 * 100) / 100);
}
export function getVideoQuestEndCardCtaText(a0) {
let buttonLabel = a0.ctaConfig.buttonLabel;
if (buttonLabel == null) {
buttonLabel = intl.string(t.iiTtpJ);
}
return buttonLabel;
}
export function handleVideoQuestModalClose({ questId, sourceQuestContent, videoSessionId }) {
VideoQuestUIStore.getState().setTranscriptEnabled(false);
const videoProgress = VideoQuestUIStore.getState().getVideoProgress(questId);
if (videoProgress != null) {
const quest = QuestStore.getQuest(questId);
if (quest != null && quest.userStatus?.enrolledAt != null && quest.userStatus?.completedAt == null) {
const maxTimestampSec = videoProgress.maxTimestampSec;
if (!(isQuestExpired(quest) || quest.userStatus?.enrolledAt == null || quest.userStatus?.completedAt != null)) {
updateVideoProgress(quest.id, maxTimestampSec);
}
}
const { maxTimestampSec: maxTimestampSec2, duration } = videoProgress;
const progress = maxTimestampSec2 <= 0 ? 0 : duration <= 0 ? 0 : maxTimestampSec2 >= duration ? 1 : Math.min(1, Math.round(maxTimestampSec2 / duration * 100) / 100);
trackQuestEvent({
questId,
event: AnalyticEvents.QUEST_VIDEO_PROGRESSED,
properties: {
progress,
video_timestamp_seconds: videoProgress.maxTimestampSec,
video_session_id: videoSessionId
},
sourceQuestContent
});
trackQuestEvent({
questId,
event: AnalyticEvents.QUEST_VIDEO_MODAL_CLOSED,
properties: {
video_progress: progress,
video_session_id: videoSessionId,
network_connection_speed: NetworkStore.getEffectiveConnectionSpeed()
},
sourceQuestContent
});
}
}
export function getVideoQuestModalKey(a0) {
return `VIDEO-QUEST-${a0}`;
}
export function computeMaxSeekableTime(a0, a1) {
return a0 >= a1 - 1 ? Math.max(a0, a1) : a0;
}
export function isVideoQuestProgressing(a0) {
return !!hasWatchVideoTasks(a0) && isModalOpen(`VIDEO-QUEST-${a0.id}`);
}