decord/alpha/source/modules/threads/ThreadHooks.tsx
github-actions f95a0071ef chore: update source for alpha 349.1
Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/05xxx/module_5021.js (118.4 MB)
2026-09-29 09:27:02 +00:00

577 lines
20 KiB
TypeScript

// Module ID: 6853
// Function ID: 6854
// Name: ThreadHooks
// Dependencies: [32, 4749, 2049, 502, 2045, 4469, 5985, 1074, 504, 1086, 6854, 11, 12, 6855, 6856, 5046, 2]
// Exports: computeCanStartPrivateThread, computeCanStartPublicThread, computeIsReadOnlyThread, getIsActiveChannelOrUnarchivableThread, isNonModInLockedThread, isThreadModerator, useCanJoinThreadVoice, useCanManageThread, useCanRemoveThreadMember, useCanStartPublicThread, useCanStartThread, useCanViewThreadForMessage, useHasActiveThreads, useHasPermissionToJoinThreadVoice, useIsActiveChannelOrUnarchivableThread, useIsNonModInLockedThread, useIsThreadModerator
// Module 6853 (ThreadHooks)
import SnowflakeUtilsDefault from "SnowflakeUtils" /* 11 */;
import _modDef12 from "module_12" /* 12 */;
import BigFlagUtilsAll from "BigFlagUtils" /* 1086 */;
import isSystemMessageDefault from "isSystemMessage" /* 6854 */;
import useIsRemoteDefault from "useIsRemote" /* 6855 */;
import _slicedToArray from "module_32" /* 32 */;
import createExperiment from "createExperiment" /* 4749 */;
import AuthenticationStore from "AuthenticationStore" /* 502 */;
import ChannelStore from "ChannelStore" /* 2045 */;
import PermissionStore from "PermissionStore" /* 4469 */;
import ActiveJoinedThreadsStore from "ActiveJoinedThreadsStore" /* 5985 */;
const require = globalThis.__r;
const require = fn;
function useCanStartPrivateThread(type) {
_require = type;
const items = [PermissionStore];
const items1 = [type];
let tmp3 = type.type === constants3.GUILD_TEXT;
const stateFromStores = require("initialize").useStateFromStores(items, () => PermissionStore.can(BigFlagUtilsAll.combine(constants.CREATE_PRIVATE_THREADS), closure_0), items1);
if (!tmp3) {
tmp3 = type.type === tmp2.GUILD_APP;
}
if (tmp3) {
let flag = false;
if (stateFromStores) {
flag = false;
if (THREADED_CHANNEL_TYPES.has(type.type)) {
flag = true;
}
}
tmp3 = flag;
}
return tmp3;
}
function useCanUnarchiveThread(channel) {
_require = channel;
const items = [PermissionStore];
let stateFromStores = require("initialize").useStateFromStores(items, () => {
let canResult = null != closure_0;
if (canResult) {
canResult = PermissionStore.can(constants.SEND_MESSAGES_IN_THREADS, tmp);
}
if (canResult) {
canResult = PermissionStore.can(constants.SEND_MESSAGES, tmp);
}
return canResult;
});
const obj = require("initialize");
const items1 = [PermissionStore, ChannelStore];
const items2 = [channel];
closure_129_0 = channel;
const stateFromStores1 = require("initialize").useStateFromStores(items1, () => {
channel = null;
if (null != closure_0) {
channel = ChannelStore.getChannel(tmp.parent_id);
}
let canResult = null != channel;
if (canResult) {
canResult = PermissionStore.can(constants.SEND_MESSAGES_IN_THREADS, tmp);
}
if (canResult) {
canResult = PermissionStore.can(constants.SEND_MESSAGES, channel);
}
return canResult;
}, items2);
const obj2 = require("initialize");
const items3 = [PermissionStore];
const stateFromStores2 = require("initialize").useStateFromStores(items3, () => {
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult = null != closure_0;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, closure_0);
}
return canResult;
});
if (stateFromStores) {
stateFromStores = stateFromStores1;
}
const tmp4 = null == channel || !channel.isThread() || channel.isMediaThread();
let tmp5 = !tmp4;
if (!tmp4) {
const threadMetadata = channel.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
if (locked) {
stateFromStores = stateFromStores2;
}
tmp5 = stateFromStores;
}
return tmp5;
}
function canUnarchiveThread(stateFromStores) {
let canResult = null != stateFromStores;
if (canResult) {
canResult = obj.can(constants.SEND_MESSAGES_IN_THREADS, stateFromStores);
}
let channel = null;
if (null != stateFromStores) {
channel = ChannelStore.getChannel(stateFromStores.parent_id);
}
let canResult1 = null != channel;
if (canResult1) {
canResult1 = obj.can(constants.SEND_MESSAGES_IN_THREADS, channel);
}
if (canResult) {
canResult = canResult1;
}
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult2 = null != stateFromStores;
if (canResult2) {
canResult2 = first.can(constants.MANAGE_THREADS, stateFromStores);
}
const tmp9 = null == stateFromStores || !stateFromStores.isThread() || stateFromStores.isMediaThread();
let tmp10 = !tmp9;
if (!tmp9) {
const threadMetadata = stateFromStores.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
if (locked) {
canResult = canResult2;
}
tmp10 = canResult;
}
return tmp10;
}
const THREADED_CHANNEL_TYPES = fn(2049).THREADED_CHANNEL_TYPES;
const Constants = fn(1074);
({ Permissions: c10, MessageFlags: closure_11, ChannelTypes: closure_12 } = Constants);
let obj = { id: "2022-07_voice_in_threads", label: "Voice in Threads", kind: "guild", defaultConfig: { enabled: false }, treatments: null };
let items = [{ id: 1, label: "On", config: { enabled: true } }];
obj.treatments = items;
const importDefaultResultResult = createExperiment(obj);
const size = fn(2);
const result = size.fileFinishedImporting("modules/threads/ThreadHooks.tsx");
export const VoiceInThreadsExperiment = importDefaultResultResult;
export const useCanStartPublicThread = function useCanStartPublicThread(type, arg1) {
_require = type;
const items = [PermissionStore];
const items1 = [type];
let flag = false;
if (obj.useStateFromStores(items, () => {
if (forumLikeChannel.isForumLikeChannel()) {
let SEND_MESSAGES = constants.SEND_MESSAGES;
} else {
SEND_MESSAGES = BigFlagUtilsAll.combine(constants.CREATE_PUBLIC_THREADS, constants.READ_MESSAGE_HISTORY);
}
return PermissionStore.can(SEND_MESSAGES, forumLikeChannel);
}, items1)) {
flag = false;
if (THREADED_CHANNEL_TYPES.has(type.type)) {
flag = true;
if (null != arg1) {
flag = false;
if (!arg1.hasFlag(constants2.HAS_THREAD)) {
flag = true;
if (isSystemMessageDefault(arg1)) {
flag = false;
}
}
}
}
}
return flag;
};
export const computeCanStartPublicThread = function computeCanStartPublicThread(channel, message) {
if (channel.isForumLikeChannel()) {
let SEND_MESSAGES = constants.SEND_MESSAGES;
} else {
SEND_MESSAGES = BigFlagUtilsAll.combine(constants.CREATE_PUBLIC_THREADS, constants.READ_MESSAGE_HISTORY);
}
let flag = false;
if (PermissionStore.can(SEND_MESSAGES, channel)) {
flag = false;
if (THREADED_CHANNEL_TYPES.has(channel.type)) {
flag = true;
if (null != message) {
flag = false;
if (!message.hasFlag(constants2.HAS_THREAD)) {
flag = true;
if (isSystemMessageDefault(message)) {
flag = false;
}
}
}
}
}
return flag;
};
export { useCanStartPrivateThread };
export const computeCanStartPrivateThread = function computeCanStartPrivateThread(type, hasFlag) {
let tmp3 = type.type === constants3.GUILD_TEXT;
if (!tmp3) {
tmp3 = type.type === tmp2.GUILD_APP;
}
if (tmp3) {
let flag = false;
if (canResult) {
flag = false;
if (THREADED_CHANNEL_TYPES.has(type.type)) {
flag = true;
if (null != hasFlag) {
flag = false;
if (!hasFlag.hasFlag(constants2.HAS_THREAD)) {
flag = true;
if (isSystemMessageDefault(hasFlag)) {
flag = false;
}
}
}
}
}
tmp3 = flag;
}
return tmp3;
};
export const useCanStartThread = function useCanStartThread(channel) {
_require = channel;
const items = [PermissionStore];
const items1 = [channel];
let flag = false;
if (obj.useStateFromStores(items, () => {
if (forumLikeChannel.isForumLikeChannel()) {
let SEND_MESSAGES = constants.SEND_MESSAGES;
} else {
SEND_MESSAGES = BigFlagUtilsAll.combine(constants.CREATE_PUBLIC_THREADS, constants.READ_MESSAGE_HISTORY);
}
return PermissionStore.can(SEND_MESSAGES, forumLikeChannel);
}, items1)) {
flag = false;
if (THREADED_CHANNEL_TYPES.has(channel.type)) {
flag = true;
}
}
if (!flag) {
flag = useCanStartPrivateThread(channel);
}
return flag;
};
export const useCanViewThreadForMessage = function useCanViewThreadForMessage(hasFlag) {
_require = hasFlag;
const items = [ChannelStore];
const items1 = [hasFlag];
const stateFromStores = require("initialize").useStateFromStores(items, () => ChannelStore.getChannel(SnowflakeUtilsDefault.castMessageIdAsChannelId(hasFlag.id)), items1);
const obj = require("initialize");
const items2 = [PermissionStore];
const items3 = [stateFromStores];
const stateFromStores1 = require("initialize").useStateFromStores(items2, () => PermissionStore.can(constants.VIEW_CHANNEL, stateFromStores), items3);
let hasFlagResult = hasFlag.hasFlag(constants2.HAS_THREAD);
if (hasFlagResult) {
hasFlagResult = null != stateFromStores && stateFromStores1;
const tmp5 = null != stateFromStores && stateFromStores1;
}
return hasFlagResult;
};
export const useHasActiveThreads = function useHasActiveThreads(channel) {
_require = channel;
const items = [ActiveJoinedThreadsStore, PermissionStore];
return require("initialize").useStateFromStoresObject(items, () => {
const activeJoinedThreadsForParent = ActiveJoinedThreadsStore.getActiveJoinedThreadsForParent(user.guild_id, user.id);
const activeJoinedRelevantThreadsForParent = ActiveJoinedThreadsStore.getActiveJoinedRelevantThreadsForParent(user.guild_id, user.id);
const activeUnjoinedThreadsForParent = ActiveJoinedThreadsStore.getActiveUnjoinedThreadsForParent(user.guild_id, user.id);
const someResult = _modDef12(activeJoinedRelevantThreadsForParent).some((channel) => closure_1_8.can(constants.VIEW_CHANNEL, channel.channel));
const obj = _modDef12(activeJoinedRelevantThreadsForParent);
const someResult1 = _modDef12(activeJoinedThreadsForParent).some((channel) => {
let canResult = !(channel.channel.id in activeJoinedRelevantThreadsForParent);
if (canResult) {
canResult = PermissionStore.can(constants.VIEW_CHANNEL, channel.channel);
}
return canResult;
});
const obj2 = _modDef12(activeJoinedThreadsForParent);
let someResult2 = _modDef12(activeUnjoinedThreadsForParent).some((item) => closure_1_8.can(constants.VIEW_CHANNEL, item));
let tmp7 = someResult;
if (!someResult) {
tmp7 = someResult1;
}
if (!tmp7) {
tmp7 = someResult2;
}
const obj4 = { hasActiveThreads: tmp7, hasMoreActiveThreads: null };
if (!someResult2) {
someResult2 = someResult1;
}
obj4.hasMoreActiveThreads = someResult2;
return obj4;
});
};
export const useCanManageThread = function useCanManageThread(channel) {
_require = channel;
const items = [ChannelStore];
const stateFromStores = require("initialize").useStateFromStores(items, () => {
parent_id = undefined;
if (parent_id != null) {
parent_id = parent_id.parent_id;
}
return ChannelStore.getChannel(parent_id);
});
const obj = require("initialize");
const items1 = [PermissionStore];
const items2 = [stateFromStores];
const stateFromStores1 = require("initialize").useStateFromStores(items1, () => {
let canResult = null != stateFromStores;
if (canResult) {
canResult = PermissionStore.can(constants.MANAGE_THREADS, tmp);
}
return canResult;
}, items2);
const obj2 = require("initialize");
const items3 = [AuthenticationStore];
let tmp4 = null != channel;
const stateFromStores2 = require("initialize").useStateFromStores(items3, () => id.getId());
if (tmp4) {
tmp4 = null != stateFromStores;
}
if (tmp4) {
let isThreadResult = channel.isThread();
if (isThreadResult) {
let tmp6 = stateFromStores1;
if (!tmp6) {
const isLockedThreadResult = channel.isLockedThread();
let tmp8 = !isLockedThreadResult;
if (!isLockedThreadResult) {
tmp8 = channel.ownerId === stateFromStores2;
}
tmp6 = tmp8;
}
isThreadResult = tmp6;
}
tmp4 = isThreadResult;
}
return tmp4;
};
export { useCanUnarchiveThread };
export { canUnarchiveThread };
export const useIsActiveChannelOrUnarchivableThread = function useIsActiveChannelOrUnarchivableThread(channel) {
let tmp2 = null != channel;
if (tmp2) {
const isThreadResult = channel.isThread();
let isActiveThreadResult = !isThreadResult;
if (isThreadResult) {
isActiveThreadResult = channel.isActiveThread();
}
if (!isActiveThreadResult) {
let isArchivedThreadResult = channel.isArchivedThread();
if (isArchivedThreadResult) {
const threadMetadata = channel.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
isArchivedThreadResult = true !== locked;
}
if (isArchivedThreadResult) {
isArchivedThreadResult = tmp;
}
isActiveThreadResult = isArchivedThreadResult;
}
tmp2 = isActiveThreadResult;
}
return tmp2;
};
export const getIsActiveChannelOrUnarchivableThread = function getIsActiveChannelOrUnarchivableThread(channel) {
let tmp = null != channel;
if (tmp) {
const isThreadResult = channel.isThread();
let isActiveThreadResult = !isThreadResult;
if (isThreadResult) {
isActiveThreadResult = channel.isActiveThread();
}
if (!isActiveThreadResult) {
let isArchivedThreadResult = channel.isArchivedThread();
if (isArchivedThreadResult) {
const threadMetadata = channel.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
isArchivedThreadResult = true !== locked;
}
if (isArchivedThreadResult) {
isArchivedThreadResult = canUnarchiveThread(channel);
}
isActiveThreadResult = isArchivedThreadResult;
}
tmp = isActiveThreadResult;
}
return tmp;
};
export const computeIsReadOnlyThread = function computeIsReadOnlyThread(channel) {
if (channel.isMediaThread()) {
return true;
} else {
const canResult = PermissionStore.can(constants.MANAGE_THREADS, channel);
return channel.isArchivedLockedThread() && !PermissionStore.can(constants.MANAGE_THREADS, channel);
}
};
export const useIsThreadModerator = function useIsThreadModerator(channel) {
_require = channel;
const items = [PermissionStore];
return require("initialize").useStateFromStores(items, () => {
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult = null != closure_0;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, closure_0);
}
return canResult;
});
};
export const isThreadModerator = function isThreadModerator(arg0) {
let tmp = arg1;
if (arg1 === undefined) {
const items = [PermissionStore];
tmp = items;
}
const first = _slicedToArray(tmp, 1)[0];
let canResult = null != arg0;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, arg0);
}
return canResult;
};
export const useCanRemoveThreadMember = function useCanRemoveThreadMember(channelId) {
_require = channelId;
let items = [ChannelStore, PermissionStore, AuthenticationStore];
return require("initialize").useStateFromStores(items, () => {
const channel = ChannelStore.getChannel(closure_0);
if (null == channel) {
return false;
} else {
let tmp5 = channel.type === constants3.PRIVATE_THREAD && channel.ownerId === tmp3;
if (!tmp5) {
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult = null != channel;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, channel);
}
tmp5 = canResult;
}
return tmp5;
}
});
};
export const useHasPermissionToJoinThreadVoice = function useHasPermissionToJoinThreadVoice(isThread) {
_require = isThread;
const items = [PermissionStore];
let stateFromStores = require("initialize").useStateFromStores(items, () => PermissionStore.can(constants.CONNECT, closure_0));
let tmp3 = null != isThread;
if (tmp3) {
const isThreadResult = isThread.isThread();
let isActiveThreadResult = !isThreadResult;
if (isThreadResult) {
isActiveThreadResult = isThread.isActiveThread();
}
if (!isActiveThreadResult) {
let isArchivedThreadResult = isThread.isArchivedThread();
if (isArchivedThreadResult) {
const threadMetadata = isThread.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
isArchivedThreadResult = true !== locked;
}
if (isArchivedThreadResult) {
isArchivedThreadResult = tmp2;
}
isActiveThreadResult = isArchivedThreadResult;
}
tmp3 = isActiveThreadResult;
}
if (stateFromStores) {
stateFromStores = tmp3;
}
return stateFromStores;
};
export const useCanJoinThreadVoice = function useCanJoinThreadVoice(channel) {
const tmp2 = useIsRemoteDefault();
_require = channel;
const items = [PermissionStore];
let stateFromStores = require("initialize").useStateFromStores(items, () => PermissionStore.can(constants.CONNECT, closure_0));
let tmp6 = null != channel;
if (tmp6) {
const isThreadResult = channel.isThread();
let isActiveThreadResult = !isThreadResult;
if (isThreadResult) {
isActiveThreadResult = channel.isActiveThread();
}
if (!isActiveThreadResult) {
let isArchivedThreadResult = channel.isArchivedThread();
if (isArchivedThreadResult) {
const threadMetadata = channel.threadMetadata;
let locked;
if (threadMetadata != null) {
locked = threadMetadata.locked;
}
isArchivedThreadResult = true !== locked;
}
if (isArchivedThreadResult) {
isArchivedThreadResult = tmp5;
}
isActiveThreadResult = isArchivedThreadResult;
}
tmp6 = isActiveThreadResult;
}
if (stateFromStores) {
stateFromStores = tmp6;
}
let enabled = importDefaultResultResult.useExperiment({ guildId: channel.guild_id, location: "e791ea_1" }, { autoTrackExposure: false }).enabled;
const obj = require("initialize");
const obj2 = { guildId: channel.guild_id, location: "e791ea_1" };
const isGameInvitesPost = require("GameInvitesChannelUtils").useIsGameInvitesPost(channel);
const tmp3Result = require("GameInvitesChannelUtils");
let shouldAgeVerifyForAgeGate = require("AgeGateUtils").useShouldAgeVerifyForAgeGate();
if (shouldAgeVerifyForAgeGate) {
shouldAgeVerifyForAgeGate = tmp3(5046).shouldShowAgeGateForChannelId(channel.id);
const tmp3Result4 = tmp3(5046);
}
let isVocalThreadResult = !tmp2;
if (!tmp2) {
isVocalThreadResult = channel.isVocalThread();
}
if (isVocalThreadResult) {
if (!enabled) {
enabled = isGameInvitesPost;
}
isVocalThreadResult = enabled;
}
if (isVocalThreadResult) {
isVocalThreadResult = stateFromStores;
}
if (isVocalThreadResult) {
isVocalThreadResult = !shouldAgeVerifyForAgeGate;
}
return isVocalThreadResult;
};
export const useIsNonModInLockedThread = function useIsNonModInLockedThread(channel) {
_require = channel;
let items = [PermissionStore];
const stateFromStores = require("initialize").useStateFromStores(items, () => {
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult = null != closure_0;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, closure_0);
}
return canResult;
});
const obj = require("initialize");
return channel.isLockedThread() && !stateFromStores;
};
export const isNonModInLockedThread = function isNonModInLockedThread(isLockedThread) {
const items = [PermissionStore];
const first = _slicedToArray(items, 1)[0];
let canResult = null != isLockedThread;
if (canResult) {
canResult = first.can(constants.MANAGE_THREADS, isLockedThread);
}
return isLockedThread.isLockedThread() && !canResult;
};