171 lines
5.9 KiB
TypeScript
171 lines
5.9 KiB
TypeScript
// Metro module 1362 (f1363).
|
|
import { AnalyticEvents } from "../../Constants";
|
|
import { CONTENT_TYPES_WITH_BYPASS_FATIGUE } from "./DismissibleContentFatigueConfig";
|
|
import { isGuildDismissibleContent } from "./DismissibleContentTypes";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c1132_4 = {
|
|
numberOfDCsShownToday: 0,
|
|
dailyCapPeriodStart: null,
|
|
dismissibleContentSeenDuringSession: new Set(),
|
|
dailyCapOverridden: false,
|
|
newUserMinAgeRequiredOverridden: false,
|
|
renderedAtTimestamps: new Map(),
|
|
lastDismissed: null,
|
|
seenForGuildId: new Map()
|
|
};
|
|
class DismissibleContentFrameworkStore extends Module589.PersistedStore {
|
|
static displayName = "DismissibleContentFrameworkStore";
|
|
static persistKey = "DismissibleContentFrameworkStore";
|
|
static migrations = [(a0) => ({
|
|
...a0
|
|
})];
|
|
initialize(a0) {
|
|
if (a0 != null) {
|
|
let numberOfDCsShownToday = a0.numberOfDCsShownToday;
|
|
if (numberOfDCsShownToday == null) {
|
|
numberOfDCsShownToday = 0;
|
|
}
|
|
c1132_4.numberOfDCsShownToday = numberOfDCsShownToday;
|
|
c1132_4.dailyCapPeriodStart = a0.dailyCapPeriodStart;
|
|
let dailyCapOverridden2 = a0.dailyCapOverridden;
|
|
if (dailyCapOverridden2 == null) {
|
|
dailyCapOverridden2 = false;
|
|
}
|
|
c1132_4.dailyCapOverridden = dailyCapOverridden2;
|
|
let newUserMinAgeRequiredOverridden2 = a0.newUserMinAgeRequiredOverridden;
|
|
if (newUserMinAgeRequiredOverridden2 == null) {
|
|
newUserMinAgeRequiredOverridden2 = false;
|
|
}
|
|
c1132_4.newUserMinAgeRequiredOverridden = newUserMinAgeRequiredOverridden2;
|
|
}
|
|
c1132_4.dismissibleContentSeenDuringSession = new Set();
|
|
c1132_4.seenForGuildId = new Map();
|
|
c1132_4.lastDismissed = null;
|
|
}
|
|
getState() {
|
|
return c1132_4;
|
|
}
|
|
get dailyCapOverridden() {
|
|
return c1132_4.dailyCapOverridden;
|
|
}
|
|
get newUserMinAgeRequiredOverridden() {
|
|
return c1132_4.newUserMinAgeRequiredOverridden;
|
|
}
|
|
get lastDismissed() {
|
|
return c1132_4.lastDismissed;
|
|
}
|
|
getRenderedAtTimestamp(a0) {
|
|
return c1132_4.renderedAtTimestamps.get(a0);
|
|
}
|
|
hasUserHitDCCap(a0, a1) {
|
|
L3: {
|
|
if (a0 != null) {
|
|
if (!CONTENT_TYPES_WITH_BYPASS_FATIGUE.has(a0) && !c1132_4.dailyCapOverridden) {
|
|
break L3;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
if (a0 != null) {
|
|
const r22 = a1 != null && isGuildDismissibleContent(a0);
|
|
if (r22 && a1 != null) {
|
|
const r31 = c1132_4.seenForGuildId.get(a1);
|
|
if (r31 != null && r31.has(a0)) {
|
|
return false;
|
|
}
|
|
}
|
|
if (!r22 && c1132_4.dismissibleContentSeenDuringSession.has(a0)) {
|
|
return false;
|
|
}
|
|
}
|
|
const date = new Date();
|
|
date.setHours(0, 0, 0, 0);
|
|
if (c1132_4.dailyCapPeriodStart != null && c1132_4.dailyCapPeriodStart < date.getTime()) {
|
|
c1132_4.numberOfDCsShownToday = 0;
|
|
c1132_4.dailyCapPeriodStart = null;
|
|
}
|
|
return c1132_4.numberOfDCsShownToday >= 3;
|
|
}
|
|
}
|
|
const dismissibleContentFrameworkStore = new DismissibleContentFrameworkStore(Dispatcher, {
|
|
LOGOUT: function handleLogout() {
|
|
c1132_4 = {
|
|
...c1132_4,
|
|
dismissibleContentSeenDuringSession: new Set(),
|
|
renderedAtTimestamps: new Map(),
|
|
seenForGuildId: new Map()
|
|
};
|
|
},
|
|
DCF_DAILY_CAP_OVERRIDE: function handleDailyCapOverride(a0) {
|
|
c1132_4.dailyCapOverridden = a0.value;
|
|
},
|
|
DCF_NEW_USER_MIN_AGE_REQUIRED_OVERRIDE: function handleNewUserMinAgeRequiredOverride(a0) {
|
|
c1132_4.newUserMinAgeRequiredOverridden = a0.value;
|
|
},
|
|
DCF_HANDLE_DC_SHOWN: function handleDCShownToUser(a0) {
|
|
L19: {
|
|
const { dismissibleContent, guildId } = a0;
|
|
c1132_4.renderedAtTimestamps.set(dismissibleContent, new Date().getTime());
|
|
if (!CONTENT_TYPES_WITH_BYPASS_FATIGUE.has(dismissibleContent) && !c1132_4.dailyCapOverridden) {
|
|
const r36 = isGuildDismissibleContent(dismissibleContent) && guildId != null;
|
|
if (!r36 && c1132_4.dismissibleContentSeenDuringSession.has(dismissibleContent)) {
|
|
break L19;
|
|
}
|
|
if (r36) {
|
|
const r11 = c1132_4.seenForGuildId.get(guildId);
|
|
if (r11 != null && r11.has(dismissibleContent)) {
|
|
break L19;
|
|
}
|
|
}
|
|
if (r36) {
|
|
let r53 = c1132_4.seenForGuildId.get(guildId);
|
|
if (r53 == null) {
|
|
r53 = new Set();
|
|
}
|
|
r53.add(dismissibleContent);
|
|
c1132_4.seenForGuildId.set(guildId, r53);
|
|
} else {
|
|
c1132_4.dismissibleContentSeenDuringSession.add(dismissibleContent);
|
|
}
|
|
if (c1132_4.dailyCapPeriodStart == null) {
|
|
const date = new Date();
|
|
date.setHours(0, 0, 0, 0);
|
|
c1132_4.dailyCapPeriodStart = date.getTime();
|
|
}
|
|
c1132_4.numberOfDCsShownToday = c1132_4.numberOfDCsShownToday + 1;
|
|
if (c1132_4.numberOfDCsShownToday > 3) {
|
|
AnalyticsUtils.track(AnalyticEvents.DCF_CAP_EXCEEDED, {
|
|
cap_type: "daily_cap",
|
|
dismissible_content: dismissibleContent,
|
|
shown_dcs: c1132_4.numberOfDCsShownToday
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
DCF_HANDLE_DC_DISMISSED: function handleDCDismissed(a0) {
|
|
const dismissibleContent = a0.dismissibleContent;
|
|
c1132_4.lastDismissed = {
|
|
content: dismissibleContent,
|
|
guildId: a0.guildId
|
|
};
|
|
c1132_4.renderedAtTimestamps.delete(dismissibleContent);
|
|
},
|
|
DCF_OVERRIDE_LAST_DC_DISMISSED: function handleResetLastDCDismissed({ dismissibleContent, guildId }) {
|
|
c1132_4.lastDismissed = dismissibleContent != null ? {
|
|
content: dismissibleContent,
|
|
guildId
|
|
} : null;
|
|
},
|
|
DCF_RESET: function resetStore() {
|
|
c1132_4.dailyCapPeriodStart = null;
|
|
c1132_4.numberOfDCsShownToday = 0;
|
|
c1132_4.dismissibleContentSeenDuringSession = new Set();
|
|
c1132_4.seenForGuildId = new Map();
|
|
c1132_4.lastDismissed = null;
|
|
}
|
|
});
|
|
export default dismissibleContentFrameworkStore;
|