225 lines
11 KiB
TypeScript
225 lines
11 KiB
TypeScript
// Metro module 15365 (f15366).
|
|
import * as Module19 from "react";
|
|
import { useContext, useMemo, useEffect, useCallback } from "react";
|
|
import { View } from "react-native";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../../stores/GuildMemberStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import RelationshipStore from "../../../stores/RelationshipStore";
|
|
import UserGuildSettingsStore from "../../../stores/UserGuildSettingsStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import { ITEM_PADDING } from "./DesignConstants";
|
|
import { DEFAULT_ROLE_COLOR_HEX, MessageEmbedTypes } from "../../../Constants";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import { createICYMIStyles } from "./createICYMIStyles";
|
|
import { isAndroid } from "../../../utils/PlatformUtils";
|
|
import { ICYMIContext } from "./ICYMIContext";
|
|
import { extractMediaSourcesFromMessage } from "../../media_viewer/native/MediaSourceUtil";
|
|
import { GRAVITY_VALID_EMBED_TYPES } from "../ICYMITypes";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import { MessageRowPreview, NonMediaEmbedsRowPreview } from "./ICYMIMessageRowPreview";
|
|
import ICYMIMediaMosaic from "./media/ICYMIMediaMosaic";
|
|
import { Text } from "../../../design/components/Text/native/Text";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { Avatar, AvatarSizes } from "../../../design/void/native";
|
|
import { getName } from "../../../utils/NicknameUtils";
|
|
import GuildActionCreators from "../../../actions/GuildActionCreators";
|
|
import { useICYMIMessage, useGravityMessage } from "../ICYMIUtils";
|
|
import ICYMIActionCreators from "../ICYMIActionCreators";
|
|
import { openChannelLongPressActionSheet } from "../../channel/native/openChannelLongPressActionSheet";
|
|
import { showLongPressMessageActionSheet } from "../../messages/native/long_press/showLongPressMessageActionSheet";
|
|
import { navigateToPost } from "./ICYMIShared";
|
|
import ICYMICardInCard from "./ICYMICardInCard";
|
|
import SnowflakeUtils from "../../../utils/SnowflakeUtils";
|
|
import { PressableHighlight } from "../../../design/void/Pressables/native/Pressables";
|
|
import getChannelA11yLabel, { getChannelA11yHint } from "../../channel/getChannelA11yLabel";
|
|
import ICYMICardInteractionRow from "./ICYMICardInteractionRow";
|
|
let PX_12, PX_8, styles, ReplyMessageContent, Component;
|
|
const MessageRowContent = function MessageRowContent(props) {
|
|
const { message, channel, lineClamp = 3, nested = false, visible = false } = props;
|
|
const r14 = styles();
|
|
const context = useContext(ICYMIContext);
|
|
const r34 = extractMediaSourcesFromMessage(message, message, channel.guild_id, GRAVITY_VALID_EMBED_TYPES);
|
|
const stateFromStores2 = useStateFromStores([UserGuildSettingsStore], () => UserGuildSettingsStore.isChannelMuted(channel.getGuildId(), channel.id));
|
|
const memo = useMemo(() => {
|
|
const r1 = message.embeds.length !== 1 || message.attachments.length > 0;
|
|
return r1 ? !r1 : message.embeds[0].type === MessageEmbedTypes.GIFV && message.embeds[0].url === message.content;
|
|
}, [message.attachments.length, message.content, message.embeds]);
|
|
const r18 = message.attachments.every(({ content_type }) => content_type == null ? void 0 : content_type.startsWith("audio/"));
|
|
return <View style={[r14.messagePreview, nested ? null : {
|
|
paddingLeft: context.margin
|
|
}]}>
|
|
{memo ? !memo : <MessageRowPreview message={message} muted={stateFromStores2} lineClamp={lineClamp} messageOptions={r34.length === 0 ? message.attachments.length > 0 ? message.embeds.length === 0 ? {
|
|
renderAttachments: true
|
|
} : void 0 : void 0 : void 0} pointerEvents={r18 ? "auto" : "none"} />}
|
|
{r34.length > 0 && <View style={r14.media}>
|
|
<ICYMIMediaMosaic message={message} visible={visible} itemType="message" />
|
|
</View>}
|
|
{r34.length === 0 && message.embeds.length > 0 && <View style={r14.media}>
|
|
<NonMediaEmbedsRowPreview message={message} muted={stateFromStores2} lineClamp={3} />
|
|
</View>}
|
|
</View>;
|
|
};
|
|
ReplyMessageContent = function ReplyMessageContent(props) {
|
|
const { message: message2, channel: channel3, guild } = props;
|
|
const r12 = styles();
|
|
const context = useContext(ICYMIContext);
|
|
const stateFromStores2 = useStateFromStores([UserStore], () => UserStore.getUser(message2.author.id));
|
|
let color = useStateFromStores([GuildMemberStore], () => GuildMemberStore.getMember(guild.id, message2.author.id))?.colorString;
|
|
if (color == null) {
|
|
color = DEFAULT_ROLE_COLOR_HEX;
|
|
}
|
|
const width = useContext(ICYMIContext).width;
|
|
return stateFromStores2 == null ? null : <View style={r12.replyPreview}>
|
|
<Text variant="text-sm/semibold" color="text-muted" style={{
|
|
fontStyle: "italic"
|
|
}}>
|
|
{intl.string(t.mPPcez)}
|
|
</Text>
|
|
<View style={r12.replyInner}>
|
|
<Avatar animate={false} guildId={guild.id} user={stateFromStores2} size={AvatarSizes.SMALL} />
|
|
<View style={{
|
|
gap: 4,
|
|
width: width - context.inset - 2 * ITEM_PADDING - 2 * PX_12 - 30 - PX_8 - 2
|
|
}}>
|
|
<Text variant="text-md/semibold" style={{
|
|
color
|
|
}} lineClamp={1}>
|
|
{getName(guild.id, channel3.id, stateFromStores2)}
|
|
</Text>
|
|
<ICYMIContext.Provider value={{
|
|
width: width - 2 * PX_12 - 30 - PX_8 - 2,
|
|
margin: context.margin,
|
|
inset: context.inset
|
|
}}>
|
|
<MessageRowContent message={message2} channel={channel3} guild={guild} nested />
|
|
</ICYMIContext.Provider>
|
|
</View>
|
|
</View>
|
|
</View>;
|
|
};
|
|
PX_12 = Module712.space.PX_12;
|
|
PX_8 = Module712.space.PX_8;
|
|
styles = createICYMIStyles((a0) => ({
|
|
pressable: {
|
|
flex: 1,
|
|
paddingLeft: a0.inset,
|
|
gap: Module712.space.PX_8
|
|
},
|
|
messagePreview: {
|
|
marginTop: isAndroid() ? -2 : 0,
|
|
borderRadius: Module712.radii.md,
|
|
gap: 0
|
|
},
|
|
replyPreview: {
|
|
gap: Module712.space.PX_8,
|
|
marginHorizontal: a0.margin,
|
|
padding: PX_12,
|
|
overflow: "hidden",
|
|
borderWidth: 1,
|
|
borderColor: Module712.colors.BORDER_SUBTLE,
|
|
borderRadius: Module712.radii.lg,
|
|
maxHeight: 132
|
|
},
|
|
replyInner: {
|
|
flexDirection: "row",
|
|
gap: PX_8,
|
|
overflow: "hidden"
|
|
},
|
|
afterMessage: {
|
|
paddingLeft: a0.inset,
|
|
paddingBottom: a0.margin
|
|
},
|
|
media: {
|
|
marginRight: a0.margin
|
|
},
|
|
footer: {
|
|
marginTop: Module712.space.PX_8,
|
|
marginBottom: a0.margin,
|
|
gap: Module712.space.PX_8,
|
|
paddingHorizontal: a0.margin,
|
|
marginLeft: a0.inset
|
|
}
|
|
}));
|
|
Component = Module19.memo(function({ message: message3, channel: channel2, guild: guild2, visible, messageContext }) {
|
|
const stateFromStores2 = useStateFromStores([UserGuildSettingsStore], () => UserGuildSettingsStore.isChannelMuted(channel2.getGuildId(), channel2.id));
|
|
useEffect(() => {
|
|
if (guild2?.id != null) {
|
|
GuildActionCreators.requestMembersById(guild2?.id, message3.author.id);
|
|
}
|
|
}, [guild2?.id, message3.author.id]);
|
|
const iCYMIMessage = useICYMIMessage(channel2.id, messageContext?.reply_message_id);
|
|
const iCYMIMessage2 = useICYMIMessage(channel2.id, messageContext?.before_message_id);
|
|
const r14 = styles();
|
|
const callback2 = useCallback(() => {
|
|
ICYMIActionCreators.itemInteracted(message3.id, "message", "long_press_channel");
|
|
ICYMIActionCreators.feedItemActioned({
|
|
itemId: message3.id,
|
|
itemType: "message",
|
|
actionParameters: {
|
|
actionGestureType: "long_press",
|
|
actionTargetElement: "item_header",
|
|
actionIntentType: "open",
|
|
actionDestinationType: null
|
|
}
|
|
});
|
|
openChannelLongPressActionSheet(channel2.id);
|
|
}, [channel2.id, message3]);
|
|
const callback3 = useCallback(() => {
|
|
ICYMIActionCreators.itemInteracted(message3.id, "message", "long_press_message");
|
|
ICYMIActionCreators.feedItemActioned({
|
|
itemId: message3.id,
|
|
itemType: "message",
|
|
actionParameters: {
|
|
actionGestureType: "long_press",
|
|
actionTargetElement: "item_body",
|
|
actionIntentType: "open",
|
|
actionDestinationType: null
|
|
}
|
|
});
|
|
showLongPressMessageActionSheet({
|
|
channel: channel2,
|
|
message: message3,
|
|
user: UserStore.getUser(message3.author.id)
|
|
});
|
|
}, [channel2, message3]);
|
|
const callback = useCallback(() => {
|
|
ICYMIActionCreators.itemInteracted(message3.id, "message", "press_message");
|
|
ICYMIActionCreators.feedItemActioned({
|
|
itemId: message3.id,
|
|
itemType: "message",
|
|
actionParameters: {
|
|
actionGestureType: "press",
|
|
actionTargetElement: "item_container",
|
|
actionIntentType: "navigate",
|
|
actionDestinationType: "channel"
|
|
}
|
|
});
|
|
navigateToPost(channel2.id, guild2.id, message3.id);
|
|
}, [channel2.id, guild2.id, message3.id]);
|
|
return <ICYMICardInCard actionLabel={intl.string(t.hMFMY9)} id={message3.id} interactionType="message" channelId={channel2.id} timestamp={SnowflakeUtils.extractTimestamp(message3.id)} onHeaderPress={callback} onHeaderLongPress={callback2} message={message3} shouldFeatureUser>
|
|
<PressableHighlight onPress={callback} onLongPress={callback3} unstable_pressDelay={130} accessibilityRole="button" accessibilityLabel={getChannelA11yLabel({
|
|
channel: channel2
|
|
})} accessibilityHint={getChannelA11yHint({
|
|
channel: channel2,
|
|
muted: stateFromStores2
|
|
})} style={r14.pressable}>
|
|
{iCYMIMessage2 != null ? <MessageRowContent message={iCYMIMessage2} channel={channel2} guild={guild2} visible={visible} /> : null}
|
|
<MessageRowContent message={message3} channel={channel2} guild={guild2} visible={visible} />
|
|
{iCYMIMessage != null ? <ReplyMessageContent message={iCYMIMessage} channel={channel2} guild={guild2} /> : null}
|
|
</PressableHighlight>
|
|
<View style={r14.footer}>
|
|
<ICYMICardInteractionRow message={message3} channel={channel2} guild={guild2} backgroundVariant="base" id={message3.id} itemType="message" />
|
|
</View>
|
|
</ICYMICardInCard>;
|
|
});
|
|
export default function MessageRowWrapper(props) {
|
|
const { message: message4, messageContext, visible } = props;
|
|
const gravityMessage = useGravityMessage(message4);
|
|
const stateFromStores = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(gravityMessage.getChannelId()));
|
|
const stateFromStores2 = useStateFromStores([GuildStore], () => GuildStore.getGuild(stateFromStores?.guild_id));
|
|
const stateFromStores3 = useStateFromStores([RelationshipStore], () => RelationshipStore.isBlockedOrIgnored(gravityMessage.author.id));
|
|
return stateFromStores == null ? null : stateFromStores2 == null ? null : stateFromStores3 ? null : <Component message={gravityMessage} channel={stateFromStores} guild={stateFromStores2} messageContext={messageContext} visible={visible} />;
|
|
};
|
|
export { MessageRowContent };
|