mirror of
https://github.com/cinnyapp/cinny.git
synced 2026-11-20 00:51:24 -08:00
rename reply content renderer to inline render and properly truncate
fallback content
This commit is contained in:
1 parent
f46d01e9f4
commit
2cd3f67da7
6 files changed
+120
-171
No files matched your search
+32
-26
@@ -10,25 +10,21 @@ Please see LICENSE file in root of repository for full details.
|
||||
import React from 'react';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import { Text } from 'folds';
|
||||
import { Icons, Text } from 'folds';
|
||||
import {
|
||||
MessageAudioContent,
|
||||
MessageFileContent,
|
||||
MessageImageContent,
|
||||
MessageStickerContent,
|
||||
MessageVideoContent,
|
||||
UnsupportedContent,
|
||||
ReplyMEmote,
|
||||
ReplyMNotice,
|
||||
ReplyMText,
|
||||
ReplyMLocation,
|
||||
EmptyContent,
|
||||
FallbackContent,
|
||||
} from './message';
|
||||
import { MsgType } from '../../types/matrix/common';
|
||||
import { rContent } from '../../client/reader';
|
||||
import { MessageEvent } from '../../types/matrix/room';
|
||||
|
||||
type RenderReplyContentProps = {
|
||||
type RenderInlineContentProps = {
|
||||
displayName: string;
|
||||
eventType: string;
|
||||
edited?: boolean;
|
||||
@@ -38,7 +34,7 @@ type RenderReplyContentProps = {
|
||||
linkifyOpts: Opts;
|
||||
};
|
||||
|
||||
export function RenderReplyContent({
|
||||
export function RenderInlineContent({
|
||||
displayName,
|
||||
eventType,
|
||||
edited,
|
||||
@@ -46,17 +42,19 @@ export function RenderReplyContent({
|
||||
highlightRegex,
|
||||
htmlReactParserOptions,
|
||||
linkifyOpts,
|
||||
}: RenderReplyContentProps) {
|
||||
}: RenderInlineContentProps) {
|
||||
if (eventType === MessageEvent.Sticker) {
|
||||
return (
|
||||
<Text size="T300" priority="300">
|
||||
<MessageStickerContent />
|
||||
</Text>
|
||||
<FallbackContent iconSrc={Icons.Sticker}>
|
||||
<Text size="T300" priority="300" truncate>
|
||||
<i>Sticker</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
if (eventType !== MessageEvent.RoomMessage) {
|
||||
return <UnsupportedContent size="T300" eventType={eventType} />;
|
||||
return <UnsupportedContent size="T300" eventType={eventType} truncate />;
|
||||
}
|
||||
|
||||
const msgType = rContent.msgtype(content);
|
||||
@@ -100,33 +98,41 @@ export function RenderReplyContent({
|
||||
|
||||
if (msgType === MsgType.Image) {
|
||||
return (
|
||||
<Text size="T300" priority="300">
|
||||
<MessageImageContent />
|
||||
</Text>
|
||||
<FallbackContent iconSrc={Icons.Photo}>
|
||||
<Text size="T300" priority="300" truncate>
|
||||
<i>Image</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Video) {
|
||||
return (
|
||||
<Text size="T300" priority="300">
|
||||
<MessageVideoContent />
|
||||
</Text>
|
||||
<FallbackContent iconSrc={Icons.Vlc}>
|
||||
<Text size="T300" priority="300" truncate>
|
||||
<i>Video</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Audio) {
|
||||
return (
|
||||
<Text size="T300" priority="300">
|
||||
<MessageAudioContent />
|
||||
</Text>
|
||||
<FallbackContent iconSrc={Icons.Play}>
|
||||
<Text size="T300" priority="300" truncate>
|
||||
<i>Audio</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.File) {
|
||||
return (
|
||||
<Text size="T300" priority="300">
|
||||
<MessageFileContent />
|
||||
</Text>
|
||||
<FallbackContent iconSrc={Icons.File}>
|
||||
<Text size="T300" priority="300" truncate>
|
||||
<i>File</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +141,7 @@ export function RenderReplyContent({
|
||||
}
|
||||
|
||||
if (Object.keys(content).length === 0) {
|
||||
return <EmptyContent size="T300" />;
|
||||
return <EmptyContent size="T300" truncate />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -18,14 +18,9 @@ import {
|
||||
AudioContent,
|
||||
FileContent,
|
||||
ImageContent,
|
||||
MessageBadEncryptedContent,
|
||||
MessageBrokenContent,
|
||||
MessageDeletedContent,
|
||||
MessageEditedContent,
|
||||
UnsupportedMessageEventType,
|
||||
MessageUnsupportedContent,
|
||||
VideoContent,
|
||||
MessageEmptyContent,
|
||||
FallbackContent,
|
||||
} from './content';
|
||||
import { FALLBACK_MIMETYPE, getBlobSafeMimeType } from '../../utils/mimeTypes';
|
||||
import { parseGeoUri, scaleYDimension } from '../../utils/common';
|
||||
@@ -35,56 +30,81 @@ import { RenderBody } from './RenderBody';
|
||||
import { rContent, rEncryptedFile, rInfo } from '../../../client/reader';
|
||||
import { UrlPreviewCard, UrlPreviewHolder } from '../url-preview';
|
||||
import { testMatrixTo } from '../../plugins/matrix-to';
|
||||
import { Code } from '../../styles/CustomHtml.css';
|
||||
|
||||
type TextProps = {
|
||||
size?: 'T400' | 'T300';
|
||||
truncate?: boolean;
|
||||
};
|
||||
|
||||
export function MBadEncrypted({ size }: TextProps) {
|
||||
return (
|
||||
<Text size={size}>
|
||||
<MessageBadEncryptedContent />
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
type RedactedContentProps = TextProps & {
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
export function RedactedContent({ size, reason }: RedactedContentProps) {
|
||||
export function RedactedContent({ size, reason, truncate }: RedactedContentProps) {
|
||||
return (
|
||||
<Text size={size}>
|
||||
<MessageDeletedContent reason={reason} />
|
||||
</Text>
|
||||
<FallbackContent variant="Warning" iconSrc={Icons.Delete}>
|
||||
<Text size={size} truncate={truncate}>
|
||||
{reason ? (
|
||||
<i>This message has been deleted. {reason}</i>
|
||||
) : (
|
||||
<i>This message has been deleted</i>
|
||||
)}
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
export function UnsupportedContent({ size, eventType }: TextProps & { eventType?: string }) {
|
||||
export function UnsupportedContent({
|
||||
size,
|
||||
truncate,
|
||||
eventType,
|
||||
}: TextProps & { eventType?: string }) {
|
||||
return (
|
||||
<Text size={size}>
|
||||
{eventType ? (
|
||||
<UnsupportedMessageEventType eventType={eventType} />
|
||||
) : (
|
||||
<MessageUnsupportedContent />
|
||||
)}
|
||||
</Text>
|
||||
<FallbackContent
|
||||
variant={eventType ? undefined : 'Critical'}
|
||||
iconSrc={eventType ? Icons.Code : Icons.Warning}
|
||||
>
|
||||
<Text size={size} truncate={truncate}>
|
||||
{eventType ? (
|
||||
<>
|
||||
Sent <code className={Code}>{eventType}</code> event
|
||||
</>
|
||||
) : (
|
||||
<i>Unsupported message</i>
|
||||
)}
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
export function BrokenContent({ size }: TextProps) {
|
||||
export function FailedToLoadContent({ size, truncate }: TextProps) {
|
||||
return (
|
||||
<Text size={size}>
|
||||
<MessageBrokenContent />
|
||||
</Text>
|
||||
<FallbackContent variant="Critical" iconSrc={Icons.Warning}>
|
||||
<Text size={size} truncate={truncate}>
|
||||
<i>Failed to load message</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmptyContent({ size }: TextProps) {
|
||||
export function BrokenContent({ size, truncate }: TextProps) {
|
||||
return (
|
||||
<Text size={size}>
|
||||
<MessageEmptyContent />
|
||||
</Text>
|
||||
<FallbackContent variant="Critical" iconSrc={Icons.Warning}>
|
||||
<Text size={size} truncate={truncate}>
|
||||
<i>Broken message</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmptyContent({ size, truncate }: TextProps) {
|
||||
return (
|
||||
<FallbackContent variant="Critical" iconSrc={Icons.Warning}>
|
||||
<Text size={size} truncate={truncate}>
|
||||
<i>Empty message</i>
|
||||
</Text>
|
||||
</FallbackContent>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -464,7 +484,7 @@ export function MSticker({ content, mediaAutoLoad, outlineAttachment }: MSticker
|
||||
const mxcUrl = rEncryptedFile.url(rContent.file(content)) ?? rContent.url(content);
|
||||
|
||||
if (typeof mxcUrl !== 'string') {
|
||||
return <MessageBrokenContent />;
|
||||
return <BrokenContent />;
|
||||
}
|
||||
const height = scaleYDimension(rInfo.w(imgInfo) || 152, 152, rInfo.h(imgInfo) || 152);
|
||||
|
||||
|
||||
@@ -135,5 +135,9 @@ export function ReplyMLocation({ content }: ReplyMLocationProps) {
|
||||
const location = parseGeoUri(geoUri);
|
||||
if (!location) return <BrokenContent />;
|
||||
|
||||
return <Text size="T300">{geoUri}</Text>;
|
||||
return (
|
||||
<Text size="T300" truncate>
|
||||
{geoUri}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
@@ -14,15 +14,14 @@ import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import { LinePlaceholder } from './placeholder';
|
||||
import { randomNumberBetween } from '../../utils/common';
|
||||
import { MessageFailedContent } from './content';
|
||||
import { useRoomEvent } from '../../hooks/useRoomEvent';
|
||||
import colorMXID from '../../../util/colorMXID';
|
||||
import { GetMemberPowerTag } from '../../hooks/useMemberPowerTag';
|
||||
import { GetRoomMemberNameCallback } from '../../hooks/useRoomMembers';
|
||||
import { rContent, rUnsigned } from '../../../client/reader';
|
||||
import { TimelineView } from '../../../client/room';
|
||||
import { RenderReplyContent } from '../RenderReplyContent';
|
||||
import { RedactedContent } from './MsgTypeRenderers';
|
||||
import { RenderInlineContent } from '../RenderInlineContent';
|
||||
import { FailedToLoadContent, RedactedContent } from './MsgTypeRenderers';
|
||||
import { HoverUnderline } from '../../styles/Text.css';
|
||||
import { useObservableValueOptionally } from '../../hooks/useObservableValue';
|
||||
import { getLatestEditEvent } from '../../utils/room';
|
||||
@@ -144,7 +143,7 @@ export function Reply({
|
||||
inline
|
||||
>
|
||||
{(contentEvent) => (
|
||||
<RenderReplyContent
|
||||
<RenderInlineContent
|
||||
displayName={getMemberName(event.sender)}
|
||||
eventType={contentEvent.type}
|
||||
edited={!!editedEvent}
|
||||
@@ -184,11 +183,7 @@ export function Reply({
|
||||
data-event-id={eventId}
|
||||
>
|
||||
{replyEvent && renderEventContent(replyEvent)}
|
||||
{replyEvent === null && (
|
||||
<Text size="T300">
|
||||
<MessageFailedContent />
|
||||
</Text>
|
||||
)}
|
||||
{replyEvent === null && <FailedToLoadContent size="T300" truncate />}
|
||||
{replyEvent === undefined && (
|
||||
<LinePlaceholder
|
||||
style={{
|
||||
|
||||
@@ -7,69 +7,28 @@ https://cinny.in
|
||||
Please see LICENSE file in root of repository for full details.
|
||||
*/
|
||||
|
||||
import { Box, Icon, Icons, Text, as, color, config } from 'folds';
|
||||
import React from 'react';
|
||||
import { Code } from '../../../styles/CustomHtml.css';
|
||||
import { Box, ContainerColor, Icon, IconSrc, Icons, Text, as, color, config } from 'folds';
|
||||
import React, { ReactNode } from 'react';
|
||||
|
||||
const warningStyle = { color: color.Warning.Main, opacity: config.opacity.P300 };
|
||||
const criticalStyle = { color: color.Critical.Main, opacity: config.opacity.P300 };
|
||||
|
||||
export const MessageDeletedContent = as<'div', { children?: never; reason?: string }>(
|
||||
({ reason, ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={warningStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Delete} />
|
||||
{reason ? (
|
||||
<i>This message has been deleted. {reason}</i>
|
||||
) : (
|
||||
<i>This message has been deleted</i>
|
||||
)}
|
||||
type FallbackContentProps = {
|
||||
iconSrc: IconSrc;
|
||||
children?: ReactNode;
|
||||
variant?: ContainerColor;
|
||||
};
|
||||
export function FallbackContent({ variant, iconSrc, children }: FallbackContentProps) {
|
||||
return (
|
||||
<Box
|
||||
style={{ color: variant ? color[variant].OnContainer : undefined }}
|
||||
alignItems="Center"
|
||||
gap="100"
|
||||
>
|
||||
<Icon size="50" src={iconSrc} />
|
||||
{children}
|
||||
</Box>
|
||||
)
|
||||
);
|
||||
|
||||
export const MessageUnsupportedContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={criticalStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Warning} />
|
||||
<i>Unsupported message</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const UnsupportedMessageEventType = as<'div', { eventType: string; children?: never }>(
|
||||
({ eventType, ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Code} />
|
||||
Sent <code className={Code}>{eventType}</code> event
|
||||
</Box>
|
||||
)
|
||||
);
|
||||
|
||||
export const MessageFailedContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={criticalStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Warning} />
|
||||
<i>Failed to load message</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageBadEncryptedContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={warningStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Lock} />
|
||||
<i>Unable to decrypt message</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageNotDecryptedContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={warningStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Lock} />
|
||||
<i>This message is not decrypted yet</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageBrokenContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={criticalStyle} {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Warning} />
|
||||
<i>Broken message</i>
|
||||
</Box>
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
export const MessageEmptyContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" style={criticalStyle} {...props} ref={ref}>
|
||||
@@ -83,38 +42,3 @@ export const MessageEditedContent = as<'span', { children?: never }>(({ ...props
|
||||
{' (edited)'}
|
||||
</Text>
|
||||
));
|
||||
|
||||
export const MessageStickerContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Sticker} filled />
|
||||
<i>Sticker</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageImageContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Photo} filled />
|
||||
<i>Image</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageVideoContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Vlc} filled />
|
||||
<i>Video</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageAudioContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.Play} filled />
|
||||
<i>Audio</i>
|
||||
</Box>
|
||||
));
|
||||
|
||||
export const MessageFileContent = as<'div', { children?: never }>(({ ...props }, ref) => (
|
||||
<Box as="span" alignItems="Center" gap="100" {...props} ref={ref}>
|
||||
<Icon size="50" src={Icons.File} filled />
|
||||
<i>File</i>
|
||||
</Box>
|
||||
));
|
||||
@@ -21,7 +21,7 @@ import * as css from './styles.css';
|
||||
import { MessageContent } from '../../components/MessageContent';
|
||||
import { useClient } from '../../hooks/useClient';
|
||||
import { NavItemContent } from '../../components/nav/styles.css';
|
||||
import { RenderReplyContent } from '../../components/RenderReplyContent';
|
||||
import { RenderInlineContent } from '../../components/RenderInlineContent';
|
||||
import { rContent, rUnsigned } from '../../../client/reader';
|
||||
import { getLatestEditEvent } from '../../utils/room';
|
||||
import { RedactedContent } from '../../components/message';
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
renderMatrixMention,
|
||||
} from '../../plugins/react-custom-html-parser';
|
||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
import { getMxIdLocalPart } from '../../utils/matrix';
|
||||
|
||||
type ThreadNavItemProps = {
|
||||
thread: ThreadTimeline;
|
||||
@@ -66,7 +67,7 @@ function ThreadNavItem({
|
||||
redactedEvents?.has(event.event_id) || !!rUnsigned.redactedBecause(event.unsigned);
|
||||
|
||||
if (redacted) {
|
||||
return <RedactedContent size="T300" />;
|
||||
return <RedactedContent size="T300" truncate />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -78,7 +79,7 @@ function ThreadNavItem({
|
||||
inline
|
||||
>
|
||||
{(contentEvent) => (
|
||||
<RenderReplyContent
|
||||
<RenderInlineContent
|
||||
displayName={event.sender}
|
||||
eventType={contentEvent.type}
|
||||
edited={!!editedEvent}
|
||||
@@ -147,7 +148,7 @@ export function ThreadNavItems({
|
||||
timeline.roomId,
|
||||
href,
|
||||
makeMentionCustomProps((evt) => evt.preventDefault()),
|
||||
(userId) => userId,
|
||||
(userId) => getMxIdLocalPart(userId) ?? userId,
|
||||
(roomId) => ct.roomToName.read.get(roomId) ?? roomId
|
||||
)
|
||||
),
|
||||
@@ -160,8 +161,7 @@ export function ThreadNavItems({
|
||||
getReactCustomHtmlInlineParser(ct, timeline.roomId, {
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleMentionClick: () => undefined,
|
||||
getMemberName: (userId) => userId,
|
||||
getMemberName: (userId) => getMxIdLocalPart(userId) ?? userId,
|
||||
getRoomName: (roomId) => ct.roomToName.read.get(roomId) ?? roomId,
|
||||
}),
|
||||
[ct, timeline, linkifyOpts, useAuthentication]
|
||||
|
||||
Reference in new issue
Block a user