127 lines
4.5 KiB
TypeScript
127 lines
4.5 KiB
TypeScript
// Metro module 10261 (f10262).
|
|
import { useMemo } from "react";
|
|
import { REACTION_MILESTONE_COUNTS } from "./InAppNotificationConstants";
|
|
import { AnalyticEvents, ChannelTypes, InAppNotificationTypes, MessageEmbedTypes, MessageFlags } from "../../../Constants";
|
|
import { sumBy } from "../../../_bundle/Module12";
|
|
import { v4 } from "../../../_bundle/Module514";
|
|
import { isIOS } from "../../../_bundle/Module501";
|
|
import isForwardMessage from "../../forwarding/isForwardMessage";
|
|
import AppAnalyticsUtils from "../../app_analytics/AppAnalyticsUtils";
|
|
let $mk84274 = function() {
|
|
return (a0) => a0.type === MessageEmbedTypes.GIFV;
|
|
};
|
|
const extractMetadataFromNotification = function extractMetadataFromNotification(notification) {
|
|
let channelId, channelType, guildId, messageId;
|
|
L43: {
|
|
const type = notification.type;
|
|
if (InAppNotificationTypes.MESSAGE !== type && InAppNotificationTypes.REACTION !== type) {
|
|
if (InAppNotificationTypes.ALERT === type) {
|
|
let r36 = notification.guild?.id;
|
|
if (r36 == null) {
|
|
r36 = notification.channel?.guild_id;
|
|
}
|
|
const id2 = notification.channel?.id;
|
|
channelType = notification.channel?.type;
|
|
messageId = void 0;
|
|
channelId = id2;
|
|
guildId = r36;
|
|
break L43;
|
|
}
|
|
if (InAppNotificationTypes.FORUM_THREAD_CREATED === type) {
|
|
const guild_id2 = notification.thread?.guild_id;
|
|
channelId = notification.thread?.id;
|
|
channelType = void 0;
|
|
messageId = void 0;
|
|
guildId = guild_id2;
|
|
break L43;
|
|
}
|
|
if (InAppNotificationTypes.MESSAGE_FAILED_TO_SEND === type) {
|
|
channelId = notification.channelId;
|
|
channelType = void 0;
|
|
messageId = void 0;
|
|
guildId = void 0;
|
|
break L43;
|
|
}
|
|
const MESSAGE_REMINDER = InAppNotificationTypes.MESSAGE_REMINDER;
|
|
channelType = void 0;
|
|
messageId = void 0;
|
|
channelId = void 0;
|
|
guildId = void 0;
|
|
if (MESSAGE_REMINDER !== type) {
|
|
break L43;
|
|
}
|
|
const guild_id = notification.channel?.guild_id;
|
|
const id = notification.channel?.id;
|
|
channelType = notification.channel?.type;
|
|
messageId = void 0;
|
|
channelId = id;
|
|
guildId = guild_id;
|
|
} else {
|
|
let r48 = notification.guild?.id;
|
|
if (r48 == null) {
|
|
r48 = notification.channel?.guild_id;
|
|
}
|
|
const id3 = notification.channel?.id;
|
|
const id4 = notification.message?.id;
|
|
channelType = notification.channel?.type;
|
|
messageId = id4;
|
|
channelId = id3;
|
|
guildId = r48;
|
|
}
|
|
}
|
|
return {
|
|
guildId,
|
|
channelId,
|
|
messageId,
|
|
channelType
|
|
};
|
|
};
|
|
export function isReactionMilestoneNotification(a0, a1) {
|
|
if (a1 != null && a1 !== ChannelTypes.GUILD_ANNOUNCEMENT) {
|
|
return REACTION_MILESTONE_COUNTS.has(sumBy(a0, ({ count_details }) => {
|
|
let r6 = count_details?.burst;
|
|
if (r6 == null) {
|
|
r6 = 0;
|
|
}
|
|
let r4 = count_details?.normal;
|
|
if (r4 == null) {
|
|
r4 = 0;
|
|
}
|
|
return r6 + r4;
|
|
}));
|
|
}
|
|
return false;
|
|
}
|
|
export function generateInAppNotificationId() {
|
|
return v4();
|
|
}
|
|
export function getMessagePreviewTextVariant() {
|
|
return isIOS() ? "text-md/normal" : "text-md/medium";
|
|
}
|
|
export function useHasPreviewableMedia(a0) {
|
|
return useMemo(() => a0.hasFlag(MessageFlags.IS_VOICE_MESSAGE) || a0.attachments.length > 0 || a0.embeds.length > 0 && a0.embeds.every($mk84274()) || a0.stickerItems.length > 0 || isForwardMessage(a0) && a0.messageSnapshots.some(({ message }) => message.hasFlag(MessageFlags.IS_VOICE_MESSAGE) || message.attachments.length > 0 || message.embeds.length > 0 && message.embeds.every($mk84274()) || message.stickerItems.length > 0), [a0]);
|
|
}
|
|
export { extractMetadataFromNotification };
|
|
export function trackInAppNotificationAccessoryClicked(a0, a1) {
|
|
const r10 = extractMetadataFromNotification(a0);
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.IN_APP_NOTIFICATION_ACCESSORY_CLICKED, {
|
|
type: a0.type,
|
|
in_app_notification_id: a0.inAppNotificationId,
|
|
notif_guild_id: r10.guildId,
|
|
notif_channel_id: r10.channelId,
|
|
message_id: r10.messageId,
|
|
accessory: a1
|
|
});
|
|
}
|
|
export function trackDismissed(a0) {
|
|
const { guildId, channelId } = a0;
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.IN_APP_NOTIFICATION_DISMISSED, {
|
|
type: a0.type,
|
|
guild_id: guildId,
|
|
channel_id: channelId,
|
|
dismiss_reason: a0.dismissReason,
|
|
in_app_notification_id: a0.inAppNotificationId,
|
|
message_id: a0.messageId
|
|
});
|
|
}
|