387 lines
13 KiB
TypeScript
387 lines
13 KiB
TypeScript
// Metro module 8184 (f8185).
|
|
import GuildScheduledEventStore from "../guild_scheduled_events/GuildScheduledEventStore";
|
|
import { ThreadChannelRecord } from "../../records/ChannelRecord";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import MessageStore from "../../stores/MessageStore";
|
|
import ReadStateStore from "../../stores/ReadStateStore";
|
|
import ICYMIStore from "./ICYMIStore";
|
|
import ICYMIUnreadStateStore from "./ICYMIUnreadStateStore";
|
|
import { ChannelTypes, GuildNSFWContentLevel } from "../../Constants";
|
|
import { ICYMIItemTypes, ICYMI_PAGE_SIZE, ContentType } from "./ICYMITypes";
|
|
import ICYMIActionCreators from "./ICYMIActionCreators";
|
|
import { createMessageRecord } from "../messages/MessageRecordUtils";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import { useStateFromStores } from "../../_bundle/Module589";
|
|
import { getICYMIEnabled } from "./ICYMIExperiment";
|
|
import { ContentInventoryAuthorType } from "../../_bundle/Module8190";
|
|
import { ContentInventoryEntryType } from "../../_bundle/Module7909";
|
|
import { NON_ELIGIBLE_SCROLL_ITEMS } from "./ICYMIItemTypes";
|
|
import { isValidImageAttachment, isValidVideoAttachment } from "../forums/ForumPostMediaUtils";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import "../../_bundle/asyncRequire";
|
|
function $mk115123($env) {
|
|
return (a0) => {
|
|
const type = a0.type;
|
|
if (type === ICYMIItemTypes.MESSAGE && a0.data.channel_type === ChannelTypes.GUILD_ANNOUNCEMENT && SnowflakeUtils.compare(ReadStateStore.ackMessageId(a0.data.channel_id), a0.data.message_id) >= 0) {
|
|
const r35 = $env;
|
|
(0, r35[1])(a0.data.channel_id, {
|
|
object: r35[0],
|
|
objectType: r35[2].ACK_SEMI_AUTOMATIC
|
|
}, true, true, SnowflakeUtils.atPreviousMillisecond(a0.data.message_id));
|
|
}
|
|
};
|
|
}
|
|
let hydrateItems, c5198_15;
|
|
let env5198 = {};
|
|
export function generateHydrationId(a0, a1) {
|
|
return `hydration-${a0}-${a1}`;
|
|
}
|
|
hydrateItems = async function hydrateItems(c26123_0, c26123_1, c26123_2) {
|
|
L11: {
|
|
const hydratedItems = ICYMIStore.getHydratedItems();
|
|
const r17 = c26123_0.slice(c26123_1, c26123_2);
|
|
if (r17.length !== 0) {
|
|
ICYMIActionCreators.loadHydratedAttempt(generateHydrationId(c26123_1, c26123_2));
|
|
const r43 = r17.filter((item) => hydratedItems[item.id] == null);
|
|
await ICYMIActionCreators.fetchHydrated(c26123_1, c26123_2, {
|
|
messageItems: [...r43.filter((item) => item.type === ICYMIItemTypes.MESSAGE).map((item) => ({
|
|
channel_id: item.data.channel_id,
|
|
message_id: item.data.message_id
|
|
})), ...r43.map((item) => {
|
|
if (item.type === ICYMIItemTypes.MESSAGE) {
|
|
const reply_message_id = item.data.message_context?.reply_message_id;
|
|
const r17 = [];
|
|
if (reply_message_id != null) {
|
|
r17.push({
|
|
channel_id: item.data.channel_id,
|
|
message_id: item.data.message_context.reply_message_id
|
|
});
|
|
}
|
|
if (item.data.message_context?.before_message_id != null) {
|
|
r17.push({
|
|
channel_id: item.data.channel_id,
|
|
message_id: item.data.message_context.before_message_id
|
|
});
|
|
}
|
|
if (item.data.message_context?.after_message_id != null) {
|
|
r17.push({
|
|
channel_id: item.data.channel_id,
|
|
message_id: item.data.message_context.after_message_id
|
|
});
|
|
}
|
|
return r17;
|
|
}
|
|
return [];
|
|
}).flat().filter(Boolean)],
|
|
activityItems: r43.filter((item) => item.type === ICYMIItemTypes.ACTIVITY).map((item) => ({
|
|
user_id: item.data.user_id,
|
|
content_id: item.data.content_id
|
|
}))
|
|
});
|
|
break L11;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
c5198_15 = {
|
|
UNKNOWN: 0,
|
|
0: "UNKNOWN",
|
|
DEFAULT: 1,
|
|
1: "DEFAULT",
|
|
MORE: 2,
|
|
2: "MORE",
|
|
LESS: 3,
|
|
3: "LESS",
|
|
MUTED: 4,
|
|
4: "MUTED"
|
|
};
|
|
export { c5198_15 as ICYMICustomScore };
|
|
export function isGuildItem(a0) {
|
|
return a0.type === ICYMIItemTypes.MESSAGE || a0.type === ICYMIItemTypes.GUILD_EVENT;
|
|
}
|
|
export function isChannelCustomScoreEligible(a0) {
|
|
return a0.type === ChannelTypes.GUILD_FORUM || (a0.type === ChannelTypes.GUILD_ANNOUNCEMENT || a0.type === ChannelTypes.GUILD_TEXT);
|
|
}
|
|
export function numberToCustomScore(a0) {
|
|
return a0 < -1.5 ? c5198_15.MUTED : a0 < 0 ? c5198_15.LESS : a0 > 0 ? c5198_15.MORE : c5198_15.DEFAULT;
|
|
}
|
|
export function customScoreToNumber(a0) {
|
|
if (c5198_15.MORE === a0) {
|
|
return 1;
|
|
}
|
|
if (c5198_15.LESS === a0) {
|
|
return -1;
|
|
}
|
|
if (c5198_15.MUTED === a0) {
|
|
return -2;
|
|
}
|
|
return 0;
|
|
}
|
|
export { hydrateItems };
|
|
export async function hydrateNextPage() {
|
|
const unreadDisplayItems = ICYMIStore.getUnreadDisplayItems();
|
|
const readDisplayItems = ICYMIStore.getReadDisplayItems();
|
|
const nextIndexToHydrate = ICYMIStore.getNextIndexToHydrate();
|
|
await hydrateItems([...unreadDisplayItems, ...readDisplayItems], nextIndexToHydrate, nextIndexToHydrate + ICYMI_PAGE_SIZE);
|
|
}
|
|
export function createGravityMessageFromServer(a0, a1) {
|
|
return {
|
|
...a1,
|
|
message: createMessageRecord(a0.message),
|
|
threadChannel: a0.thread_channel != null ? ThreadChannelRecord.fromServer(a0.thread_channel, a0.guild_id) : void 0
|
|
};
|
|
}
|
|
export function isItemUnreadInChannel(a0, a1) {
|
|
const trackedAckMessageId = ReadStateStore.getTrackedAckMessageId(a0);
|
|
return trackedAckMessageId == null || SnowflakeUtils.extractTimestamp(a1) > SnowflakeUtils.extractTimestamp(trackedAckMessageId);
|
|
}
|
|
export function useGravityMessage(a0) {
|
|
return useStateFromStores([MessageStore, ICYMIStore], () => {
|
|
let r10 = MessageStore.getMessage(a0.getChannelId(), a0.id);
|
|
if (r10 == null) {
|
|
r10 = ICYMIStore.getHydratedItem(a0.id)?.message;
|
|
}
|
|
if (r10 == null) {
|
|
r10 = a0;
|
|
}
|
|
return r10;
|
|
}, [a0]);
|
|
}
|
|
export function useGravityMessageItem(a0) {
|
|
return useStateFromStores([ICYMIStore], () => ICYMIStore.getHydratedItem(a0.id), [a0.id]);
|
|
}
|
|
export function useICYMIMessage(a0, a1) {
|
|
return useStateFromStores([MessageStore, ICYMIStore], () => {
|
|
const r1 = a1 != null;
|
|
let r2 = null;
|
|
if (r1) {
|
|
let r9 = MessageStore.getMessage(a0, a1);
|
|
if (r9 == null) {
|
|
r9 = ICYMIStore.getHydratedItem(a1)?.message;
|
|
}
|
|
r2 = r9;
|
|
}
|
|
return r2;
|
|
}, [a0, a1]);
|
|
}
|
|
export function icymiEnabled(a0) {
|
|
return getICYMIEnabled(a0);
|
|
}
|
|
export function customStatusToContentInventoryEntry(a0) {
|
|
let text = a0.data.text;
|
|
if (text == null) {
|
|
text = "";
|
|
}
|
|
return {
|
|
id: a0.id,
|
|
type: ICYMIItemTypes.CUSTOM_STATUS,
|
|
activity: {
|
|
id: a0.id,
|
|
author_id: a0.data.user_id,
|
|
author_type: ContentInventoryAuthorType.USER,
|
|
traits: [],
|
|
participants: [],
|
|
content_type: ContentInventoryEntryType.CUSTOM_STATUS,
|
|
extra: {
|
|
type: "custom_status_extra",
|
|
status: text,
|
|
emoji_id: a0.data.emoji_id,
|
|
emoji_name: a0.data.emoji_name,
|
|
emoji_animated: a0.data.emoji_animated,
|
|
attachments: a0.data.attachments
|
|
}
|
|
},
|
|
score: a0.score,
|
|
score_components: a0.score_components
|
|
};
|
|
}
|
|
export function compareGravityUnreadIds(a0, a1, a2) {
|
|
let r6 = ICYMIUnreadStateStore.getReadTimestamp(a0);
|
|
if (r6 == null) {
|
|
r6 = a2 == null ? void 0 : a2[a0];
|
|
}
|
|
let r11 = ICYMIUnreadStateStore.getReadTimestamp(a1);
|
|
if (r11 == null) {
|
|
r11 = a2 == null ? void 0 : a2[a1];
|
|
}
|
|
return r6 == null ? r11 == null ? 0 : r6 == null ? -1 : r11 == null ? 1 : r11 - r6 : r6 == null ? -1 : r11 == null ? 1 : r11 - r6;
|
|
}
|
|
export function getViewableFeedItemsArray(a0) {
|
|
const r8 = [...ICYMIStore.getUnreadDisplayItems(), ...ICYMIStore.getReadDisplayItems()];
|
|
let id = null;
|
|
let r0 = a0.length - 1;
|
|
let r24 = null;
|
|
while (0 <= r0) {
|
|
const r25 = a0[r0];
|
|
const r1 = r0;
|
|
if (r25 != null && !NON_ELIGIBLE_SCROLL_ITEMS.has(r25.item.data.kind)) {
|
|
const id2 = r25.item.id;
|
|
id = id2;
|
|
r24 = id2;
|
|
break;
|
|
}
|
|
r0 = r1 - 1;
|
|
r24 = null;
|
|
}
|
|
if (r24 == null) {
|
|
return [];
|
|
}
|
|
const r37 = r8.findIndex((item) => item.id === id);
|
|
return r37 < 0 ? [] : r8.slice(0, r37 + 1);
|
|
}
|
|
export function isItemNSFW(a0) {
|
|
let r17, channel_id;
|
|
const kind = a0.data.kind;
|
|
if (kind === "message") {
|
|
channel_id = a0.data.message.channel_id;
|
|
r17 = void 0;
|
|
} else if (kind === "forumThread") {
|
|
channel_id = a0.data.threadChannel.id;
|
|
r17 = void 0;
|
|
} else {
|
|
if (kind !== "guildEvent") {
|
|
return false;
|
|
}
|
|
r17 = GuildScheduledEventStore.getGuildScheduledEvent(a0.data.eventId)?.guild_id;
|
|
channel_id = void 0;
|
|
}
|
|
const channel = ChannelStore.getChannel(channel_id);
|
|
if (channel?.nsfw) {
|
|
return true;
|
|
}
|
|
let r7 = channel?.guild_id;
|
|
if (r7 == null) {
|
|
r7 = r17;
|
|
}
|
|
const r30 = r7 != null ? GuildStore.getGuild(r7) : null;
|
|
return r30?.nsfwLevel === GuildNSFWContentLevel.EXPLICIT || r30?.nsfwLevel === GuildNSFWContentLevel.AGE_RESTRICTED;
|
|
}
|
|
export function itemToType(a0) {
|
|
const kind = a0.data.kind;
|
|
if (kind === "end") {
|
|
return "end";
|
|
}
|
|
if (kind === "loading") {
|
|
return "loading";
|
|
}
|
|
if (kind === "bottomLoading") {
|
|
return "bottomLoading";
|
|
}
|
|
let r6 = "message";
|
|
if (kind === "message") {
|
|
const channelType = a0.channelType;
|
|
const GUILD_ANNOUNCEMENT = ChannelTypes.GUILD_ANNOUNCEMENT;
|
|
let r33 = "announcement";
|
|
if (channelType !== GUILD_ANNOUNCEMENT) {
|
|
if (a0.data.messageContext?.external_content_application_id != null) {
|
|
r6 = "game_message";
|
|
}
|
|
r33 = r6;
|
|
}
|
|
return r33;
|
|
}
|
|
if (kind === "guildEvent") {
|
|
return "guild_event";
|
|
}
|
|
if (kind === "contentInventory") {
|
|
return a0.data.content.content_type === ContentInventoryEntryType.CUSTOM_STATUS ? "hotwheels_custom_status" : "hotwheels_gaming_activity";
|
|
}
|
|
if (kind === "recommendedGuilds") {
|
|
return "recommended_guilds";
|
|
}
|
|
if (kind === "forumThread") {
|
|
return "forum_thread";
|
|
}
|
|
if (kind === "icymiHeader") {
|
|
return "icymi_header";
|
|
}
|
|
return "unknown";
|
|
}
|
|
export function determineContentType(a0, a1) {
|
|
if (a0.type === ChannelTypes.GUILD_ANNOUNCEMENT) {
|
|
return ContentType.ANNOUNCEMENT;
|
|
}
|
|
if (a0.type === ChannelTypes.GUILD_FORUM) {
|
|
return ContentType.FORUM_POST;
|
|
}
|
|
if (a1.reactions != null) {
|
|
const r19 = a1.reactions.map((reaction) => {
|
|
const r2 = reaction.count_details == null;
|
|
let r6 = 0;
|
|
if (!r2) {
|
|
let burst = reaction.count_details.burst;
|
|
if (burst == null) {
|
|
burst = 0;
|
|
}
|
|
let normal = reaction.count_details.normal;
|
|
if (normal == null) {
|
|
normal = 0;
|
|
}
|
|
r6 = burst + normal;
|
|
}
|
|
return r6;
|
|
});
|
|
if (r19.length !== 0 && r19.reduce((acc, item) => acc + item) > 10) {
|
|
return ContentType.POPULAR_MESSAGE;
|
|
}
|
|
}
|
|
return a1.attachments.length > 0 ? isValidImageAttachment(a1.attachments[0]) ? ContentType.IMAGE : isValidVideoAttachment(a1.attachments[0]) ? ContentType.VIDEO : ContentType.FILE : a1.embeds.length > 0 ? ContentType.LINK : ContentType.INTERESTING;
|
|
}
|
|
export function contentTypeToText(a0, r3 = false) {
|
|
if (ContentType.POPULAR_MESSAGE === a0) {
|
|
return intl.string(t["H/2+cl"]);
|
|
}
|
|
if (ContentType.IMAGE === a0) {
|
|
return intl.string(t.gmOWAo);
|
|
}
|
|
if (ContentType.VIDEO === a0) {
|
|
return intl.string(t.swhcPM);
|
|
}
|
|
if (ContentType.LINK === a0) {
|
|
return intl.string(t.oj5yvD);
|
|
}
|
|
if (ContentType.THREAD === a0) {
|
|
return intl.string(t.DwLrLK);
|
|
}
|
|
if (ContentType.FORUM_POST === a0) {
|
|
return intl.string(t["Q9/6BS"]);
|
|
}
|
|
if (ContentType.CHANGED_STATUS === a0) {
|
|
return intl.string(t.TGrUmi);
|
|
}
|
|
if (ContentType.INTERESTING === a0) {
|
|
return intl.string(t["TahE/i"]);
|
|
}
|
|
if (ContentType.ANNOUNCEMENT === a0) {
|
|
return r3 ? intl.string(t.E0MW8I) : intl.string(t["2ih63V"]);
|
|
}
|
|
if (ContentType.FILE === a0) {
|
|
return intl.string(t.pYrnTY);
|
|
}
|
|
}
|
|
export async function regenerateFeedAndClearReadStates(c26125_0) {
|
|
let env29895;
|
|
const r9 = env5198;
|
|
let c26125_2 = r9;
|
|
const r33 = env29895 = {
|
|
$parent: r9
|
|
};
|
|
let c26125_1 = r33;
|
|
env29895[0] = c26125_0;
|
|
env29895[1] = void 0;
|
|
env29895[2] = void 0;
|
|
env29895[1] = (await import("../../actions/ReadStateActionCreators")).ack;
|
|
const r74 = await import("../../Constants");
|
|
env29895[2] = r74.AnalyticsObjectTypes;
|
|
ICYMIStore.getDehydratedItems().forEach($mk115123(c26125_1));
|
|
await ICYMIActionCreators.clearReadStates();
|
|
await ICYMIActionCreators.fetchDehydrated({
|
|
isReloading: true,
|
|
forceRefresh: true
|
|
});
|
|
await ICYMIActionCreators.reloadICYMITab();
|
|
await ICYMIActionCreators.getGuildChannelScores();
|
|
ICYMIActionCreators.getRecommendedGuilds();
|
|
}
|