244 lines
8.1 KiB
TypeScript
244 lines
8.1 KiB
TypeScript
// Metro module 1933 (f1934).
|
|
import ImpersonateStore from "../impersonate/ImpersonateStore";
|
|
import { THREAD_CHANNEL_TYPES } from "../../records/ChannelRecord";
|
|
import { hasPermission } from "../../records/GuildRoleRecord";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../stores/GuildMemberStore";
|
|
import GuildRoleStore from "../../stores/GuildRoleStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { GuildFeatures, Permissions } from "../../Constants";
|
|
import { isSubscriptionRole, isSubscriptionRoleAvailableForPurchase } from "../guild_role_subscriptions/PremiumRoleUtils";
|
|
import * as _RolePermissionUtils from "../guild_role_subscriptions/RolePermissionUtils";
|
|
import { isChannelAccessGrantedBy, hasViewChannelPermission } from "../guild_role_subscriptions/RolePermissionUtils";
|
|
import { isRestrictedFromShowingGuildPurchaseEntryPoints } from "../creator_monetization_review/CreatorMonetizationRestrictionsUtils";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c1619_12, c1619_13, isChannelSubscriptionGatedInGuild, computeForChannel;
|
|
const isSubscriptionGated = function isSubscriptionGated({ guildId, role, isPreviewingRoles }) {
|
|
let r17 = !!isSubscriptionRole(role);
|
|
if (r17) {
|
|
let r18 = !!isPreviewingRoles;
|
|
if (!r18) {
|
|
let r22 = role;
|
|
if (r22 == null) {
|
|
r22 = void 0;
|
|
}
|
|
let r25 = !!isSubscriptionRoleAvailableForPurchase(r22);
|
|
if (!r25) {
|
|
const r5 = role == null;
|
|
let r26 = false;
|
|
if (!r5) {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
const r30 = currentUser == null;
|
|
r26 = false;
|
|
if (!r30) {
|
|
const member = GuildMemberStore.getMember(guildId, currentUser.id);
|
|
r26 = member != null && member.roles.includes(role.id);
|
|
}
|
|
}
|
|
r25 = !!r26;
|
|
}
|
|
r18 = r25;
|
|
}
|
|
r17 = r18;
|
|
}
|
|
return r17;
|
|
};
|
|
isChannelSubscriptionGatedInGuild = function isChannelSubscriptionGatedInGuild(channel, guild) {
|
|
if (!guild.features.has(GuildFeatures.CREATOR_MONETIZABLE) && !guild.features.has(GuildFeatures.CREATOR_MONETIZABLE_PROVISIONAL)) {
|
|
return false;
|
|
}
|
|
const isViewingServerShop = ImpersonateStore.isViewingServerShop(guild.id);
|
|
for (const item of Object.keys(channel.permissionOverwrites)) {
|
|
if (!isSubscriptionGated({
|
|
guildId: guild.id,
|
|
role: GuildRoleStore.getRole(guild.id, item),
|
|
isPreviewingRoles: isViewingServerShop
|
|
})) {
|
|
continue;
|
|
}
|
|
if (!isChannelAccessGrantedBy(channel, channel.permissionOverwrites[item])) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
const hasPermission2 = hasPermission(GuildRoleStore.getEveryoneRole(guild), Permissions.VIEW_CHANNEL);
|
|
const isChannelAccessDeniedBy = _RolePermissionUtils.isChannelAccessDeniedBy(channel, channel.permissionOverwrites[guild.id]);
|
|
if (!hasPermission2 && !isChannelAccessDeniedBy) {
|
|
for (const item2 of GuildRoleStore.getSortedRoles(guild.id)) {
|
|
if (!isSubscriptionGated({
|
|
guildId: guild.id,
|
|
role: item2,
|
|
isPreviewingRoles: isViewingServerShop
|
|
})) {
|
|
continue;
|
|
}
|
|
if (!hasViewChannelPermission(item2)) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
computeForChannel = function computeForChannel(guild_id, id) {
|
|
const r5 = c1619_12[guild_id];
|
|
if (r5 == null) {
|
|
return false;
|
|
}
|
|
const channel = ChannelStore.getChannel(id);
|
|
if (channel == null) {
|
|
return false;
|
|
}
|
|
const guild = GuildStore.getGuild(channel.getGuildId());
|
|
if (guild == null) {
|
|
return false;
|
|
}
|
|
const r17 = r5.has(id);
|
|
const isChannelSubscriptionGatedInGuild2 = isChannelSubscriptionGatedInGuild(channel, guild);
|
|
let r19 = r17 !== isChannelSubscriptionGatedInGuild2;
|
|
if (r19) {
|
|
if (isChannelSubscriptionGatedInGuild2) {
|
|
r5.add(id);
|
|
r19 = true;
|
|
} else {
|
|
r5.delete(id);
|
|
r19 = true;
|
|
}
|
|
}
|
|
return r19;
|
|
};
|
|
const handleInitialize = function handleInitialize() {
|
|
c1619_12 = {};
|
|
c1619_13.clear();
|
|
};
|
|
const handleGuildUpdate = function handleGuildUpdate(a0) {
|
|
delete c1619_12[a0.guild.id];
|
|
};
|
|
const handleGuildRoleUpdate = function handleGuildRoleUpdate(a0) {
|
|
delete c1619_12[a0.guildId];
|
|
};
|
|
const handleChannelUpdate = function handleChannelUpdate({ channel: channel2 }) {
|
|
let r3 = channel2.guild_id != null;
|
|
if (r3) {
|
|
const { guild_id, id } = channel2;
|
|
const r16 = c1619_12[guild_id];
|
|
const r5 = r16 == null;
|
|
let r2 = false;
|
|
if (!r5) {
|
|
const channel = ChannelStore.getChannel(id);
|
|
const r18 = channel == null;
|
|
r2 = false;
|
|
if (!r18) {
|
|
const guild = GuildStore.getGuild(channel.getGuildId());
|
|
const r23 = guild == null;
|
|
r2 = false;
|
|
if (!r23) {
|
|
const r25 = r16.has(id);
|
|
const isChannelSubscriptionGatedInGuild2 = isChannelSubscriptionGatedInGuild(channel, guild);
|
|
let r27 = r25 !== isChannelSubscriptionGatedInGuild2;
|
|
if (r27) {
|
|
if (isChannelSubscriptionGatedInGuild2) {
|
|
r16.add(id);
|
|
r27 = true;
|
|
} else {
|
|
r16.delete(id);
|
|
r27 = true;
|
|
}
|
|
}
|
|
r2 = r27;
|
|
}
|
|
}
|
|
}
|
|
r3 = r2;
|
|
}
|
|
return r3;
|
|
};
|
|
c1619_12 = {};
|
|
c1619_13 = new Set();
|
|
class GatedChannelStore extends Module589.Store {
|
|
static displayName = "GatedChannelStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, GuildMemberStore, GuildRoleStore, GuildStore, ImpersonateStore, UserStore);
|
|
}
|
|
isChannelGated(a0, a1) {
|
|
if (a0 == null) {
|
|
return false;
|
|
}
|
|
let r8 = c1619_12[a0];
|
|
if (r8 == null) {
|
|
const guild = GuildStore.getGuild(a0);
|
|
if (guild != null) {
|
|
const set = new Set();
|
|
c1619_12[a0] = set;
|
|
if (guild.features.has(GuildFeatures.ROLE_SUBSCRIPTIONS_ENABLED)) {
|
|
const mutableGuildChannelsForGuild = ChannelStore.getMutableGuildChannelsForGuild(a0);
|
|
for (const key in mutableGuildChannelsForGuild) {
|
|
const r34 = mutableGuildChannelsForGuild[key];
|
|
if (isChannelSubscriptionGatedInGuild(r34, guild)) {
|
|
set.add(r34.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
r8 = c1619_12[a0];
|
|
}
|
|
return r8 != null && r8.has(a1);
|
|
}
|
|
isChannelGatedAndVisible(a0, a1) {
|
|
return a0 != null && (this.isChannelGated(a0, a1) && !c1619_13.has(a0));
|
|
}
|
|
isChannelOrThreadParentGated(a0, a1) {
|
|
if (a0 == null) {
|
|
return false;
|
|
}
|
|
if (this.isChannelGated(a0, a1)) {
|
|
return true;
|
|
}
|
|
const channel = ChannelStore.getChannel(a1);
|
|
const r0 = channel == null || channel.parent_id == null || !THREAD_CHANNEL_TYPES.has(channel?.type);
|
|
return r0 ? !r0 : this.isChannelOrThreadParentGated(a0, channel.parent_id);
|
|
}
|
|
}
|
|
const gatedChannelStore = new GatedChannelStore(Dispatcher, {
|
|
CONNECTION_OPEN: handleInitialize,
|
|
OVERLAY_INITIALIZE: handleInitialize,
|
|
CACHE_LOADED_LAZY: handleInitialize,
|
|
GUILD_CREATE: handleGuildUpdate,
|
|
GUILD_UPDATE: handleGuildUpdate,
|
|
GUILD_DELETE: handleGuildUpdate,
|
|
GUILD_ROLE_CREATE: handleGuildRoleUpdate,
|
|
GUILD_ROLE_UPDATE: handleGuildRoleUpdate,
|
|
GUILD_ROLE_DELETE: handleGuildRoleUpdate,
|
|
IMPERSONATE_UPDATE: handleGuildRoleUpdate,
|
|
IMPERSONATE_STOP: handleGuildRoleUpdate,
|
|
CHANNEL_CREATE: handleChannelUpdate,
|
|
CHANNEL_DELETE: handleChannelUpdate,
|
|
CHANNEL_UPDATES: function handleChannelUpdates({ channels }) {
|
|
let r0 = false;
|
|
for (const item of channels) {
|
|
let r31 = item.guild_id != null;
|
|
if (r31) {
|
|
r31 = computeForChannel(item.guild_id, item.id);
|
|
}
|
|
if (r31) {
|
|
r0 = true;
|
|
}
|
|
}
|
|
return r0;
|
|
},
|
|
GUILD_ROLE_SUBSCRIPTIONS_FETCH_RESTRICTIONS_SUCCESS: function handleRoleSubscriptionsRestrictionsUpdate(a0) {
|
|
const guildId = a0.guildId;
|
|
if (isRestrictedFromShowingGuildPurchaseEntryPoints(a0.restrictions)) {
|
|
c1619_13.add(guildId);
|
|
} else {
|
|
c1619_13.delete(guildId);
|
|
}
|
|
},
|
|
GUILD_ROLE_SUBSCRIPTIONS_FETCH_RESTRICTIONS_FAILURE: function handleRoleSubscriptionsRestrictionsFetchFailure(a0) {
|
|
c1619_13.add(a0.guildId);
|
|
}
|
|
});
|
|
export default gatedChannelStore;
|