174 lines
7.9 KiB
TypeScript
174 lines
7.9 KiB
TypeScript
// Metro module 10279 (f10280).
|
|
import { useMemo } from "react";
|
|
import { View } from "react-native";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import { IN_APP_NOTIFICATION_MAX_HEIGHT, NOTIFICATION_PREVIEW_LINE_CLAMP } from "./InAppNotificationConstants";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import { isIOS } from "../../../_bundle/Module501";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import useTruncatedGradientColors from "./hooks/useTruncatedGradientColors";
|
|
import { NativeChannelRowPreview, ChannelRowPreview } from "../../main_tabs_v2/native/shared_components/ChannelRowPreview";
|
|
import { getMessagePreviewTextVariant } from "./InAppNotificationUtils";
|
|
import { Text } from "../../../design/components/Text/native/Text";
|
|
import FastImage from "../../../components_native/common/FastImage";
|
|
import { usePreviewableMedia, PreviewableMediaTypes } from "./hooks/usePreviewableMedia";
|
|
import { useNullableMessageAuthor } from "../../messages/useMessageAuthor";
|
|
import { usePreviewableMediaText } from "./hooks/usePreviewableMediaText";
|
|
import { useGetInitialMessagePreview } from "./hooks/useGetInitialMessagePreview";
|
|
import { MessageEmbedTypes } from "../../../_bundle/Module693";
|
|
import isForwardMessage from "../../forwarding/isForwardMessage";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { ChannelListLayoutTypes } from "../../main_tabs_v2/ChannelListLayoutTypes";
|
|
let useStyles, useStyles2, SystemMessageText, EmbedMediaThumbnail, EmbedCard;
|
|
const NativeMessagePreviewContent = function NativeMessagePreviewContent(props) {
|
|
const { message: message2, lineClamp, maxHeight } = props;
|
|
const truncatedGradientColors = useTruncatedGradientColors();
|
|
return <View>
|
|
<NativeChannelRowPreview message={message2} lineClamp={lineClamp} maxHeight={maxHeight} gradientStyles={truncatedGradientColors.gradientStyles} gradientColors={truncatedGradientColors.gradientColors} />
|
|
</View>;
|
|
};
|
|
SystemMessageText = function SystemMessageText(props) {
|
|
const text = props.text;
|
|
const styles = useStyles();
|
|
return <Text variant={getMessagePreviewTextVariant()} color="text-subtle" style={styles.italic} lineClamp={NOTIFICATION_PREVIEW_LINE_CLAMP}>{text}</Text>;
|
|
};
|
|
EmbedMediaThumbnail = function EmbedMediaThumbnail(props) {
|
|
const media = props.media;
|
|
const styles2 = useStyles2();
|
|
let proxyURL = media.proxyURL;
|
|
if (proxyURL == null) {
|
|
proxyURL = media.url;
|
|
}
|
|
const r16 = media.width / media.height;
|
|
return <View style={[styles2.embedMediaContainer, {
|
|
aspectRatio: Number.isFinite(r16) ? r16 > 0 ? r16 : 1 : 1
|
|
}]}>
|
|
<FastImage source={{
|
|
uri: proxyURL
|
|
}} style={styles2.embedMedia} resizeMode="contain" />
|
|
</View>;
|
|
};
|
|
EmbedCard = function EmbedCard(props) {
|
|
const embed = props.embed;
|
|
const styles2 = useStyles2();
|
|
const name2 = embed.provider?.name;
|
|
const name = embed.author?.name;
|
|
const rawTitle = embed.rawTitle;
|
|
let thumbnail = embed.thumbnail;
|
|
if (thumbnail == null) {
|
|
thumbnail = embed.image;
|
|
}
|
|
const backgroundColor = embed.color != null ? embed.color.toLowerCase() !== "#ffffff" ? embed.color : void 0 : void 0;
|
|
const r34 = [backgroundColor != null && <View style={[styles2.embedAccentBar, {
|
|
backgroundColor
|
|
}]} />, <View style={styles2.embedTextContainer}>
|
|
{name2 != null && <Text variant="text-xxs/normal" color="text-subtle" lineClamp={1}>{name2}</Text>}
|
|
{name != null && <Text variant="text-xs/medium" color="text-default" lineClamp={1}>{name}</Text>}
|
|
{rawTitle != null && <Text variant="text-xs/medium" color="text-link" lineClamp={name2 == null ? name == null ? 3 : 1 : 1}>{rawTitle}</Text>}
|
|
{embed.rawDescription != null && <Text variant="text-xs/medium" color="text-default" lineClamp={3}>{embed.rawDescription}</Text>}
|
|
</View>, thumbnail != null && <EmbedMediaThumbnail media={thumbnail} />];
|
|
return <View style={styles2.embedContainer}>{r34}</View>;
|
|
};
|
|
useStyles = createStyles({
|
|
italic: {
|
|
fontStyle: "italic",
|
|
fontFamily: isIOS() ? "ggsans-NormalItalic, NotoSans-NormalItalic" : "ggsans-MediumItalic, NotoSans-MediumItalic"
|
|
}
|
|
});
|
|
useStyles2 = createStyles({
|
|
embedContainer: {
|
|
borderRadius: Module712.radii.sm,
|
|
paddingTop: Module712.space.PX_8,
|
|
paddingBottom: Module712.space.PX_8,
|
|
paddingRight: Module712.space.PX_8,
|
|
backgroundColor: Module712.colors.BACKGROUND_MOD_SUBTLE,
|
|
flexDirection: "row",
|
|
overflow: "hidden"
|
|
},
|
|
embedAccentBar: {
|
|
width: 4,
|
|
marginTop: -Module712.space.PX_8,
|
|
marginBottom: -Module712.space.PX_8,
|
|
alignSelf: "stretch"
|
|
},
|
|
embedTextContainer: {
|
|
flex: 1,
|
|
gap: Module712.space.PX_4,
|
|
paddingVertical: Module712.space.PX_4,
|
|
paddingHorizontal: Module712.space.PX_8
|
|
},
|
|
embedMediaContainer: {
|
|
borderRadius: Module712.radii.xs,
|
|
overflow: "hidden",
|
|
height: 60,
|
|
width: void 0
|
|
},
|
|
embedMedia: {
|
|
width: "100%",
|
|
height: "100%"
|
|
}
|
|
});
|
|
export default function MessagePreviewText(props) {
|
|
const { message, lineClamp, maxHeight, showMessageAuthor = false } = props;
|
|
const previewableMedia = usePreviewableMedia(message);
|
|
const nullableMessageAuthor = useNullableMessageAuthor(showMessageAuthor ? message : null);
|
|
const previewableMediaText = usePreviewableMediaText({
|
|
previewableMedia,
|
|
author: nullableMessageAuthor
|
|
});
|
|
const { text: text2, secondaryText } = previewableMediaText;
|
|
const getInitialMessagePreview = useGetInitialMessagePreview({
|
|
message
|
|
});
|
|
const memo = useMemo(() => message.embeds.filter((embed) => embed.image != null || embed.thumbnail != null), [message.embeds]);
|
|
if (memo.length > 0) {
|
|
const embed = memo[0];
|
|
return embed.type === MessageEmbedTypes.GIFV && text2 != null ? <SystemMessageText text={text2} /> : <View>
|
|
<NativeMessagePreviewContent message={getInitialMessagePreview} lineClamp={NOTIFICATION_PREVIEW_LINE_CLAMP} maxHeight={IN_APP_NOTIFICATION_MAX_HEIGHT} />
|
|
<EmbedCard embed={embed} />
|
|
</View>;
|
|
}
|
|
if (isForwardMessage(message)) {
|
|
const r2 = message.messageSnapshots.length > 0 && message.messageSnapshots[0].message.content.length > 0;
|
|
const r3 = previewableMedia.length > 0 && previewableMedia[0].type === PreviewableMediaTypes.GIF;
|
|
L29: {
|
|
if (previewableMedia.length > 0) {
|
|
if (r2 && !r3) {
|
|
break L29;
|
|
}
|
|
return <SystemMessageText text={nullableMessageAuthor != null ? intl.format(t.sLDHDi, {
|
|
username: nullableMessageAuthor.nick
|
|
}) : intl.string(t["9ddYKt"])} />;
|
|
}
|
|
}
|
|
return <NativeMessagePreviewContent message={getInitialMessagePreview} lineClamp={lineClamp} maxHeight={maxHeight} />;
|
|
}
|
|
if (message.content.length > 0) {
|
|
if (nullableMessageAuthor != null) {
|
|
const channel = ChannelStore.getChannel(message.channel_id);
|
|
const messagePreviewTextVariant = getMessagePreviewTextVariant();
|
|
if (channel != null) {
|
|
return <ChannelRowPreview channel={channel} message={message} color="text-default" layout={ChannelListLayoutTypes.COZY} variant={messagePreviewTextVariant} muted={false} lineClamp={lineClamp} />;
|
|
}
|
|
}
|
|
return <NativeMessagePreviewContent message={getInitialMessagePreview} lineClamp={lineClamp} maxHeight={maxHeight} />;
|
|
}
|
|
if (previewableMedia.length > 0 && text2 !== null) {
|
|
return <View>
|
|
<SystemMessageText text={text2} />
|
|
{secondaryText !== null && <Text variant="redesign/message-preview/medium" color="text-link" lineClamp={NOTIFICATION_PREVIEW_LINE_CLAMP}>{secondaryText}</Text>}
|
|
</View>;
|
|
}
|
|
if (message.poll != null) {
|
|
const text = message.poll.question.text;
|
|
return <View>
|
|
<SystemMessageText text={nullableMessageAuthor != null ? intl.format(t["1wtRlq"], {
|
|
username: nullableMessageAuthor.nick
|
|
}) : intl.string(t.n3shVJ)} />
|
|
<Text variant="redesign/message-preview/medium" color="text-default" lineClamp={NOTIFICATION_PREVIEW_LINE_CLAMP}>{text}</Text>
|
|
</View>;
|
|
}
|
|
return <NativeMessagePreviewContent message={message} lineClamp={lineClamp} maxHeight={maxHeight} />;
|
|
};
|
|
export { SystemMessageText };
|