Merge branch '7w1:dev' into add-ui-for-commands
This commit is contained in:
22 files changed
+881
-173
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: minor
|
||||
---
|
||||
|
||||
Add message forwarding with metadata
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: patch
|
||||
---
|
||||
|
||||
Improved the UI of file descriptions
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
servers {
|
||||
protocols h1 h2c
|
||||
}
|
||||
}
|
||||
|
||||
:80 {
|
||||
root * /app
|
||||
|
||||
# Enable on-the-fly compression for things not pre-compressed
|
||||
encode zstd gzip
|
||||
|
||||
file_server {
|
||||
precompressed br
|
||||
}
|
||||
|
||||
try_files {path} /index.html
|
||||
}
|
||||
+2
-5
@@ -19,10 +19,7 @@ FROM scratch AS site-dist
|
||||
COPY --from=builder /src/dist /
|
||||
|
||||
## App
|
||||
FROM nginx:1.29.5-alpine
|
||||
FROM caddy:2-alpine
|
||||
|
||||
COPY --from=site-dist / /app
|
||||
COPY docker-nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
RUN rm -rf /usr/share/nginx/html \
|
||||
&& ln -s /app /usr/share/nginx/html
|
||||
COPY Caddyfile /etc/caddy/Caddyfile
|
||||
@@ -1,21 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
rewrite ^/config.json$ /config.json break;
|
||||
rewrite ^/manifest.json$ /manifest.json break;
|
||||
|
||||
rewrite ^/sw.js$ /sw.js break;
|
||||
rewrite ^/pdf.worker.min.js$ /pdf.worker.min.js break;
|
||||
|
||||
rewrite ^/public/(.*)$ /public/$1 break;
|
||||
rewrite ^/assets/(.*)$ /assets/$1 break;
|
||||
|
||||
rewrite ^/element-call/dist/(.*)$ /element-call/dist/$1 break;
|
||||
|
||||
rewrite ^(.+)$ /index.html break;
|
||||
}
|
||||
}
|
||||
Generated
+35
@@ -98,6 +98,7 @@
|
||||
"prettier": "3.8.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.3.1",
|
||||
"vite-plugin-compression2": "2.5.0",
|
||||
"vite-plugin-pwa": "^1.2.0",
|
||||
"vite-plugin-static-copy": "^3.2.0",
|
||||
"vite-plugin-svgr": "4.5.0",
|
||||
@@ -14920,6 +14921,13 @@
|
||||
"url": "https://opencollective.com/webpack"
|
||||
}
|
||||
},
|
||||
"node_modules/tar-mini": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tar-mini/-/tar-mini-0.2.0.tgz",
|
||||
"integrity": "sha512-+qfUHz700DWnRutdUsxRRVZ38G1Qr27OetwaMYTdg8hcPxf46U0S1Zf76dQMWRBmusOt2ZCK5kbIaiLkoGO7WQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/temp-dir": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz",
|
||||
@@ -16032,6 +16040,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vite-plugin-compression2": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/vite-plugin-compression2/-/vite-plugin-compression2-2.5.0.tgz",
|
||||
"integrity": "sha512-bHxtBibPxxSn5eZSe0IAzvYucP/hg8Bz8ppjbH7lndU5kIHT+92qTkB4z9xWYfnyV0YHuir1SjOuyO0fzU4Vgg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rollup/pluginutils": "^5.1.0",
|
||||
"tar-mini": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vite-plugin-pwa": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-1.2.0.tgz",
|
||||
@@ -25820,6 +25839,12 @@
|
||||
"integrity": "sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==",
|
||||
"dev": true
|
||||
},
|
||||
"tar-mini": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tar-mini/-/tar-mini-0.2.0.tgz",
|
||||
"integrity": "sha512-+qfUHz700DWnRutdUsxRRVZ38G1Qr27OetwaMYTdg8hcPxf46U0S1Zf76dQMWRBmusOt2ZCK5kbIaiLkoGO7WQ==",
|
||||
"dev": true
|
||||
},
|
||||
"temp-dir": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz",
|
||||
@@ -26369,6 +26394,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"vite-plugin-compression2": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/vite-plugin-compression2/-/vite-plugin-compression2-2.5.0.tgz",
|
||||
"integrity": "sha512-bHxtBibPxxSn5eZSe0IAzvYucP/hg8Bz8ppjbH7lndU5kIHT+92qTkB4z9xWYfnyV0YHuir1SjOuyO0fzU4Vgg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@rollup/pluginutils": "^5.1.0",
|
||||
"tar-mini": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"vite-plugin-pwa": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-1.2.0.tgz",
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
"prettier": "3.8.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.3.1",
|
||||
"vite-plugin-compression2": "2.5.0",
|
||||
"vite-plugin-pwa": "^1.2.0",
|
||||
"vite-plugin-static-copy": "^3.2.0",
|
||||
"vite-plugin-svgr": "4.5.0",
|
||||
|
||||
@@ -2,10 +2,10 @@ import { memo, useMemo, useCallback } from 'react';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { testMatrixTo } from '$plugins/matrix-to';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { settingsAtom, CaptionPosition } from '$state/settings';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import { config } from 'folds';
|
||||
import { Box, config } from 'folds';
|
||||
import {
|
||||
AudioContent,
|
||||
DownloadFile,
|
||||
@@ -74,6 +74,13 @@ function RenderMessageContentInternal({
|
||||
const content = useMemo(() => getContent<any>(), [getContent]);
|
||||
|
||||
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
|
||||
const [captionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const captionPositionMap = {
|
||||
[CaptionPosition.Above]: 'column-reverse',
|
||||
[CaptionPosition.Below]: 'column',
|
||||
[CaptionPosition.Inline]: 'row',
|
||||
[CaptionPosition.Hidden]: 'row',
|
||||
} satisfies Record<CaptionPosition, React.CSSProperties['flexDirection']>;
|
||||
|
||||
const renderBody = useCallback(
|
||||
(props: any) => (
|
||||
@@ -112,54 +119,89 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
|
||||
const renderCaption = () => {
|
||||
if (captionPosition === CaptionPosition.Hidden) return null;
|
||||
if (content.filename && content.filename !== content.body) {
|
||||
if (captionPosition !== CaptionPosition.Inline)
|
||||
return (
|
||||
<MText
|
||||
style={CAPTION_STYLE}
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<MText
|
||||
style={CAPTION_STYLE}
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
<Box
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
wordBreak: 'break-word',
|
||||
maxWidth: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
flexShrink: 1,
|
||||
}}
|
||||
>
|
||||
<MText
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderFile = () => (
|
||||
<>
|
||||
<MFile
|
||||
content={content}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
renderAsPdfFile={() => (
|
||||
<ReadPdfFile
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MFile
|
||||
content={content}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
renderAsPdfFile={() => (
|
||||
<ReadPdfFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <PdfViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
renderAsTextFile={() => (
|
||||
<ReadTextFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <TextViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<DownloadFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <PdfViewer {...p} />}
|
||||
info={info}
|
||||
/>
|
||||
)}
|
||||
renderAsTextFile={() => (
|
||||
<ReadTextFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <TextViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<DownloadFile body={body} mimeType={mimeType} url={url} encInfo={encInfo} info={info} />
|
||||
</FileContent>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</FileContent>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (msgType === MsgType.Text) {
|
||||
@@ -205,79 +247,100 @@ function RenderMessageContentInternal({
|
||||
(typeof content.url === 'string' && content.url.toLowerCase().includes('gif'));
|
||||
|
||||
return (
|
||||
<>
|
||||
<MImage
|
||||
content={content}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
autoPlay={mediaAutoLoad}
|
||||
renderImage={(p) => {
|
||||
if (isGif && !autoplayGifs && p.src) {
|
||||
return (
|
||||
<ClientSideHoverFreeze src={p.src}>
|
||||
<Image {...p} loading="lazy" />
|
||||
</ClientSideHoverFreeze>
|
||||
);
|
||||
}
|
||||
return <Image {...p} loading="lazy" />;
|
||||
}}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MImage
|
||||
content={content}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
autoPlay={mediaAutoLoad}
|
||||
renderImage={(p) => {
|
||||
if (isGif && !autoplayGifs && p.src) {
|
||||
return (
|
||||
<ClientSideHoverFreeze src={p.src}>
|
||||
<Image {...p} loading="lazy" />
|
||||
</ClientSideHoverFreeze>
|
||||
);
|
||||
}
|
||||
return <Image {...p} loading="lazy" />;
|
||||
}}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Video) {
|
||||
return (
|
||||
<>
|
||||
<MVideo
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
body={body}
|
||||
info={info}
|
||||
{...videoProps}
|
||||
renderThumbnail={
|
||||
mediaAutoLoad
|
||||
? () => (
|
||||
<ThumbnailContent
|
||||
info={info}
|
||||
renderImage={(src) => (
|
||||
<Image alt={body} title={body} src={src} loading="lazy" />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
renderVideo={(p) => <Video {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MVideo
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
body={body}
|
||||
info={info}
|
||||
{...videoProps}
|
||||
renderThumbnail={
|
||||
mediaAutoLoad
|
||||
? () => (
|
||||
<ThumbnailContent
|
||||
info={info}
|
||||
renderImage={(src) => (
|
||||
<Image alt={body} title={body} src={src} loading="lazy" />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
renderVideo={(p) => <Video {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Audio) {
|
||||
return (
|
||||
<>
|
||||
<MAudio
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MAudio
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
MessageUnsupportedContent,
|
||||
} from './content';
|
||||
import { MessageTextBody } from './layout';
|
||||
import { unwrapForwardedContent } from './modals/MessageForward';
|
||||
|
||||
export function MBadEncrypted() {
|
||||
return (
|
||||
@@ -86,6 +87,10 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
|
||||
typeof content.formatted_body === 'string' ? content.formatted_body : undefined;
|
||||
|
||||
const trimmedBody = useMemo(() => trimReplyFromBody(body), [body]);
|
||||
const unwrappedForwardedContent = useMemo(
|
||||
() => unwrapForwardedContent(customBody ?? body),
|
||||
[customBody, body]
|
||||
);
|
||||
|
||||
const safeCustomBody = useMemo(() => {
|
||||
if (!customBody) return undefined;
|
||||
@@ -96,6 +101,10 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
|
||||
return customBody;
|
||||
}, [customBody]);
|
||||
|
||||
const isForwarded = useMemo(() => {
|
||||
const forwardMeta = content['moe.sable.message.forward'];
|
||||
return typeof forwardMeta === 'object';
|
||||
}, [content]);
|
||||
const isJumbo = useMemo(() => {
|
||||
if (!trimmedBody || trimmedBody.length >= 500) return false;
|
||||
if (!JUMBO_EMOJI_REG.test(trimmedBody)) return false;
|
||||
@@ -113,6 +122,19 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
|
||||
const urlsMatch = renderUrlsPreview && trimmedBody.match(URL_REG);
|
||||
const urls = urlsMatch ? [...new Set(urlsMatch)] : undefined;
|
||||
|
||||
if (isForwarded && unwrappedForwardedContent) {
|
||||
return (
|
||||
<MessageTextBody preWrap={typeof unwrappedForwardedContent !== 'string'} style={style}>
|
||||
{renderBody({
|
||||
body: trimmedBody,
|
||||
customBody: unwrappedForwardedContent,
|
||||
})}
|
||||
{edited && <MessageEditedContent />}
|
||||
{renderUrlsPreview && urls && urls.length > 0 && renderUrlsPreview(urls)}
|
||||
</MessageTextBody>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<MessageTextBody
|
||||
@@ -231,14 +253,20 @@ export function MImage({ content, renderImageContent, outlined }: MImageProps) {
|
||||
const height = scaleYDimension(imgInfo?.w || 400, 400, imgInfo?.h || 400);
|
||||
|
||||
return (
|
||||
<Attachment outlined={outlined}>
|
||||
<Attachment
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
outlined={outlined}
|
||||
>
|
||||
<AttachmentBox
|
||||
style={{
|
||||
height: toRem(height < 48 ? 48 : height),
|
||||
}}
|
||||
>
|
||||
{renderImageContent({
|
||||
body: content.body || 'Image',
|
||||
body: content.filename || 'Image',
|
||||
info: imgInfo,
|
||||
mimeType: imgInfo?.mimetype,
|
||||
url: mxcUrl,
|
||||
@@ -283,7 +311,13 @@ export function MVideo({ content, renderAsFile, renderVideoContent, outlined }:
|
||||
const filename = content.filename ?? content.body ?? 'Video';
|
||||
|
||||
return (
|
||||
<Attachment outlined={outlined}>
|
||||
<Attachment
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
outlined={outlined}
|
||||
>
|
||||
<AttachmentHeader>
|
||||
<FileHeader
|
||||
body={filename}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { modalAtom, ModalType } from '$state/modal';
|
||||
import { MessageReportInternal } from './MessageReport';
|
||||
import { MessageDeleteInternal } from './MessageDelete';
|
||||
import { MessageSourceInternal } from './MessageSource';
|
||||
import { MessageForwardInternal } from './MessageForward';
|
||||
import { MessageAllReactionInternal } from './MessageReactions';
|
||||
import { MessageReadReceiptInternal } from './MessageReadRecipts';
|
||||
|
||||
@@ -40,6 +41,12 @@ export function GlobalModalManager() {
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{modal.type === ModalType.Forward && (
|
||||
<Box>
|
||||
<MessageForwardInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{modal.type === ModalType.Source && (
|
||||
<Modal variant="Surface" size="300">
|
||||
<MessageSourceInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
// Modal for message forwarding, which allows users to select a room to forward the message to
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { modalAtom, ModalType } from '$state/modal';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Dialog,
|
||||
Header,
|
||||
Icon,
|
||||
Icons,
|
||||
IconButton,
|
||||
MenuItem,
|
||||
Text,
|
||||
config,
|
||||
Scroll,
|
||||
as,
|
||||
} from 'folds';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { JoinRule, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { allRoomsAtom } from '$state/room-list/roomList';
|
||||
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
|
||||
import { factoryRoomIdByActivity } from '$utils/sort';
|
||||
import * as css from '$features/room/message/styles.css';
|
||||
import { sanitizeCustomHtml } from '$utils/sanitize';
|
||||
import { getStateEvents } from '$utils/room';
|
||||
import { StateEvent } from '$types/matrix/room';
|
||||
|
||||
// Message forwarding component
|
||||
export const MessageForwardItem = as<'button', MessageForwardItemProps>(
|
||||
({ room, mEvent, onClose, ...props }: MessageForwardItemProps) => {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
const handleClick = () => {
|
||||
setModal({
|
||||
type: ModalType.Forward,
|
||||
room,
|
||||
mEvent,
|
||||
});
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.ArrowRight} />}
|
||||
radii="300"
|
||||
{...props}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Forward
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export const unwrapForwardedContent = (content: string) => {
|
||||
// unwrap the content of a forwarded message if it was wrapped in a blockquote with the data-forward-marker attribute
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(content, 'text/html');
|
||||
const forwardMarker = doc.querySelector('[data-forward-marker]');
|
||||
if (forwardMarker) {
|
||||
const blockquote = forwardMarker.querySelector('blockquote');
|
||||
if (blockquote) {
|
||||
return blockquote.innerHTML;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
};
|
||||
|
||||
type MessageForwardInternalProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
type ForwardMeta = {
|
||||
v: 1;
|
||||
is_forwarded: true;
|
||||
original_timestamp: number;
|
||||
original_room_id?: string;
|
||||
original_event_id?: string;
|
||||
// to mark that event_id and room_id are not present
|
||||
original_event_private: boolean;
|
||||
};
|
||||
|
||||
export function MessageForwardInternal({ room, mEvent, onClose }: MessageForwardInternalProps) {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const [isTargetSelected, setIsTargetSelected] = useState(false);
|
||||
const [isForwardSuccess, setIsForwardSuccess] = useState(false);
|
||||
const [isForwardError, setIsForwardError] = useState(false);
|
||||
const [targetRoomId, setTargetRoomId] = useState<string | null>(null);
|
||||
|
||||
// detect if it's a public room or not
|
||||
const joinRule = room.getJoinRule() ?? JoinRule.Invite;
|
||||
|
||||
const parentSpaceIds = getStateEvents(room, StateEvent.SpaceParent)
|
||||
.map((e) => e.getStateKey())
|
||||
.filter((id): id is string => Boolean(id));
|
||||
|
||||
const isInPublicSpace = parentSpaceIds.some((spaceId) => {
|
||||
const space = mx.getRoom(spaceId);
|
||||
return Boolean(space?.isSpaceRoom()) && space?.getJoinRule() === JoinRule.Public;
|
||||
});
|
||||
|
||||
// A room is private if its join rule is Invite (or other non-public/non-knock/non-restricted),
|
||||
// or it's Restricted but NOT inside a public space.
|
||||
const isPrivate =
|
||||
joinRule === JoinRule.Invite ||
|
||||
(joinRule === JoinRule.Restricted && !isInPublicSpace) ||
|
||||
(joinRule !== JoinRule.Public &&
|
||||
joinRule !== JoinRule.Knock &&
|
||||
joinRule !== JoinRule.Restricted);
|
||||
|
||||
const allRooms = useAtomValue(allRoomsAtom);
|
||||
const allJoinedRooms = useAllJoinedRoomsSet();
|
||||
const getRoom = useGetRoom(allJoinedRooms);
|
||||
// possible targets to forward the message to
|
||||
const forwardTargets = useMemo(
|
||||
() =>
|
||||
allRooms
|
||||
.filter((id) => id !== room.roomId)
|
||||
.filter((id) => {
|
||||
const target = getRoom(id);
|
||||
return !!target && !target.isSpaceRoom() && target.maySendMessage();
|
||||
})
|
||||
.sort(factoryRoomIdByActivity(mx)),
|
||||
[allRooms, room.roomId, getRoom, mx]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (isForwardSuccess) {
|
||||
setTimeout(() => {
|
||||
// close the modal if the message was forwarded successfully
|
||||
onClose();
|
||||
}, 2000);
|
||||
}
|
||||
}, [isForwardSuccess, onClose]);
|
||||
|
||||
// actually forward the message to the selected room
|
||||
const handleForwardClick = () => {
|
||||
if (!targetRoomId) return;
|
||||
|
||||
const targetRoom = getRoom(targetRoomId);
|
||||
const eventId = mEvent.getId();
|
||||
if (!targetRoom || !eventId) return;
|
||||
|
||||
type SendEventType = Parameters<typeof mx.sendEvent>[2];
|
||||
type SendEventContent = Parameters<typeof mx.sendEvent>[3];
|
||||
|
||||
const eventType = mEvent.getType() as SendEventType;
|
||||
// using reference relation to indicate that this is a forwarded message,
|
||||
// which allows clients to display it as such
|
||||
|
||||
const bodyModifText = `(Forwarded message from ${isPrivate ? 'a private room' : (getRoom(room.roomId)?.name ?? 'a room')})`;
|
||||
let newBodyPlain = '';
|
||||
let newBodyHtml = '';
|
||||
// transform if msgtype is m.text
|
||||
if (mEvent.getContent().msgtype === 'm.text') {
|
||||
const original = mEvent.getContent().body;
|
||||
newBodyPlain = `${bodyModifText}\n\n${original
|
||||
.split('\n')
|
||||
.map((l: string) => `> ${l}`)
|
||||
.join('\n')}`;
|
||||
const safeHtml = sanitizeCustomHtml(original).replace(/\n/g, '<br>');
|
||||
newBodyHtml =
|
||||
`<div class="forwarded" data-forward-marker>` +
|
||||
`<p>${sanitizeCustomHtml(bodyModifText)}</p>` +
|
||||
`<blockquote>${safeHtml}</blockquote>` +
|
||||
`</div>`;
|
||||
}
|
||||
let content;
|
||||
// handle privacy stuff
|
||||
if (isPrivate) {
|
||||
// if the message is from a private room, we should strip any media or mentions to avoid leaking information to the target room
|
||||
// we can still include the original message content in the body of the message, so we'll just use a fallback text/plain content with the original message body
|
||||
content = {
|
||||
...mEvent.getContent(),
|
||||
body: newBodyPlain,
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: newBodyHtml,
|
||||
'moe.sable.message.forward': {
|
||||
v: 1,
|
||||
is_forwarded: true,
|
||||
original_timestamp: mEvent.getTs(),
|
||||
original_event_private: true,
|
||||
} satisfies ForwardMeta,
|
||||
};
|
||||
} else {
|
||||
content = {
|
||||
...mEvent.getContent(),
|
||||
body: newBodyPlain,
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: newBodyHtml,
|
||||
'm.relates_to': {
|
||||
rel_type: 'm.reference',
|
||||
event_id: eventId,
|
||||
},
|
||||
'moe.sable.message.forward': {
|
||||
v: 1,
|
||||
is_forwarded: true,
|
||||
original_timestamp: mEvent.getTs(),
|
||||
original_room_id: room.roomId,
|
||||
original_event_id: eventId,
|
||||
original_event_private: false,
|
||||
} satisfies ForwardMeta,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
mx.sendEvent(targetRoom.roomId, null, eventType, content as unknown as SendEventContent).then(
|
||||
() => setIsForwardSuccess(true)
|
||||
);
|
||||
} catch {
|
||||
setIsForwardSuccess(false);
|
||||
setIsForwardError(true);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog variant="Surface">
|
||||
<Header
|
||||
style={{
|
||||
padding: `0 ${config.space.S200} 0 ${config.space.S400}`,
|
||||
borderBottomWidth: config.borderWidth.B300,
|
||||
}}
|
||||
variant="Surface"
|
||||
size="500"
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Text size="H4">Forward Message</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={onClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box direction="Column" style={{ height: '300px' }}>
|
||||
<Scroll hideTrack>
|
||||
<Box direction="Column" style={{ padding: config.space.S300 }}>
|
||||
{forwardTargets.map((roomId) => {
|
||||
const target = getRoom(roomId);
|
||||
if (!target) return null;
|
||||
return (
|
||||
<MenuItem
|
||||
key={roomId}
|
||||
data-room-id={roomId}
|
||||
onClick={() => {
|
||||
setIsTargetSelected(true);
|
||||
setTargetRoomId(roomId);
|
||||
}}
|
||||
variant={targetRoomId === roomId ? 'Success' : 'Surface'}
|
||||
aria-pressed={targetRoomId === roomId}
|
||||
size="400"
|
||||
radii="400"
|
||||
>
|
||||
<Text truncate>{target.name}</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Scroll>
|
||||
{isTargetSelected && targetRoomId && (
|
||||
<Button style={{ margin: config.space.S300 }} onClick={handleForwardClick}>
|
||||
<Text>Forward to {getRoom(targetRoomId)?.name}</Text>
|
||||
</Button>
|
||||
)}
|
||||
{isForwardError && (
|
||||
<Text size="T300" color="Critical600" style={{ margin: config.space.S300 }}>
|
||||
Failed to forward message. Please try again.
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageForwardItemProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose?: () => void;
|
||||
};
|
||||
@@ -1,5 +1,24 @@
|
||||
import { ReactNode, useEffect, useState } from 'react';
|
||||
import { Box, Chip, Icon, IconButton, Icons, Text, Tooltip, color, config, toRem } from 'folds';
|
||||
import { ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Chip,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Scroll,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
color,
|
||||
config,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { getReactCustomHtmlParser, LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { RenderBody } from '$components/message';
|
||||
import { UploadStatus, UploadSuccess, useBindUploadAtom } from '$state/upload';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { TUploadContent } from '$utils/matrix';
|
||||
@@ -102,6 +121,7 @@ type UploadCardRendererProps = {
|
||||
setDesc: (fileItem: TUploadItem, body: string, formatted_body: string) => void;
|
||||
onRemove: (file: TUploadContent) => void;
|
||||
onComplete?: (upload: UploadSuccess) => void;
|
||||
roomId: string;
|
||||
};
|
||||
export function UploadCardRenderer({
|
||||
isEncrypted,
|
||||
@@ -110,6 +130,7 @@ export function UploadCardRenderer({
|
||||
setDesc,
|
||||
onRemove,
|
||||
onComplete,
|
||||
roomId,
|
||||
}: UploadCardRendererProps) {
|
||||
const mx = useMatrixClient();
|
||||
const mediaConfig = useMediaConfig();
|
||||
@@ -141,6 +162,20 @@ export function UploadCardRenderer({
|
||||
onComplete?.(upload);
|
||||
}
|
||||
}, [upload, onComplete]);
|
||||
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(() => ({ ...LINKIFY_OPTS }), []);
|
||||
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, roomId, {
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[linkifyOpts, mx, roomId, spoilerClickHandler, useAuthentication]
|
||||
);
|
||||
return (
|
||||
<UploadCard
|
||||
radii="300"
|
||||
@@ -159,17 +194,35 @@ export function UploadCardRenderer({
|
||||
<Text size="B300">Retry</Text>
|
||||
</Chip>
|
||||
)}
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setIsDescribed(!isDescribed);
|
||||
}}
|
||||
aria-label="Add Upload Description"
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
size="300"
|
||||
>
|
||||
<Icon src={isDescribed ? Icons.ChevronBottom : Icons.ChevronTop} size="50" />
|
||||
</IconButton>
|
||||
{!isDescribed && (
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setIsDescribed(true);
|
||||
}}
|
||||
aria-label="Add Upload Description"
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
size="300"
|
||||
>
|
||||
<Icon src={Icons.Pencil} size="50" />
|
||||
</IconButton>
|
||||
)}
|
||||
{isDescribed && (
|
||||
<TooltipProvider
|
||||
delay={400}
|
||||
position="Top"
|
||||
style={{ textAlign: 'center' }}
|
||||
tooltip={
|
||||
<Tooltip>
|
||||
<Text size="H5">
|
||||
Don't forget to save your description before sending the message!
|
||||
</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(triggerRef) => <Icon ref={triggerRef} src={Icons.Info} size="50" />}
|
||||
</TooltipProvider>
|
||||
)}
|
||||
|
||||
<IconButton
|
||||
onClick={removeUpload}
|
||||
@@ -214,6 +267,7 @@ export function UploadCardRenderer({
|
||||
</Text>
|
||||
</UploadCardError>
|
||||
)}
|
||||
|
||||
{isDescribed && (
|
||||
<DescriptionEditor
|
||||
value={fileItem.formatted_body || fileItem.body}
|
||||
@@ -221,25 +275,34 @@ export function UploadCardRenderer({
|
||||
setDesc(fileItem, plainText, htmlContent);
|
||||
setIsDescribed(false);
|
||||
}}
|
||||
onCancel={() => setIsDescribed(false)}
|
||||
/>
|
||||
)}
|
||||
{!isDescribed && fileItem.body && fileItem.body.length > 0 && (
|
||||
<Tooltip
|
||||
<Scroll
|
||||
direction="Vertical"
|
||||
variant="SurfaceVariant"
|
||||
visibility="Always"
|
||||
size="300"
|
||||
style={{
|
||||
maxHeight: toRem(105),
|
||||
overflow: 'scroll',
|
||||
backgroundColor: 'var(--sable-bg-container)',
|
||||
borderRadius: config.radii.R400,
|
||||
maxHeight: '180px',
|
||||
marginTop: config.space.S0,
|
||||
overflowY: 'auto',
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
size="T200"
|
||||
style={{
|
||||
height: '100%',
|
||||
wordBreak: 'break-word',
|
||||
}}
|
||||
>
|
||||
{fileItem.body}
|
||||
</Text>
|
||||
</Tooltip>
|
||||
<Box style={{ padding: config.space.S200, wordBreak: 'break-word' }}>
|
||||
<Text size="T200" priority="400" as="div">
|
||||
<RenderBody
|
||||
body={fileItem.body}
|
||||
customBody={fileItem.formatted_body}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
</Text>
|
||||
</Box>
|
||||
</Scroll>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ type DescriptionEditorProps = {
|
||||
isSaving?: boolean;
|
||||
imagePackRooms?: any[];
|
||||
onSave: (plaintext: string, htmlContent: string) => void;
|
||||
onCancel: () => void;
|
||||
};
|
||||
|
||||
export function DescriptionEditor({
|
||||
@@ -51,6 +52,7 @@ export function DescriptionEditor({
|
||||
isSaving,
|
||||
imagePackRooms,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: DescriptionEditorProps) {
|
||||
const editor = useEditor();
|
||||
const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline');
|
||||
@@ -129,6 +131,7 @@ export function DescriptionEditor({
|
||||
(evt) => {
|
||||
if (isKeyHotkey('escape', evt)) {
|
||||
evt.preventDefault();
|
||||
onCancel();
|
||||
return;
|
||||
}
|
||||
const prevWordRange = getPrevWorldRange(editor);
|
||||
@@ -137,7 +140,7 @@ export function DescriptionEditor({
|
||||
: undefined;
|
||||
setAutocompleteQuery(query);
|
||||
},
|
||||
[editor]
|
||||
[editor, onCancel]
|
||||
);
|
||||
|
||||
const handleCloseAutocomplete = useCallback(() => {
|
||||
@@ -180,18 +183,33 @@ export function DescriptionEditor({
|
||||
justifyContent="SpaceBetween"
|
||||
gap="100"
|
||||
>
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={handleSave}
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">{isSaving ? 'Saving' : 'Save'}</Text>
|
||||
</Chip>
|
||||
<Box gap="200">
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={handleSave}
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">{isSaving ? 'Saving' : 'Save'}</Text>
|
||||
</Chip>
|
||||
</Box>
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={onCancel}
|
||||
variant="Warning"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">Cancel</Text>
|
||||
</Chip>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box gap="Inherit">
|
||||
<IconButton
|
||||
|
||||
@@ -717,6 +717,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setMetadata={handleFileMetadata}
|
||||
onRemove={handleRemoveUpload}
|
||||
setDesc={setDesc}
|
||||
roomId={roomId}
|
||||
/>
|
||||
))}
|
||||
</UploadBoardContent>
|
||||
|
||||
@@ -132,7 +132,7 @@ import { useGetMemberPowerTag } from '$hooks/useMemberPowerTag';
|
||||
import { profilesCacheAtom } from '$state/userRoomProfile';
|
||||
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
|
||||
import * as css from './RoomTimeline.css';
|
||||
import { EncryptedContent, Event, Message, Reactions } from './message';
|
||||
import { EncryptedContent, Event, ForwardedMessageProps, Message, Reactions } from './message';
|
||||
|
||||
const TimelineFloat = as<'div', css.TimelineFloatVariants>(
|
||||
({ position, className, ...props }, ref) => (
|
||||
@@ -1338,6 +1338,29 @@ export function RoomTimeline({
|
||||
const senderDisplayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
|
||||
// determine if message is forwarded by checking for the presence of the 'moe.sable.message.forward' key in the event content
|
||||
const forwardContent = safeContent['moe.sable.message.forward'] as
|
||||
| {
|
||||
original_timestamp?: unknown;
|
||||
original_room_id?: string;
|
||||
original_event_id?: string;
|
||||
original_event_private?: boolean;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
const messageForwardedProps: ForwardedMessageProps | undefined = forwardContent
|
||||
? {
|
||||
isForwarded: true,
|
||||
originalTimestamp:
|
||||
typeof forwardContent.original_timestamp === 'number'
|
||||
? forwardContent.original_timestamp
|
||||
: mEvent.getTs(),
|
||||
originalRoomId: forwardContent.original_room_id ?? room.roomId,
|
||||
originalEventId: forwardContent.original_event_id ?? '',
|
||||
originalEventPrivate: forwardContent.original_event_private ?? false,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<Message
|
||||
key={mEvent.getId()}
|
||||
@@ -1361,6 +1384,7 @@ export function RoomTimeline({
|
||||
onReactionToggle={handleReactionToggle}
|
||||
senderId={senderId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
messageForwardedProps={messageForwardedProps}
|
||||
sendStatus={mEvent.getAssociatedStatus()}
|
||||
onResend={handleResend}
|
||||
onDeleteFailedSend={handleDeleteFailedSend}
|
||||
|
||||
@@ -75,9 +75,11 @@ import { useBlobCache } from '$hooks/useBlobCache';
|
||||
import { MessageAllReactionItem } from '$components/message/modals/MessageReactions';
|
||||
import { MessageReadReceiptItem } from '$components/message/modals/MessageReadRecipts';
|
||||
import { MessageSourceCodeItem } from '$components/message/modals/MessageSource';
|
||||
import { MessageForwardItem } from '$components/message/modals/MessageForward';
|
||||
import { MessageDeleteItem } from '$components/message/modals/MessageDelete';
|
||||
import { MessageReportItem } from '$components/message/modals/MessageReport';
|
||||
import { filterPronounsByLanguage } from '$utils/pronouns';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { MessageEditor } from './MessageEditor';
|
||||
import * as css from './styles.css';
|
||||
|
||||
@@ -155,6 +157,7 @@ export const MessageCopyLinkItem = as<
|
||||
);
|
||||
});
|
||||
|
||||
// message pinning
|
||||
export const MessagePinItem = as<
|
||||
'button',
|
||||
{
|
||||
@@ -195,6 +198,14 @@ export const MessagePinItem = as<
|
||||
);
|
||||
});
|
||||
|
||||
export type ForwardedMessageProps = {
|
||||
originalTimestamp: number;
|
||||
isForwarded: boolean;
|
||||
originalRoomId: string;
|
||||
originalEventId: string;
|
||||
originalEventPrivate: boolean;
|
||||
};
|
||||
|
||||
export type MessageProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
@@ -230,6 +241,7 @@ export type MessageProps = {
|
||||
sendStatus?: EventStatus | null;
|
||||
onResend?: (event: MatrixEvent) => void;
|
||||
onDeleteFailedSend?: (event: MatrixEvent) => void;
|
||||
messageForwardedProps?: ForwardedMessageProps;
|
||||
};
|
||||
|
||||
function useMobileDoubleTap(callback: () => void, delay = 300) {
|
||||
@@ -329,6 +341,7 @@ function MessageInternal(
|
||||
sendStatus,
|
||||
onResend,
|
||||
onDeleteFailedSend,
|
||||
messageForwardedProps,
|
||||
...props
|
||||
}: MessageProps & { className?: string; children?: ReactNode },
|
||||
ref: any
|
||||
@@ -469,6 +482,8 @@ function MessageInternal(
|
||||
const isFailedSend = sendStatus === EventStatus.NOT_SENT;
|
||||
const canResend = isFailedSend && senderId === mx.getUserId() && !!onResend;
|
||||
const canDeleteFailedSend = isFailedSend && senderId === mx.getUserId() && !!onDeleteFailedSend;
|
||||
// handle clicks on mentions in the message body (e.g. jump to original message from a forwarded message notice)
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
|
||||
const handleResendClick: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
(evt) => {
|
||||
@@ -500,6 +515,35 @@ function MessageInternal(
|
||||
[css.MessageFailed]: isFailedSend,
|
||||
})}
|
||||
>
|
||||
{messageForwardedProps?.isForwarded && (
|
||||
<Chip as="div" variant="SurfaceVariant" radii="Pill">
|
||||
<Text size="T200" priority="300">
|
||||
Forwarded{' '}
|
||||
{messageForwardedProps.originalEventPrivate ? 'private message' : 'from another room'}{' '}
|
||||
{!messageForwardedProps.originalEventPrivate && (
|
||||
<a
|
||||
href={getMatrixToRoomEvent(
|
||||
messageForwardedProps.originalRoomId,
|
||||
messageForwardedProps.originalEventId
|
||||
)}
|
||||
rel="noreferrer noopener"
|
||||
data-mention-id={messageForwardedProps.originalRoomId}
|
||||
data-mention-event-id={messageForwardedProps.originalEventId}
|
||||
onClick={mentionClickHandler}
|
||||
>
|
||||
jump to original
|
||||
</a>
|
||||
)}
|
||||
<Time
|
||||
ts={messageForwardedProps?.originalTimestamp ?? 0}
|
||||
compact={messageLayout === MessageLayout.Compact}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
style={{ marginLeft: config.space.S100, justifyContent: 'flex-end' }}
|
||||
/>
|
||||
</Text>
|
||||
</Chip>
|
||||
)}
|
||||
{reply}
|
||||
{edit && onEditId ? (
|
||||
<MessageEditor
|
||||
@@ -812,6 +856,7 @@ function MessageInternal(
|
||||
<MessageSourceCodeItem room={room} mEvent={mEvent} />
|
||||
)}
|
||||
<MessageCopyLinkItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
<MessageForwardItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
{canPinEvent && (
|
||||
<MessagePinItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
)}
|
||||
@@ -1105,6 +1150,7 @@ export const Event = as<'div', EventProps>(
|
||||
<MessageSourceCodeItem room={room} mEvent={mEvent} />
|
||||
)}
|
||||
<MessageCopyLinkItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
<MessageForwardItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
</Box>
|
||||
{((!mEvent.isRedacted() && canDelete && !stateEvent) ||
|
||||
(mEvent.getSender() !== mx.getUserId() && !stateEvent)) && (
|
||||
|
||||
@@ -172,7 +172,6 @@ function IdentityCosmetics() {
|
||||
const [renderRoomColors, setRenderRoomColors] = useSetting(settingsAtom, 'renderRoomColors');
|
||||
const [renderRoomFonts, setRenderRoomFonts] = useSetting(settingsAtom, 'renderRoomFonts');
|
||||
const [uniformIcons, setUniformIcons] = useSetting(settingsAtom, 'uniformIcons');
|
||||
const [rightBubbles, setRightBubbles] = useSetting(settingsAtom, 'useRightBubbles');
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
@@ -229,13 +228,6 @@ function IdentityCosmetics() {
|
||||
after={<Switch variant="Primary" value={uniformIcons} onChange={setUniformIcons} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Aligned Bubbles"
|
||||
description="When using bubble layout, have your bubbles right aligned."
|
||||
after={<Switch variant="Primary" value={rightBubbles} onChange={setRightBubbles} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
MessageLayout,
|
||||
MessageSpacing,
|
||||
RightSwipeAction,
|
||||
CaptionPosition,
|
||||
settingsAtom,
|
||||
} from '$state/settings';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
@@ -42,6 +43,7 @@ import { KeySymbol } from '$utils/key-symbol';
|
||||
import { isMacOS, mobileOrTablet } from '$utils/user-agent';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useMessageLayoutItems } from '$hooks/useMessageLayout';
|
||||
import { useCaptionPositionItems } from '$hooks/useCaptionPosition';
|
||||
import { useMessageSpacingItems } from '$hooks/useMessageSpacing';
|
||||
import { useDateFormatItems } from '$hooks/useDateFormat';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
@@ -523,6 +525,74 @@ function SelectMessageLayout() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
function SelectCaptionPosition() {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
const [captionPosition, setCaptionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const captionPositionItems = useCaptionPositionItems();
|
||||
|
||||
const handleMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setMenuCords(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
const handleSelect = (position: CaptionPosition) => {
|
||||
setCaptionPosition(position);
|
||||
setMenuCords(undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
outlined
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
after={<Icon size="300" src={Icons.ChevronBottom} />}
|
||||
onClick={handleMenu}
|
||||
>
|
||||
<Text size="T300">
|
||||
{captionPositionItems.find((i) => i.layout === captionPosition)?.name ?? captionPosition}
|
||||
</Text>
|
||||
</Button>
|
||||
<PopOut
|
||||
anchor={menuCords}
|
||||
offset={5}
|
||||
position="Bottom"
|
||||
align="End"
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => setMenuCords(undefined),
|
||||
clickOutsideDeactivates: true,
|
||||
isKeyForward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowDown' || evt.key === 'ArrowRight',
|
||||
isKeyBackward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowUp' || evt.key === 'ArrowLeft',
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu>
|
||||
<Box direction="Column" gap="100" style={{ padding: config.space.S100 }}>
|
||||
{captionPositionItems.map((item) => (
|
||||
<MenuItem
|
||||
key={item.layout}
|
||||
size="300"
|
||||
variant={captionPosition === item.layout ? 'Primary' : 'Surface'}
|
||||
radii="300"
|
||||
onClick={() => handleSelect(item.layout)}
|
||||
>
|
||||
<Text size="T300">{item.name}</Text>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Box>
|
||||
</Menu>
|
||||
</FocusTrap>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectMessageSpacing() {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
@@ -753,6 +823,8 @@ function Messages() {
|
||||
'hideMembershipInReadOnly'
|
||||
);
|
||||
|
||||
const [messageLayout] = useSetting(settingsAtom, 'messageLayout');
|
||||
const [rightBubbles, setRightBubbles] = useSetting(settingsAtom, 'useRightBubbles');
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Messages</Text>
|
||||
@@ -762,12 +834,24 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Message Spacing" after={<SelectMessageSpacing />} />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="File description placement" after={<SelectCaptionPosition />} />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Emoji Selector Character Threshold"
|
||||
after={<EmojiSelectorThresholdInput />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
{messageLayout === MessageLayout.Bubble && (
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Aligned Bubbles"
|
||||
description="While using bubble layout, have your bubbles right aligned."
|
||||
after={<Switch variant="Primary" value={rightBubbles} onChange={setRightBubbles} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
)}
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Membership Change"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useMemo } from 'react';
|
||||
import { CaptionPosition } from '$state/settings';
|
||||
|
||||
export type MessageLayoutItem = {
|
||||
name: string;
|
||||
layout: CaptionPosition;
|
||||
};
|
||||
|
||||
export const useCaptionPositionItems = (): MessageLayoutItem[] =>
|
||||
useMemo(
|
||||
() => [
|
||||
{
|
||||
layout: CaptionPosition.Above,
|
||||
name: 'Above',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Inline,
|
||||
name: 'Inline',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Hidden,
|
||||
name: 'Hidden',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Below,
|
||||
name: 'Below',
|
||||
},
|
||||
],
|
||||
[]
|
||||
);
|
||||
@@ -3,6 +3,8 @@ import { MatrixEvent, Room, Relations } from '$types/matrix-sdk';
|
||||
|
||||
export enum ModalType {
|
||||
Delete = 'delete',
|
||||
// for forwarding a message to another room, not to be confused with the "share" action which is for sharing a message to another app
|
||||
Forward = 'forward',
|
||||
Report = 'report',
|
||||
Source = 'source',
|
||||
Reactions = 'reactions',
|
||||
@@ -11,6 +13,7 @@ export enum ModalType {
|
||||
|
||||
export type ModalState =
|
||||
| { type: ModalType.Delete; room: Room; mEvent: MatrixEvent }
|
||||
| { type: ModalType.Forward; room: Room; mEvent: MatrixEvent }
|
||||
| { type: ModalType.Report; room: Room; mEvent: MatrixEvent }
|
||||
| { type: ModalType.Source; room: Room; mEvent: MatrixEvent }
|
||||
| { type: ModalType.Reactions; room: Room; relations: Relations }
|
||||
|
||||
@@ -15,6 +15,12 @@ export enum RightSwipeAction {
|
||||
Reply = 'reply',
|
||||
}
|
||||
|
||||
export enum CaptionPosition {
|
||||
Above = 'above',
|
||||
Inline = 'inline',
|
||||
Hidden = 'hidden',
|
||||
Below = 'below',
|
||||
}
|
||||
export type JumboEmojiSize = 'none' | 'extraSmall' | 'small' | 'normal' | 'large' | 'extraLarge';
|
||||
|
||||
export interface Settings {
|
||||
@@ -69,6 +75,7 @@ export interface Settings {
|
||||
filterPronounsLanguages?: string[];
|
||||
renderRoomColors: boolean;
|
||||
renderRoomFonts: boolean;
|
||||
captionPosition: CaptionPosition;
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: boolean;
|
||||
@@ -143,6 +150,7 @@ const defaultSettings: Settings = {
|
||||
renderGlobalNameColors: true,
|
||||
renderRoomColors: true,
|
||||
renderRoomFonts: true,
|
||||
captionPosition: CaptionPosition.Below,
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: true,
|
||||
|
||||
@@ -10,6 +10,8 @@ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfil
|
||||
import inject from '@rollup/plugin-inject';
|
||||
import topLevelAwait from 'vite-plugin-top-level-await';
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
import { compression, defineAlgorithm } from 'vite-plugin-compression2';
|
||||
import { constants as zlibConstants } from 'zlib';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { cloudflare } from '@cloudflare/vite-plugin';
|
||||
@@ -183,6 +185,14 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
}),
|
||||
compression({
|
||||
algorithms: [
|
||||
defineAlgorithm('brotliCompress', {
|
||||
params: { [zlibConstants.BROTLI_PARAM_QUALITY]: zlibConstants.BROTLI_MAX_QUALITY },
|
||||
}),
|
||||
],
|
||||
include: /\.(html|xml|css|json|js|mjs|svg|yaml|yml|toml|wasm|txt|map)$/,
|
||||
}),
|
||||
],
|
||||
optimizeDeps: {
|
||||
// Rebuild dep optimizer cache on each dev start to avoid stale API shapes.
|
||||
|
||||
Reference in new issue
Block a user