273 lines
9.4 KiB
TypeScript
273 lines
9.4 KiB
TypeScript
// Metro module 1364 (f1365).
|
|
import LoginRequiredActionStore from "../auth/LoginRequiredActionStore";
|
|
import UserRequiredActionStore from "../../stores/UserRequiredActionStore";
|
|
import { TaskRunner } from "./TaskRunner";
|
|
import { createWithEqualityFn } from "../../_bundle/identity_700";
|
|
import { CONTENT_TYPES_WITH_BYPASS_FATIGUE } from "./DismissibleContentFatigueConfig";
|
|
import { batchUpdates } from "../../_bundle/Module705";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import isActionRequired from "../core/isActionRequired";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c1133_5, withEqualityFn, c1133_7, withUpdateWinner, $mk69091 = function() {
|
|
return () => {
|
|
withEqualityFn.setState(() => ({
|
|
candidates: new Map(),
|
|
shownFatigableCandidate: null,
|
|
prevFatigableCandidate: null,
|
|
recentlyShown: [],
|
|
currentlyShown: new Set(),
|
|
currentlyShownGroup: new Set(),
|
|
lastWinnerTime: 0,
|
|
postConnectionOpen: true
|
|
}));
|
|
};
|
|
};
|
|
const withContent = function withContent(a0, a1) {
|
|
if (a1 == null) {
|
|
return a0;
|
|
}
|
|
a0.currentlyShown.add(a1.content);
|
|
const recentlyShown = a0.recentlyShown.filter((item) => item !== a1.content);
|
|
recentlyShown.unshift(a1.content);
|
|
recentlyShown.splice(5);
|
|
a0.recentlyShown = recentlyShown;
|
|
if (a1.groupName != null) {
|
|
a0.currentlyShownGroup.add(a1.groupName);
|
|
}
|
|
if (!CONTENT_TYPES_WITH_BYPASS_FATIGUE.has(a1.content)) {
|
|
a0.shownFatigableCandidate = a1;
|
|
if (a0.prevFatigableCandidate?.content !== a1.content) {
|
|
a0.prevFatigableCandidate = a1;
|
|
a0.lastWinnerTime = new Date().getTime();
|
|
}
|
|
}
|
|
const onAdded = a1.onAdded;
|
|
if (onAdded != null) {
|
|
onAdded.call(a1);
|
|
}
|
|
return a0;
|
|
};
|
|
withUpdateWinner = function withUpdateWinner(a0) {
|
|
if (a0.candidates.size === 0) {
|
|
return a0;
|
|
}
|
|
const r8 = new Date().getTime() - a0.lastWinnerTime;
|
|
const r26 = a0.prevFatigableCandidate != null && a0.candidates.has(a0.prevFatigableCandidate.content) && a0.shownFatigableCandidate == null;
|
|
const r4 = r8 > 300000;
|
|
if (r26 && !r4) {
|
|
c1133_5.unschedule();
|
|
const r35 = a0.prevFatigableCandidate != null ? a0.candidates.get(a0.prevFatigableCandidate.content) : void 0;
|
|
const shownFatigableCandidate = a0.shownFatigableCandidate;
|
|
if (shownFatigableCandidate != null) {
|
|
if (shownFatigableCandidate.content != null) {
|
|
a0.currentlyShown.delete(shownFatigableCandidate.content);
|
|
}
|
|
if (shownFatigableCandidate.groupName != null) {
|
|
a0.currentlyShownGroup.delete(shownFatigableCandidate.groupName);
|
|
}
|
|
if (a0.shownFatigableCandidate?.content === shownFatigableCandidate.content) {
|
|
a0.shownFatigableCandidate = null;
|
|
}
|
|
}
|
|
withContent(a0, r35);
|
|
} else if (!(a0.shownFatigableCandidate != null && !r4)) {
|
|
let r57 = c1133_5.scheduled();
|
|
if (!r57) {
|
|
const time = new Date().getTime();
|
|
r57 = a0.shownFatigableCandidate == null && time - a0.lastWinnerTime < 3600000;
|
|
}
|
|
if (!r57) {
|
|
c1133_5.schedule(() => {
|
|
batchUpdates(() => {
|
|
withEqualityFn.setState((state) => {
|
|
const r4 = {
|
|
...state,
|
|
candidates: new Map(state.candidates),
|
|
currentlyShown: new Set(state.currentlyShown),
|
|
currentlyShownGroup: new Set(state.currentlyShownGroup)
|
|
};
|
|
let c31235_0 = r4;
|
|
const r36 = [...r4.candidates.keys()];
|
|
const r45 = r4.prevFatigableCandidate !== null && r4.candidates.has(r4.prevFatigableCandidate.content) && r4.candidates.size > 1 ? r36.filter((item) => item !== c31235_0.prevFatigableCandidate?.content) : r36;
|
|
const r59 = r4.candidates.get(r45[Math.floor(Math.random() * r45.length)]);
|
|
const shownFatigableCandidate = r4.shownFatigableCandidate;
|
|
if (shownFatigableCandidate != null) {
|
|
if (shownFatigableCandidate.content != null) {
|
|
r4.currentlyShown.delete(shownFatigableCandidate.content);
|
|
}
|
|
if (shownFatigableCandidate.groupName != null) {
|
|
r4.currentlyShownGroup.delete(shownFatigableCandidate.groupName);
|
|
}
|
|
if (r4.shownFatigableCandidate?.content === shownFatigableCandidate.content) {
|
|
r4.shownFatigableCandidate = null;
|
|
}
|
|
}
|
|
withContent(r4, r59);
|
|
return r4;
|
|
});
|
|
});
|
|
}, 250);
|
|
}
|
|
}
|
|
return a0;
|
|
};
|
|
c1133_5 = new TaskRunner();
|
|
withEqualityFn = createWithEqualityFn(function initState() {
|
|
return {
|
|
candidates: new Map(),
|
|
shownFatigableCandidate: null,
|
|
prevFatigableCandidate: null,
|
|
recentlyShown: [],
|
|
currentlyShown: new Set(),
|
|
currentlyShownGroup: new Set(),
|
|
lastWinnerTime: 0,
|
|
postConnectionOpen: false
|
|
};
|
|
});
|
|
c1133_7 = false;
|
|
class DismissibleContentShownStateStore extends Module589.Store {
|
|
static displayName = "DismissibleContentShownStateStore";
|
|
initialize() {
|
|
this.waitFor(LoginRequiredActionStore, UserRequiredActionStore);
|
|
this.syncWith([LoginRequiredActionStore, UserRequiredActionStore], () => this.setHasRequiredAction());
|
|
}
|
|
setHasRequiredAction() {
|
|
c1133_7 = isActionRequired(LoginRequiredActionStore, UserRequiredActionStore);
|
|
}
|
|
}
|
|
export const dismissibleContentShownStateStore = new DismissibleContentShownStateStore(Dispatcher, {
|
|
CONNECTION_OPEN: () => {
|
|
batchUpdates($mk69091());
|
|
c1133_5.unschedule();
|
|
},
|
|
LOGOUT: () => {
|
|
batchUpdates($mk69091());
|
|
c1133_5.unschedule();
|
|
}
|
|
});
|
|
export default function useDismissibleContentShownStateStore(a0, a1) {
|
|
return withEqualityFn(a0, a1);
|
|
};
|
|
export function isInCooldown() {
|
|
const state = withEqualityFn.getState();
|
|
const time = new Date().getTime();
|
|
return state.shownFatigableCandidate == null && time - state.lastWinnerTime < 3600000;
|
|
}
|
|
export function isStateInCooldown(a0) {
|
|
const time = new Date().getTime();
|
|
return a0.shownFatigableCandidate == null && time - a0.lastWinnerTime < 3600000;
|
|
}
|
|
export function addCandidateContent(a0) {
|
|
let c12984_1 = CONTENT_TYPES_WITH_BYPASS_FATIGUE.has(a0.content);
|
|
batchUpdates(() => {
|
|
withEqualityFn.setState((state) => {
|
|
const r1 = {
|
|
...state,
|
|
candidates: new Map(state.candidates),
|
|
currentlyShown: new Set(state.currentlyShown),
|
|
currentlyShownGroup: new Set(state.currentlyShownGroup)
|
|
};
|
|
if (!c1133_7) {
|
|
if (c12984_1) {
|
|
withContent(r1, a0);
|
|
} else {
|
|
r1.candidates.set(a0.content, a0);
|
|
withUpdateWinner(r1);
|
|
}
|
|
}
|
|
return r1;
|
|
});
|
|
});
|
|
}
|
|
export function removeCandidateContent(c12985_0, c12985_1) {
|
|
batchUpdates(() => {
|
|
withEqualityFn.setState((state) => {
|
|
const r3 = {
|
|
...state,
|
|
candidates: new Map(state.candidates),
|
|
currentlyShown: new Set(state.currentlyShown),
|
|
currentlyShownGroup: new Set(state.currentlyShownGroup)
|
|
};
|
|
if (c12985_1) {
|
|
r3.candidates.delete(c12985_0.content);
|
|
if (c12985_0 != null) {
|
|
if (c12985_0.content != null) {
|
|
r3.currentlyShown.delete(c12985_0.content);
|
|
}
|
|
if (c12985_0.groupName != null) {
|
|
r3.currentlyShownGroup.delete(c12985_0.groupName);
|
|
}
|
|
if (r3.shownFatigableCandidate?.content === c12985_0.content) {
|
|
r3.shownFatigableCandidate = null;
|
|
}
|
|
}
|
|
withUpdateWinner(r3);
|
|
} else {
|
|
r3.candidates.delete(c12985_0.content);
|
|
if (c12985_0 != null) {
|
|
if (c12985_0.content != null) {
|
|
r3.currentlyShown.delete(c12985_0.content);
|
|
}
|
|
if (c12985_0.groupName != null) {
|
|
r3.currentlyShownGroup.delete(c12985_0.groupName);
|
|
}
|
|
if (r3.shownFatigableCandidate?.content === c12985_0.content) {
|
|
r3.shownFatigableCandidate = null;
|
|
}
|
|
}
|
|
}
|
|
return r3;
|
|
});
|
|
});
|
|
}
|
|
export function getLastShownDismissibleContent() {
|
|
let r6 = withEqualityFn.getState().recentlyShown[0];
|
|
if (r6 == null) {
|
|
r6 = null;
|
|
}
|
|
return r6;
|
|
}
|
|
export function getCurrentFatigableWinner() {
|
|
let r7 = withEqualityFn.getState().shownFatigableCandidate?.content;
|
|
if (r7 == null) {
|
|
r7 = null;
|
|
}
|
|
return r7;
|
|
}
|
|
export function isContentShown(a0) {
|
|
return withEqualityFn.getState().currentlyShown.has(a0);
|
|
}
|
|
export function useIsContentShown(c12986_0) {
|
|
return withEqualityFn((a0) => a0.currentlyShown.has(c12986_0));
|
|
}
|
|
export function useIsAnyContentShown(c12987_0) {
|
|
return withEqualityFn((c24398_0) => c12987_0.some((item) => c24398_0.currentlyShown.has(item)));
|
|
}
|
|
export function isAnyContentShown(a0) {
|
|
const currentlyShown = withEqualityFn.getState().currentlyShown;
|
|
return a0.find((item) => currentlyShown.has(item));
|
|
}
|
|
export function getCurrentlyShownCounts() {
|
|
const length = [...withEqualityFn.getState().currentlyShown].filter((item) => !CONTENT_TYPES_WITH_BYPASS_FATIGUE.has(item)).length;
|
|
return [withEqualityFn.getState().currentlyShown.size, length];
|
|
}
|
|
export function reset() {
|
|
batchUpdates($mk69091());
|
|
c1133_5.unschedule();
|
|
}
|
|
export function resetFatigueCooldown() {
|
|
batchUpdates(() => {
|
|
withEqualityFn.setState((state) => ({
|
|
...state,
|
|
candidates: new Map(state.candidates),
|
|
currentlyShown: new Set(state.currentlyShown),
|
|
currentlyShownGroup: new Set(state.currentlyShownGroup),
|
|
prevFatigableCandidate: null,
|
|
lastWinnerTime: 0
|
|
}));
|
|
});
|
|
}
|
|
export function isPostConnectionOpen() {
|
|
return withEqualityFn.getState().postConnectionOpen;
|
|
}
|