308 lines
8.8 KiB
TypeScript
308 lines
8.8 KiB
TypeScript
// Metro module 9274 (f9275).
|
|
import GuildMemberCountStore from "./GuildMemberCountStore";
|
|
import GuildStore from "./GuildStore";
|
|
import PermissionStore from "./PermissionStore";
|
|
import SelectedGuildStore from "./SelectedGuildStore";
|
|
import UserStore from "./UserStore";
|
|
import { FIRST_RUN_DATE_KEY, GuildFeatures, Permissions } from "../Constants";
|
|
import Durations from "../utils/Durations";
|
|
import { surveyFetch } from "../actions/SurveyActionCreators";
|
|
import { deserialize } from "../_bundle/HighLow";
|
|
import { Storage } from "../_bundle/Module595";
|
|
import Module3771 from "../_bundle/Module3771";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
let c6104_12, c6104_13, c6104_14, c6104_15, c6104_16, survey, c6104_18, DAY, c6104_20, c6104_21, c6104_22, setSurvey, handleSelectedGuildChange, $mk82199 = function() {
|
|
return function meetsGuildRequirements(a0) {
|
|
let r42;
|
|
const { guild_requirements = [], guild_size = [null, null], guild_permissions = [] } = a0;
|
|
if (guild_requirements.length === 0) {
|
|
return true;
|
|
}
|
|
for (const item of guild_requirements) {
|
|
if (c6104_22.has(item)) {
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
const r54 = guild_requirements.includes(c6104_21.GUILD_SIZE_ALL);
|
|
let r56 = true;
|
|
loop14: for (const r64 of GuildStore.getGuildsArray()) {
|
|
const r65 = r64;
|
|
if (!(!r54 && !guild_requirements.includes(c6104_21.GUILD_SIZE))) {
|
|
const memberCount = GuildMemberCountStore.getMemberCount(r65.id);
|
|
if (memberCount == null) {
|
|
r56 = false;
|
|
continue;
|
|
}
|
|
if (guild_size[0] != null && memberCount < guild_size[0]) {
|
|
r56 = false;
|
|
continue;
|
|
}
|
|
if (guild_size[1] != null && memberCount > guild_size[1]) {
|
|
r56 = false;
|
|
continue;
|
|
}
|
|
}
|
|
if (guild_requirements.includes(c6104_21.IS_COMMUNITY) && !r65.features.has(GuildFeatures.COMMUNITY)) {
|
|
continue;
|
|
}
|
|
if (guild_requirements.includes(c6104_21.IS_HUB) && !r65.features.has(GuildFeatures.HUB)) {
|
|
continue;
|
|
}
|
|
if (guild_requirements.includes(c6104_21.GUILD_PERMISSIONS)) {
|
|
if (guild_permissions.length === 0) {
|
|
continue;
|
|
}
|
|
let r108 = false;
|
|
let r110 = guild_permissions[Symbol.iterator]();
|
|
const next = r110.next;
|
|
while (true) {
|
|
const r113 = r110 === void 0 ? void 0 : (r42 = next.call(r110)).done ? r110 = void 0 : r42.value;
|
|
if (r110 !== void 0) {
|
|
L34: {
|
|
try {
|
|
try {
|
|
if (PermissionStore.can(deserialize(r113), r65)) {
|
|
r108 = true;
|
|
break L34;
|
|
}
|
|
continue;
|
|
} catch ($e) {
|
|
continue;
|
|
}
|
|
} catch (r126) {
|
|
if (r110 !== void 0 && typeof r110.return === "function") {
|
|
try {
|
|
r110.return();
|
|
} catch {}
|
|
}
|
|
throw r126;
|
|
}
|
|
}
|
|
const r124 = r110;
|
|
if (r124 !== void 0 && typeof r124.return === "function") {
|
|
r124.return();
|
|
}
|
|
}
|
|
if (r108) {
|
|
break;
|
|
}
|
|
continue loop14;
|
|
}
|
|
}
|
|
const id = UserStore.getCurrentUser()?.id;
|
|
const r135 = id === r65.ownerId;
|
|
const r140 = PermissionStore.can(Permissions.ADMINISTRATOR, r65);
|
|
if (guild_requirements.includes(c6104_21.IS_OWNER) && !r135) {
|
|
continue;
|
|
}
|
|
if (guild_requirements.includes(c6104_21.IS_ADMIN) && !r140) {
|
|
continue;
|
|
}
|
|
let r152 = c6104_16;
|
|
if (r152 == null) {
|
|
r152 = {};
|
|
}
|
|
c6104_16 = r152;
|
|
if (r152[a0.key] == null) {
|
|
c6104_16[a0.key] = a0;
|
|
}
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
const r161 = guildId != null && guildId === r65.id;
|
|
if (guild_requirements.includes(c6104_21.IS_VIEWING) && !r161) {
|
|
continue;
|
|
}
|
|
if (r54) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
if (r54 && r56) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
};
|
|
const fetchSurveyIfNeeded = function fetchSurveyIfNeeded() {
|
|
let r0 = c6104_18;
|
|
if (!r0) {
|
|
const r1 = c6104_13.lastFetched == null || Date.now() - c6104_13.lastFetched >= DAY;
|
|
r0 = r1 ? !r1 : c6104_13.surveyOverride == null;
|
|
}
|
|
if (!r0) {
|
|
c6104_18 = true;
|
|
surveyFetch(c6104_13.surveyOverride, true);
|
|
}
|
|
};
|
|
setSurvey = function setSurvey({ survey: survey2, isActionTriggered }) {
|
|
c6104_18 = false;
|
|
c6104_13.lastFetched = Date.now();
|
|
if (isActionTriggered) {
|
|
c6104_13.lastActionTriggered = Date.now();
|
|
}
|
|
if (c6104_13.hiddenSurveys == null) {
|
|
c6104_13.hiddenSurveys = {};
|
|
}
|
|
let r1 = survey2 != null;
|
|
const r5 = r1 ? c6104_13.hiddenSurveys[survey2.key] == null : r1;
|
|
if (r1) {
|
|
r1 = $mk82199()(survey2);
|
|
}
|
|
const r2 = c6104_14 || c6104_15;
|
|
const r38 = Storage.get(FIRST_RUN_DATE_KEY);
|
|
const r3 = r38 == null || Module3771().diff(r38, "day") < 7;
|
|
survey = r5 ? r1 ? r2 ? null : r3 ? null : survey2 : null : null;
|
|
};
|
|
handleSelectedGuildChange = function handleSelectedGuildChange() {
|
|
if (survey != null) {
|
|
let r10 = !!$mk82199()(survey);
|
|
if (!r10) {
|
|
survey = null;
|
|
r10 = false;
|
|
}
|
|
if (r10) {
|
|
return false;
|
|
}
|
|
}
|
|
let r11 = c6104_16;
|
|
if (r11 == null) {
|
|
r11 = {};
|
|
}
|
|
c6104_16 = r11;
|
|
const survey2 = Object.values(c6104_16)[0];
|
|
if (survey2 != null && $mk82199()(survey2)) {
|
|
setSurvey({
|
|
type: "SURVEY_FETCHED",
|
|
survey: survey2
|
|
});
|
|
} else if (survey != null) {
|
|
survey = null;
|
|
}
|
|
};
|
|
c6104_12 = {
|
|
hiddenSurveys: {},
|
|
surveyOverride: null,
|
|
lastFetched: null,
|
|
lastSeen: null,
|
|
lastActionTriggered: null
|
|
};
|
|
c6104_13 = c6104_12;
|
|
c6104_14 = false;
|
|
c6104_15 = false;
|
|
c6104_16 = {};
|
|
survey = null;
|
|
c6104_18 = false;
|
|
DAY = Durations.Millis.DAY;
|
|
c6104_20 = 10 * Durations.Millis.HOUR;
|
|
c6104_21 = {
|
|
IS_OWNER: "is_owner",
|
|
IS_ADMIN: "is_admin",
|
|
IS_COMMUNITY: "is_community",
|
|
GUILD_SIZE: "guild_size",
|
|
IS_HUB: "is_hub",
|
|
IS_VIEWING: "is_viewing",
|
|
GUILD_PERMISSIONS: "guild_permissions",
|
|
GUILD_SIZE_ALL: "guild_size_all"
|
|
};
|
|
c6104_22 = new Set(Object.values(c6104_21));
|
|
class SurveyStore extends Module589.PersistedStore {
|
|
static displayName = "SurveyStore";
|
|
static persistKey = "SurveyStore";
|
|
static migrations = [(a0) => {
|
|
const r1 = {
|
|
...a0
|
|
};
|
|
delete r1["validSurveys"];
|
|
delete r1["currentSurvey"];
|
|
delete r1["iosIsPushNotificationClicked"];
|
|
delete r1["iosIsInviteShown"];
|
|
delete r1["iosFirstRunDate"];
|
|
return r1;
|
|
}, (a0) => {
|
|
let lastSeen = a0.lastSeen;
|
|
if (lastSeen == null) {
|
|
lastSeen = null;
|
|
}
|
|
return {
|
|
...a0,
|
|
lastSeen
|
|
};
|
|
}, (a0) => {
|
|
let hiddenSurveys = a0.hiddenSurveys;
|
|
if (hiddenSurveys == null) {
|
|
hiddenSurveys = {};
|
|
}
|
|
return {
|
|
...a0,
|
|
hiddenSurveys
|
|
};
|
|
}];
|
|
initialize(a0) {
|
|
let r2 = a0;
|
|
this.waitFor(GuildMemberCountStore, GuildStore, PermissionStore, SelectedGuildStore, UserStore);
|
|
if (a0 == null) {
|
|
r2 = c6104_12;
|
|
}
|
|
c6104_13 = r2;
|
|
this.syncWith([SelectedGuildStore], handleSelectedGuildChange);
|
|
}
|
|
getState() {
|
|
return c6104_13;
|
|
}
|
|
getCurrentSurvey() {
|
|
return c6104_13.lastFetched == null || Date.now() - c6104_13.lastFetched >= DAY ? null : survey;
|
|
}
|
|
getSurveyOverride() {
|
|
return c6104_13.surveyOverride;
|
|
}
|
|
getLastSeenTimestamp() {
|
|
return c6104_13.lastSeen;
|
|
}
|
|
shouldAllowSurveyAction() {
|
|
const r6 = Date.now();
|
|
let lastActionTriggered = c6104_13.lastActionTriggered;
|
|
if (lastActionTriggered == null) {
|
|
lastActionTriggered = 0;
|
|
}
|
|
return r6 - lastActionTriggered >= c6104_20;
|
|
}
|
|
}
|
|
const surveyStore = new SurveyStore(Dispatcher, {
|
|
CONNECTION_OPEN: fetchSurveyIfNeeded,
|
|
CONNECTION_RESUMED: fetchSurveyIfNeeded,
|
|
SURVEY_FETCHED: setSurvey,
|
|
SURVEY_HIDE: function handleSurveyHide({ key }) {
|
|
c6104_13.hiddenSurveys[key] = true;
|
|
survey = null;
|
|
let r7 = c6104_16;
|
|
if (r7 == null) {
|
|
r7 = {};
|
|
}
|
|
c6104_16 = r7;
|
|
delete r7[key];
|
|
},
|
|
SURVEY_OVERRIDE: function handleSurveyOverride({ id }) {
|
|
c6104_13.surveyOverride = id;
|
|
if (id != null) {
|
|
delete c6104_13.hiddenSurveys[id];
|
|
}
|
|
surveyFetch(c6104_13.surveyOverride, true);
|
|
},
|
|
PUSH_NOTIFICATION_CLICK: function handlePushNotificationClick() {
|
|
c6104_14 = true;
|
|
},
|
|
DISPLAYED_INVITE_SHOW: function handleInviteShow() {
|
|
c6104_15 = true;
|
|
},
|
|
LOGOUT: function handleLogout() {
|
|
c6104_13.hiddenSurveys = {};
|
|
},
|
|
SURVEY_SEEN: function handleSurveySeen() {
|
|
c6104_13.lastSeen = Date.now();
|
|
}
|
|
});
|
|
export default surveyStore;
|
|
export { DAY as SURVEY_REFETCH_INTERVAL };
|
|
export { c6104_20 as SURVEY_ACTION_INTERVAL };
|