decord/source/modules/forums/tracking/TrackingUtils.tsx

295 lines
12 KiB
TypeScript
Raw Normal View History

// Module ID: 7769
// Function ID: 7770
2026-07-29 08:29:29 +00:00
// Name: collectForumAnalyticsMetadata
// Dependencies: [5507, 4201, 7770, 7306, 1957, 4901, 4199, 4900, 7277, 1074, 1964, 1113, 7771, 1966, 7772, 11, 7773, 2]
2026-07-29 08:29:29 +00:00
// Exports: collectForumPostAnalyticsMetadata, convertSortOrderToReadableString, getForumChannelSessionId, getForumPostAttachmentMimetypes, getForumPostDraftAppliedTagIds, getForumPostDraftNumAttachments, getNumActiveThreads
2026-07-20 16:05:17 +00:00
// Module 7769 (collectForumAnalyticsMetadata)
2026-08-24 06:08:38 +00:00
import DISCORD_EPOCHDefault from "DISCORD_EPOCH" /* 11 */;
import set2 from "set" /* 1966 */;
import getForumChannelSessionIdDefault from "getForumChannelSessionId" /* 7771 */;
import setFilterTagIdsDefault from "setFilterTagIds" /* 7772 */;
import closure_3 from "handleThreadCreateOrUpdate" /* 5507 */;
import closure_4 from "storeThread" /* 4201 */;
import closure_5 from "updateFromGuild" /* 7770 */;
import closure_6 from "updateState" /* 7306 */;
import closure_7 from "ensureGuildLoaded" /* 1957 */;
import closure_8 from "handleChanged" /* 4901 */;
import { DraftType } from "handleChanged" /* 4901 */;
import closure_10 from "getUncachedChannelPermissions" /* 4199 */;
import closure_11 from "map" /* 4900 */;
import closure_12 from "handleLoadThreadsSuccess" /* 7277 */;
import { Permissions } from "ME" /* 1074 */;
import { ChannelFlags } from "set" /* 1964 */;
import { ThreadSortOrderReadableForAnalytics as closure_15 } from "AbortCodes" /* 1113 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function collectForumAnalyticsMetadata(sessionId) {
sessionId = sessionId.sessionId;
const channel = store.getChannel(sessionId.channelId);
let tmp = null;
if (null != channel) {
tmp = null;
if (channel.isForumLikeChannel()) {
let tmp2 = null != channel.topic;
if (tmp2) {
tmp2 = channel.topic.trim().length > 0;
const str = channel.topic;
}
2026-07-29 08:29:29 +00:00
const obj = { forum_channel_has_guidelines: null, forum_channel_default_emoji_reaction_id: null, forum_channel_default_emoji_reaction_name: null, forum_channel_available_tag_ids: null, forum_channel_tag_required: null, forum_channel_can_create_post: null, forum_channel_filter_tag_ids: null, forum_channel_sort_order: null, forum_channel_session_id: null, forum_channel_layout: null, forum_channel_default_sort_order: null, forum_channel_tag_setting: null, forum_channel_default_layout: null, forum_channel_is_moderator_report_channel: null };
obj[0] = tmp2;
2026-07-20 16:05:17 +00:00
const defaultReactionEmoji = channel.defaultReactionEmoji;
let emojiId;
2026-07-29 08:29:29 +00:00
if (defaultReactionEmoji != null) {
2026-07-20 16:05:17 +00:00
emojiId = defaultReactionEmoji.emojiId;
}
2026-07-29 08:29:29 +00:00
obj[1] = emojiId;
2026-07-20 16:05:17 +00:00
const defaultReactionEmoji2 = channel.defaultReactionEmoji;
let emojiName;
2026-07-29 08:29:29 +00:00
if (defaultReactionEmoji2 != null) {
2026-07-20 16:05:17 +00:00
emojiName = defaultReactionEmoji2.emojiName;
}
2026-07-29 08:29:29 +00:00
obj[2] = emojiName;
2026-07-20 16:05:17 +00:00
const availableTags = channel.availableTags;
let mapped;
2026-07-29 08:29:29 +00:00
if (availableTags != null) {
2026-07-20 16:05:17 +00:00
mapped = availableTags.map((id) => id.id);
}
2026-07-29 08:29:29 +00:00
if (mapped == null) {
2026-07-20 16:05:17 +00:00
mapped = [];
}
2026-07-29 08:29:29 +00:00
obj[3] = mapped;
obj[4] = channel.hasFlag(ChannelFlags.REQUIRE_TAG);
2026-08-24 06:08:38 +00:00
obj[5] = closure_10.can(Permissions.SEND_MESSAGES, channel);
obj[6] = setFilterTagIdsDefault.getFilterTagIdsAnalytics();
const obj3 = setFilterTagIdsDefault;
obj[7] = setFilterTagIdsDefault.getSortOrderAnalytics(channel.id);
2026-07-29 08:29:29 +00:00
if (sessionId == null) {
let tmp8Result = tmp8(7771);
2026-07-29 08:29:29 +00:00
sessionId = tmp8Result.getForumChannelSessionId(channel.id);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[8] = sessionId;
tmp8Result = tmp8(7772);
2026-07-29 08:29:29 +00:00
obj[9] = tmp8Result.getLayoutAnalytics(channel.id);
obj[10] = channel.defaultSortOrder;
2026-08-24 06:08:38 +00:00
const obj4 = setFilterTagIdsDefault;
obj[11] = setFilterTagIdsDefault.getTagSettingAnalytics(channel.id);
2026-07-29 08:29:29 +00:00
obj[12] = channel.defaultForumLayout;
obj[13] = channel.isModeratorReportChannel();
2026-07-20 16:05:17 +00:00
tmp = obj;
2026-08-24 06:08:38 +00:00
const tmp8Result1 = setFilterTagIdsDefault;
2026-07-20 16:05:17 +00:00
}
}
return tmp;
}
2026-08-24 06:08:38 +00:00
const result = require("set").fileFinishedImporting("modules/forums/tracking/TrackingUtils.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export const getForumChannelSessionId = function getForumChannelSessionId(arg0) {
2026-08-24 06:08:38 +00:00
return getForumChannelSessionIdDefault.getForumChannelSessionId(arg0);
2026-07-29 08:29:29 +00:00
};
2026-07-20 16:05:17 +00:00
export const convertSortOrderToReadableString = function convertSortOrderToReadableString(sortOrder) {
2026-08-24 06:08:38 +00:00
if (set2.ThreadSortOrder.CREATION_DATE === sortOrder) {
2026-07-20 16:05:17 +00:00
return constants.CREATION_DATE;
2026-08-24 06:08:38 +00:00
} else if (set2.ThreadSortOrder.LATEST_ACTIVITY === sortOrder) {
2026-07-20 16:05:17 +00:00
return constants.LATEST_ACTIVITY;
} else {
const _Error = Error;
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
error = new Error("Unexpected sort order " + sortOrder);
2026-07-20 16:05:17 +00:00
throw error;
}
2026-08-24 06:08:38 +00:00
const tmp = require;
2026-07-20 16:05:17 +00:00
};
export const getForumPostDraftNumAttachments = function getForumPostDraftNumAttachments(channelId) {
return uploads.getUploads(channelId, DraftType.FirstThreadMessage).length;
};
export const getForumPostDraftAppliedTagIds = function getForumPostDraftAppliedTagIds(channelId) {
const channel = store.getChannel(channelId);
if (null == channel) {
return [];
} else {
2026-07-29 08:29:29 +00:00
const channel1 = obj.getChannel(channel.parent_id);
if (channel1 != null) {
2026-07-20 16:05:17 +00:00
const availableTags = channel1.availableTags;
}
if (null != channel1) {
if (null != availableTags) {
2026-07-23 10:11:24 +00:00
threadSettings = threadSettings.getThreadSettings(channelId);
2026-07-20 16:05:17 +00:00
let appliedTags;
2026-07-29 08:29:29 +00:00
if (threadSettings != null) {
2026-07-20 16:05:17 +00:00
appliedTags = threadSettings.appliedTags;
}
2026-07-29 08:29:29 +00:00
if (appliedTags == null) {
2026-07-20 16:05:17 +00:00
const _Set = Set;
appliedTags = new Set();
}
const _Set2 = Set;
const set = new Set(availableTags.map((id) => id.id));
const _Array = Array;
return Array.from(appliedTags).filter((arg0) => set.has(arg0));
}
}
return [];
}
2026-07-29 08:29:29 +00:00
obj = store;
2026-07-20 16:05:17 +00:00
};
export const getNumActiveThreads = function getNumActiveThreads(guildId, channelId) {
return Object.keys(threadsForParent.getThreadsForParent(guildId, channelId)).length;
};
2026-07-29 08:29:29 +00:00
export const getForumPostAttachmentMimetypes = function getForumPostAttachmentMimetypes(arg0) {
const message = store2.getMessage(arg0);
let firstMessage = null;
if (message.loaded) {
firstMessage = message.firstMessage;
}
if (null == firstMessage) {
let items = [];
} else {
const attachments = firstMessage.attachments;
items = attachments.map((content_type) => {
let str = content_type.content_type;
if (str == null) {
str = "unknown";
}
return str;
});
}
return items;
};
2026-07-20 16:05:17 +00:00
export { collectForumAnalyticsMetadata };
export const collectForumPostAnalyticsMetadata = function collectForumPostAnalyticsMetadata(channelId) {
channelId = channelId.channelId;
2026-07-29 08:29:29 +00:00
let obj = store;
2026-07-20 16:05:17 +00:00
const channel = store.getChannel(channelId);
if (null != channel) {
if (channel.isForumPost()) {
2026-07-29 08:29:29 +00:00
const channel1 = obj.getChannel(channel.parent_id);
let tmp = null;
2026-07-20 16:05:17 +00:00
if (null != channel1) {
2026-07-29 08:29:29 +00:00
tmp = null;
2026-07-20 16:05:17 +00:00
if (channel1.isForumLikeChannel()) {
2026-07-29 08:29:29 +00:00
obj = {};
obj = { channelId: null, sessionId: null };
obj[0] = channel1.id;
obj[1] = channelId.sessionId;
2026-07-20 16:05:17 +00:00
const merged = Object.assign(collectForumAnalyticsMetadata(obj));
2026-07-29 08:29:29 +00:00
obj.thread_approximate_member_count = memberCount.getMemberCount(channelId);
obj.thread_approximate_message_count = count.getCount(channelId);
2026-07-20 16:05:17 +00:00
const threadMetadata = channel.threadMetadata;
let archived;
2026-07-29 08:29:29 +00:00
if (threadMetadata != null) {
2026-07-20 16:05:17 +00:00
archived = threadMetadata.archived;
}
2026-07-29 08:29:29 +00:00
obj.thread_archived = true === archived;
2026-07-20 16:05:17 +00:00
const threadMetadata2 = channel.threadMetadata;
2026-07-29 08:29:29 +00:00
let flag2;
if (threadMetadata2 != null) {
flag2 = threadMetadata2.locked;
}
if (flag2 == null) {
flag2 = false;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj.thread_locked = flag2;
2026-07-20 16:05:17 +00:00
const threadMetadata3 = channel.threadMetadata;
2026-07-29 08:29:29 +00:00
let num;
if (threadMetadata3 != null) {
num = threadMetadata3.autoArchiveDuration;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (num == null) {
num = 0;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj.thread_auto_archive_duration_minutes = num;
2026-08-24 06:08:38 +00:00
obj.thread_approximate_creation_date = DISCORD_EPOCHDefault.extractTimestamp(channelId);
2026-07-29 08:29:29 +00:00
obj.forum_post_id = channel.id;
2026-08-24 06:08:38 +00:00
const obj6 = DISCORD_EPOCHDefault;
obj.forum_post_first_message_id = DISCORD_EPOCHDefault.castChannelIdAsMessageId(channel.id);
2026-07-29 08:29:29 +00:00
const message = store2.getMessage(channel.id);
let firstMessage = null;
if (message.loaded) {
firstMessage = message.firstMessage;
}
let num3 = 0;
if (null != firstMessage) {
const reactions = firstMessage.reactions;
num3 = reactions.reduce((arg0, count) => arg0 + count.count, 0);
}
obj.forum_post_num_reactions = num3;
const message1 = obj8.getMessage(channel.id);
let firstMessage1 = null;
if (message1.loaded) {
firstMessage1 = message1.firstMessage;
}
let num4 = 0;
if (null != firstMessage1) {
num4 = firstMessage1.reactions.length;
}
obj.forum_post_num_unique_reactions = num4;
let set;
const channel2 = obj.getChannel(channel.id);
if (null == channel2) {
let items = [];
} else {
const channel3 = obj.getChannel(channel2.parent_id);
if (channel3 != null) {
const availableTags = channel3.availableTags;
}
if (null != channel3) {
if (null != availableTags) {
const _Set = Set;
set = new Set(availableTags.map((id) => id.id));
const appliedTags = channel2.appliedTags;
items = undefined;
if (appliedTags != null) {
items = appliedTags.filter((arg0) => set.has(arg0));
}
if (items == null) {
items = [];
}
}
}
items = [];
}
obj.forum_post_applied_tag_ids = items;
obj.forum_post_is_pinned = channel.hasFlag(ChannelFlags.PINNED);
let tmp8Result = tmp8(7773);
2026-07-29 08:29:29 +00:00
const readStateSnapshotAnalytics = tmp8Result.getReadStateSnapshotAnalytics(channel.id);
2026-07-20 16:05:17 +00:00
let isNew;
2026-07-29 08:29:29 +00:00
if (readStateSnapshotAnalytics != null) {
2026-07-20 16:05:17 +00:00
isNew = readStateSnapshotAnalytics.isNew;
}
2026-07-29 08:29:29 +00:00
obj.forum_post_is_new = isNew;
tmp8Result = tmp8(7773);
2026-07-29 08:29:29 +00:00
const readStateSnapshotAnalytics1 = tmp8Result.getReadStateSnapshotAnalytics(channel.id);
2026-07-20 16:05:17 +00:00
let hasUnreads;
2026-07-29 08:29:29 +00:00
if (readStateSnapshotAnalytics1 != null) {
2026-07-20 16:05:17 +00:00
hasUnreads = readStateSnapshotAnalytics1.hasUnreads;
}
2026-07-29 08:29:29 +00:00
obj.forum_post_is_unread = hasUnreads;
2026-08-24 06:08:38 +00:00
obj.forum_post_is_following = closure_4.hasJoined(channel.id);
2026-07-29 08:29:29 +00:00
const message2 = obj8.getMessage(channel.id);
let firstMessage2 = null;
if (message2.loaded) {
firstMessage2 = message2.firstMessage;
}
if (null == firstMessage2) {
let items1 = [];
} else {
const attachments = firstMessage2.attachments;
items1 = attachments.map((content_type) => {
let str = content_type.content_type;
if (str == null) {
str = "unknown";
}
return str;
});
}
obj.forum_post_attachment_mimetypes = items1;
2026-08-24 06:08:38 +00:00
const obj7 = DISCORD_EPOCHDefault;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
return tmp;
2026-07-20 16:05:17 +00:00
}
}
return null;
};