148 lines
6.0 KiB
TypeScript
148 lines
6.0 KiB
TypeScript
// Metro module 10264 (f10265).
|
|
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import SelectedGuildStore from "../../stores/SelectedGuildStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import GuildIncidentsStore from "./GuildIncidentsStore";
|
|
import { IncidentAlertModeratorPermissions } from "./GuildAntiRaidConstants";
|
|
import { EMPTY_STRING_SNOWFLAKE_ID, GuildFeatures } from "../../Constants";
|
|
import { useStateFromStores, useStateFromStoresArray } from "../../_bundle/defaultAreStatesEqual";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import * as _GuildAntiRaidUtils from "./GuildAntiRaidUtils";
|
|
import { hasDetectedActivity } from "./GuildAntiRaidUtils";
|
|
import { hasAny } from "../../_bundle/HighLow";
|
|
import { computePermissions } from "../../utils/PermissionUtils";
|
|
import { canReportRaid } from "./GuildAntiRaidPermissionsUtils";
|
|
const getFirstGuildIncidentId = function getFirstGuildIncidentId(a0) {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
const incidentsByGuild = GuildIncidentsStore.getIncidentsByGuild();
|
|
for (const item of SnowflakeUtils.keys(incidentsByGuild).map((item) => GuildStore.getGuild(item))) {
|
|
const context = item;
|
|
if (item == null) {
|
|
continue;
|
|
}
|
|
const r47 = incidentsByGuild[context.id];
|
|
if (r47 == null) {
|
|
continue;
|
|
}
|
|
if (!hasDetectedActivity(r47) && !_GuildAntiRaidUtils.isUnderLockdown(r47)) {
|
|
continue;
|
|
}
|
|
if (_GuildAntiRaidUtils.isUnderLockdown(r47) && context.id !== a0) {
|
|
continue;
|
|
}
|
|
if (!hasAny(computePermissions({
|
|
user: currentUser,
|
|
context,
|
|
checkElevated: false
|
|
}), IncidentAlertModeratorPermissions)) {
|
|
continue;
|
|
}
|
|
return context.id;
|
|
}
|
|
return null;
|
|
};
|
|
export function useFirstGuildIncidentId() {
|
|
let stateFromStores;
|
|
const stateFromStores2 = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
stateFromStores = useStateFromStores([GuildIncidentsStore], () => GuildIncidentsStore.getIncidentsByGuild());
|
|
for (const item of useStateFromStoresArray([GuildStore], () => SnowflakeUtils.keys(stateFromStores).map((item) => GuildStore.getGuild(item)))) {
|
|
const context = item;
|
|
if (item == null) {
|
|
continue;
|
|
}
|
|
const r55 = stateFromStores[context.id];
|
|
if (r55 == null) {
|
|
continue;
|
|
}
|
|
if (!hasDetectedActivity(r55) && !_GuildAntiRaidUtils.isUnderLockdown(r55)) {
|
|
continue;
|
|
}
|
|
if (!hasAny(computePermissions({
|
|
user: stateFromStores2,
|
|
context,
|
|
checkElevated: false
|
|
}), IncidentAlertModeratorPermissions)) {
|
|
continue;
|
|
}
|
|
return context.id;
|
|
}
|
|
return null;
|
|
}
|
|
export function useGuildIncidentsState(c17817_0) {
|
|
const stateFromStores2 = useStateFromStores([GuildStore, PermissionStore], () => {
|
|
const guild = GuildStore.getGuild(c17817_0);
|
|
if (guild == null) {
|
|
return false;
|
|
}
|
|
const guildPermissions = PermissionStore.getGuildPermissions(guild);
|
|
return guildPermissions != null && hasAny(guildPermissions, IncidentAlertModeratorPermissions);
|
|
});
|
|
const stateFromStores3 = useStateFromStores([GuildIncidentsStore], () => c17817_0 != null ? GuildIncidentsStore.getGuildIncident(c17817_0) : null);
|
|
return {
|
|
shouldShowIncidentActions: stateFromStores2,
|
|
incidentData: stateFromStores3,
|
|
isUnderLockdown: stateFromStores3 != null && _GuildAntiRaidUtils.isUnderLockdown(stateFromStores3)
|
|
};
|
|
}
|
|
export function shouldShowRaidNotificationNagbar() {
|
|
const firstGuildIncidentId = getFirstGuildIncidentId(SelectedGuildStore.getGuildId());
|
|
let r11 = UserSettingsProtoStore.getGuildsProto();
|
|
if (r11 == null) {
|
|
r11 = {};
|
|
}
|
|
const r12 = firstGuildIncidentId != null ? r11[firstGuildIncidentId] : null;
|
|
const r13 = r12 != null && r12.disableRaidAlertNag;
|
|
return {
|
|
show: firstGuildIncidentId != null && !r13,
|
|
guildId: firstGuildIncidentId
|
|
};
|
|
}
|
|
export function shouldShowRaidInAppNotification() {
|
|
const firstGuildIncidentId = getFirstGuildIncidentId(SelectedGuildStore.getGuildId());
|
|
let r13 = UserSettingsProtoStore.getGuildsProto();
|
|
if (r13 == null) {
|
|
r13 = {};
|
|
}
|
|
const r14 = firstGuildIncidentId != null ? r13[firstGuildIncidentId] : null;
|
|
const r15 = r14 != null && r14.disableRaidAlertNag;
|
|
const r8 = firstGuildIncidentId != null ? GuildIncidentsStore.getGuildIncident(firstGuildIncidentId) : null;
|
|
const r18 = r8 != null && _GuildAntiRaidUtils.isUnderLockdown(r8);
|
|
return {
|
|
show: firstGuildIncidentId != null && !r18 && !r15,
|
|
guildId: firstGuildIncidentId
|
|
};
|
|
}
|
|
export function getDisabledActions(a0) {
|
|
if (a0 == null) {
|
|
return {
|
|
dmsDisabled: false,
|
|
invitesDisabled: false
|
|
};
|
|
}
|
|
const guildIncident = GuildIncidentsStore.getGuildIncident(a0.id);
|
|
return {
|
|
invitesDisabled: (a0 == null ? void 0 : a0.features.has(GuildFeatures.INVITES_DISABLED)) || guildIncident?.invitesDisabledUntil != null && new Date(guildIncident.invitesDisabledUntil) > new Date(),
|
|
dmsDisabled: guildIncident?.dmsDisabledUntil != null && new Date(guildIncident.dmsDisabledUntil) > new Date()
|
|
};
|
|
}
|
|
export function useDisabledActions(a0) {
|
|
let r11 = a0?.id;
|
|
if (r11 == null) {
|
|
r11 = EMPTY_STRING_SNOWFLAKE_ID;
|
|
}
|
|
const EMPTY_STRING_SNOWFLAKE_ID2 = r11;
|
|
const stateFromStores2 = useStateFromStores([GuildIncidentsStore], () => GuildIncidentsStore.getGuildIncident(EMPTY_STRING_SNOWFLAKE_ID2), [EMPTY_STRING_SNOWFLAKE_ID2]);
|
|
return a0 == null ? {
|
|
dmsDisabled: false,
|
|
invitesDisabled: false
|
|
} : {
|
|
invitesDisabled: (a0 == null ? void 0 : a0.features.has(GuildFeatures.INVITES_DISABLED)) || stateFromStores2?.invitesDisabledUntil != null && new Date(stateFromStores2.invitesDisabledUntil) > new Date(),
|
|
dmsDisabled: stateFromStores2?.dmsDisabledUntil != null && new Date(stateFromStores2.dmsDisabledUntil) > new Date()
|
|
};
|
|
}
|
|
export function useShowAntiRaidInGuildNotifSettings(c17819_0) {
|
|
return useStateFromStores([PermissionStore, GuildStore], () => canReportRaid(GuildStore.getGuild(c17819_0), PermissionStore));
|
|
}
|