Merge pull request #17 from 7w1/timeline-optimizations
Timeline optimizations
This commit is contained in:
20 files changed
+664
-636
No files matched your search
@@ -1,5 +1,13 @@
|
||||
# Sable Client Changelog
|
||||
|
||||
## Version 1.1.5
|
||||
|
||||
- Various performance improvements. See commits for details.
|
||||
- Fix typing indicator z index on mobile.
|
||||
- Fix room nicknames not displaying.
|
||||
- Fix rare crash with colorMXID [(#15)](https://github.com/7w1/sable/pull/15)
|
||||
- Fix crash from long pronoun pills [(#16)](https://github.com/7w1/sable/pull/16)
|
||||
|
||||
## Version 1.1.4
|
||||
|
||||
- Various performance improvements
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "sable",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sable",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@atlaskit/pragmatic-drag-and-drop": "1.1.6",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sable",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"description": "Yet another matrix client fork",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useMemo, useCallback } from 'react';
|
||||
import { MsgType } from 'matrix-js-sdk';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
@@ -30,7 +30,6 @@ import { ImageViewer } from './image-viewer';
|
||||
import { PdfViewer } from './Pdf-viewer';
|
||||
import { TextViewer } from './text-viewer';
|
||||
import { testMatrixTo } from '../plugins/matrix-to';
|
||||
import { IImageContent } from '../../types/matrix/common';
|
||||
|
||||
type RenderMessageContentProps = {
|
||||
displayName: string;
|
||||
@@ -46,7 +45,6 @@ type RenderMessageContentProps = {
|
||||
outlineAttachment?: boolean;
|
||||
};
|
||||
|
||||
// Checks for supported direct preview file types
|
||||
const getMediaType = (url: string) => {
|
||||
const cleanUrl = url.toLowerCase();
|
||||
if (cleanUrl.match(/\.(mp4|webm|ogg)$/i)) return 'video';
|
||||
@@ -57,7 +55,9 @@ const getMediaType = (url: string) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export function RenderMessageContent({
|
||||
const CAPTION_STYLE = { marginTop: config.space.S200 };
|
||||
|
||||
function RenderMessageContentInternal({
|
||||
displayName,
|
||||
msgType,
|
||||
ts,
|
||||
@@ -70,7 +70,18 @@ export function RenderMessageContent({
|
||||
linkifyOpts,
|
||||
outlineAttachment,
|
||||
}: RenderMessageContentProps) {
|
||||
const renderUrlsPreview = (urls: string[]) => {
|
||||
const content = useMemo(() => getContent<any>(), [getContent]);
|
||||
|
||||
const renderBody = useCallback((props: any) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
), [highlightRegex, htmlReactParserOptions, linkifyOpts]);
|
||||
|
||||
const renderUrlsPreview = useCallback((urls: string[]) => {
|
||||
const filteredUrls = urls.filter((url) => !testMatrixTo(url));
|
||||
if (filteredUrls.length === 0) return undefined;
|
||||
|
||||
@@ -80,10 +91,7 @@ export function RenderMessageContent({
|
||||
}));
|
||||
|
||||
const mediaLinks = analyzed.filter(item => item.type !== null);
|
||||
|
||||
const toRender = mediaLinks.length > 0
|
||||
? mediaLinks
|
||||
: [analyzed[0]];
|
||||
const toRender = mediaLinks.length > 0 ? mediaLinks : [analyzed[0]];
|
||||
|
||||
return (
|
||||
<UrlPreviewHolder>
|
||||
@@ -97,23 +105,16 @@ export function RenderMessageContent({
|
||||
))}
|
||||
</UrlPreviewHolder>
|
||||
);
|
||||
};
|
||||
}, [ts]);
|
||||
|
||||
const renderCaption = () => {
|
||||
const content: IImageContent = getContent();
|
||||
if (content.filename && content.filename !== content.body) {
|
||||
return (
|
||||
<MText
|
||||
style={{ marginTop: config.space.S200 }}
|
||||
style={CAPTION_STYLE}
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={(props) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
)}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
@@ -124,7 +125,7 @@ export function RenderMessageContent({
|
||||
const renderFile = () => (
|
||||
<>
|
||||
<MFile
|
||||
content={getContent()}
|
||||
content={content}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
@@ -161,15 +162,8 @@ export function RenderMessageContent({
|
||||
return (
|
||||
<MText
|
||||
edited={edited}
|
||||
content={getContent()}
|
||||
renderBody={(props) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
)}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
@@ -180,15 +174,8 @@ export function RenderMessageContent({
|
||||
<MEmote
|
||||
displayName={displayName}
|
||||
edited={edited}
|
||||
content={getContent()}
|
||||
renderBody={(props) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
)}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
@@ -198,15 +185,8 @@ export function RenderMessageContent({
|
||||
return (
|
||||
<MNotice
|
||||
edited={edited}
|
||||
content={getContent()}
|
||||
renderBody={(props) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
)}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
@@ -216,10 +196,10 @@ export function RenderMessageContent({
|
||||
return (
|
||||
<>
|
||||
<MImage
|
||||
content={getContent()}
|
||||
renderImageContent={(props) => (
|
||||
content={content}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...props}
|
||||
{...imageProps}
|
||||
autoPlay={mediaAutoLoad}
|
||||
renderImage={(p) => <Image {...p} loading="lazy" />}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
@@ -236,13 +216,13 @@ export function RenderMessageContent({
|
||||
return (
|
||||
<>
|
||||
<MVideo
|
||||
content={getContent()}
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...props }) => (
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
body={body}
|
||||
info={info}
|
||||
{...props}
|
||||
{...videoProps}
|
||||
renderThumbnail={
|
||||
mediaAutoLoad
|
||||
? () => (
|
||||
@@ -269,10 +249,10 @@ export function RenderMessageContent({
|
||||
return (
|
||||
<>
|
||||
<MAudio
|
||||
content={getContent()}
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(props) => (
|
||||
<AudioContent {...props} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
@@ -281,17 +261,11 @@ export function RenderMessageContent({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.File) {
|
||||
return renderFile();
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Location) {
|
||||
return <MLocation content={getContent()} />;
|
||||
}
|
||||
|
||||
if (msgType === 'm.bad.encrypted') {
|
||||
return <MBadEncrypted />;
|
||||
}
|
||||
if (msgType === MsgType.File) return renderFile();
|
||||
if (msgType === MsgType.Location) return <MLocation content={content} />;
|
||||
if (msgType === 'm.bad.encrypted') return <MBadEncrypted />;
|
||||
|
||||
return <UnsupportedContent />;
|
||||
}
|
||||
|
||||
export const RenderMessageContent = React.memo(RenderMessageContentInternal);
|
||||
@@ -1,41 +1,24 @@
|
||||
import { useMotionValue, useSpring, useTransform, motion } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { config, Icon, Icons } from 'folds';
|
||||
import { mobileOrTablet } from '../utils/user-agent';
|
||||
import { RightSwipeAction, settingsAtom } from '../state/settings';
|
||||
|
||||
export function SwipeableMessageWrapper({
|
||||
children,
|
||||
onReply
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
onReply: () => void;
|
||||
}) {
|
||||
const settings = useAtomValue(settingsAtom);
|
||||
function ActiveSwipeWrapper({ children, onReply }: { children: React.ReactNode; onReply: () => void }) {
|
||||
const x = useMotionValue(0);
|
||||
const springX = useSpring(x, { stiffness: 400, damping: 40 });
|
||||
const springX = useSpring(x, { stiffness: 300, damping: 35 });
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
|
||||
const iconOpacity = useTransform(x, [0, -8], [0, 1]);
|
||||
|
||||
const isSwipeToReplyEnabled =
|
||||
settings.mobileGestures &&
|
||||
mobileOrTablet() &&
|
||||
settings.rightSwipeAction !== RightSwipeAction.Members;
|
||||
|
||||
const bind = useDrag(({ active, movement: [mx] }) => {
|
||||
if (!isSwipeToReplyEnabled) return;
|
||||
|
||||
if (active) {
|
||||
const val = mx < 0 ? mx : 0;
|
||||
x.set(Math.max(-80, val));
|
||||
setIsReady(mx < -50);
|
||||
if (mx < -50 !== isReady) setIsReady(mx < -50);
|
||||
} else {
|
||||
if (mx < -50) {
|
||||
onReply();
|
||||
}
|
||||
if (mx < -50) onReply();
|
||||
x.set(0);
|
||||
setIsReady(false);
|
||||
}
|
||||
@@ -43,18 +26,12 @@ export function SwipeableMessageWrapper({
|
||||
axis: 'x',
|
||||
bounds: { right: 0 },
|
||||
rubberband: true,
|
||||
filterTaps: true
|
||||
filterTaps: true,
|
||||
eventOptions: { passive: true }
|
||||
});
|
||||
|
||||
if (!isSwipeToReplyEnabled) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
{...bind()}
|
||||
style={{ position: 'relative', touchAction: 'pan-y' }}
|
||||
>
|
||||
<div {...bind()} style={{ position: 'relative', touchAction: 'pan-y' }}>
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
@@ -76,10 +53,31 @@ export function SwipeableMessageWrapper({
|
||||
/>
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
<motion.div style={{ x: springX, position: 'relative', zIndex: 1 }}>
|
||||
{children}
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function SwipeableMessageWrapper({
|
||||
children,
|
||||
onReply
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
onReply: () => void;
|
||||
}) {
|
||||
const settings = useAtomValue(settingsAtom);
|
||||
|
||||
const isSwipeToReplyEnabled = useMemo(() =>
|
||||
settings.mobileGestures &&
|
||||
mobileOrTablet() &&
|
||||
settings.rightSwipeAction !== RightSwipeAction.Members,
|
||||
[settings.mobileGestures, settings.rightSwipeAction]);
|
||||
|
||||
if (!isSwipeToReplyEnabled) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return <ActiveSwipeWrapper onReply={onReply}>{children}</ActiveSwipeWrapper>;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { Overlay, OverlayBackdrop, OverlayCenter, Box } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { MessageReportInternal } from './MessageReport';
|
||||
import { MessageDeleteInternal } from './MessageDelete';
|
||||
import { MessageSourceInternal } from './MessageSource';
|
||||
import { MessageAllReactionInternal } from './MessageReactions';
|
||||
import { stopPropagation } from '../../../utils/keyboard';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
import { MessageReadReceiptInternal } from './MessageReadRecipts';
|
||||
|
||||
export function GlobalModalManager() {
|
||||
const [modal, setModal] = useAtom(modalAtom);
|
||||
|
||||
if (!modal) return null;
|
||||
|
||||
const close = () => setModal(null);
|
||||
|
||||
return (
|
||||
<Overlay open backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: close,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
{modal.type === ModalType.Report && (
|
||||
<MessageReportInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />
|
||||
)}
|
||||
{modal.type === ModalType.Delete && (
|
||||
<MessageDeleteInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />
|
||||
)}
|
||||
{modal.type === ModalType.Source && (
|
||||
<MessageSourceInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />
|
||||
)}
|
||||
{modal.type === ModalType.Reactions && (
|
||||
<MessageAllReactionInternal room={modal.room} relations={modal.relations} onClose={close} />
|
||||
)}
|
||||
{modal.type === ModalType.ReadReceipts && (
|
||||
<MessageReadReceiptInternal room={modal.room} eventId={modal.eventId} onClose={close} />
|
||||
)}
|
||||
</Box>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
import React, { useCallback, FormEventHandler } from 'react';
|
||||
import { Room, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import {
|
||||
Box, Dialog, Header, IconButton, Icon, Icons,
|
||||
Text, Input, Button, Spinner, MenuItem, config, color
|
||||
} from 'folds';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
import * as css from '../../../features/room/message/styles.css';
|
||||
|
||||
export function MessageDeleteItem({ room, mEvent }: { room: Room; mEvent: MatrixEvent }) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.Delete} />}
|
||||
radii="300"
|
||||
variant="Critical"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal({
|
||||
type: ModalType.Delete,
|
||||
room,
|
||||
mEvent
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Delete
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageDeleteInternalProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function MessageDeleteInternal({ room, mEvent, onClose }: MessageDeleteInternalProps) {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const [deleteState, deleteMessage] = useAsyncCallback(
|
||||
useCallback(
|
||||
(eventId: string, reason?: string) =>
|
||||
mx.redactEvent(room.roomId, eventId, undefined, reason ? { reason } : undefined),
|
||||
[mx, room]
|
||||
)
|
||||
);
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
const eventId = mEvent.getId();
|
||||
if (
|
||||
!eventId ||
|
||||
deleteState.status === AsyncStatus.Loading ||
|
||||
deleteState.status === AsyncStatus.Success
|
||||
)
|
||||
return;
|
||||
|
||||
const target = evt.target as HTMLFormElement | undefined;
|
||||
const reasonInput = target?.reasonInput as HTMLInputElement | undefined;
|
||||
const reason = reasonInput && reasonInput.value.trim();
|
||||
|
||||
deleteMessage(eventId, reason);
|
||||
};
|
||||
|
||||
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">Delete Message</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={onClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box
|
||||
as="form"
|
||||
onSubmit={handleSubmit}
|
||||
style={{ padding: config.space.S400 }}
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<Text priority="400">
|
||||
This action is irreversible! Are you sure that you want to delete this message?
|
||||
</Text>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">
|
||||
Reason{' '}
|
||||
<Text as="span" size="T200">
|
||||
(optional)
|
||||
</Text>
|
||||
</Text>
|
||||
<Input name="reasonInput" variant="Background" />
|
||||
{deleteState.status === AsyncStatus.Error && (
|
||||
<Text style={{ color: color.Critical.Main }} size="T300">
|
||||
Failed to delete message! Please try again.
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="Critical"
|
||||
before={
|
||||
deleteState.status === AsyncStatus.Loading ? (
|
||||
<Spinner fill="Solid" variant="Critical" size="200" />
|
||||
) : undefined
|
||||
}
|
||||
aria-disabled={deleteState.status === AsyncStatus.Loading}
|
||||
>
|
||||
<Text size="B400">
|
||||
{deleteState.status === AsyncStatus.Loading ? 'Deleting...' : 'Delete'}
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import {
|
||||
Icon, Icons, Text, MenuItem
|
||||
} from 'folds';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
import * as css from '../../../features/room/message/styles.css';
|
||||
import { ReactionViewer } from '../../../features/room/reaction-viewer';
|
||||
|
||||
|
||||
export function MessageAllReactionItem({ room, relations }: { room: Room; relations: Relations }) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.Smile} />}
|
||||
radii="300"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal({
|
||||
type: ModalType.Reactions,
|
||||
room,
|
||||
relations
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
View Reactions
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageAllReactionInternalProps = {
|
||||
room: Room;
|
||||
relations: Relations;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function MessageAllReactionInternal({ room, relations, onClose }: MessageAllReactionInternalProps) {
|
||||
return (
|
||||
<ReactionViewer
|
||||
room={room}
|
||||
relations={relations}
|
||||
requestClose={onClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { MenuItem, Icon, Icons, Text } from 'folds';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
import { EventReaders } from '../../../components/event-readers';
|
||||
import * as css from '../../../features/room/message/styles.css';
|
||||
|
||||
export function MessageReadReceiptItem({ room, eventId }: { room: Room; eventId: string }) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.CheckTwice} />}
|
||||
radii="300"
|
||||
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal({
|
||||
|
||||
type: ModalType.ReadReceipts,
|
||||
room,
|
||||
eventId
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Read Receipts
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageReadReceiptInternalProps = {
|
||||
room: Room;
|
||||
eventId: string;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function MessageReadReceiptInternal({ room, eventId, onClose }: MessageReadReceiptInternalProps) {
|
||||
return (
|
||||
<EventReaders
|
||||
room={room}
|
||||
eventId={eventId}
|
||||
requestClose={onClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import React, { useCallback, FormEventHandler } from 'react';
|
||||
import { Room, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import {
|
||||
Box, Dialog, Header, IconButton, Icon, Icons,
|
||||
Text, Input, Button, Spinner, MenuItem, config, color
|
||||
} from 'folds';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
import * as css from '../../../features/room/message/styles.css';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
|
||||
export function MessageReportItem({ room, mEvent }: { room: Room; mEvent: MatrixEvent }) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
variant="Critical"
|
||||
after={<Icon size="100" src={Icons.Warning} />}
|
||||
radii="300"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal({
|
||||
type: ModalType.Report,
|
||||
room,
|
||||
mEvent
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Report
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageReportInternalProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function MessageReportInternal({ room, mEvent, onClose }: MessageReportInternalProps) {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const [reportState, reportMessage] = useAsyncCallback(
|
||||
useCallback(
|
||||
(eventId: string, score: number, reason: string) =>
|
||||
mx.reportEvent(room.roomId, eventId, score, reason),
|
||||
[mx, room]
|
||||
)
|
||||
);
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
const eventId = mEvent.getId();
|
||||
if (
|
||||
!eventId ||
|
||||
reportState.status === AsyncStatus.Loading ||
|
||||
reportState.status === AsyncStatus.Success
|
||||
)
|
||||
return;
|
||||
|
||||
const target = evt.target as HTMLFormElement | undefined;
|
||||
const reasonInput = target?.reasonInput as HTMLInputElement | undefined;
|
||||
const reason = reasonInput && reasonInput.value.trim();
|
||||
|
||||
reportMessage(eventId, reason ? -100 : -50, reason || 'No reason provided');
|
||||
};
|
||||
|
||||
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">Report Message</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={onClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box
|
||||
as="form"
|
||||
onSubmit={handleSubmit}
|
||||
style={{ padding: config.space.S400 }}
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<Text priority="400">
|
||||
Report this message to the server, which may then notify the appropriate people to
|
||||
take action.
|
||||
</Text>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Reason</Text>
|
||||
<Input name="reasonInput" variant="Background" required />
|
||||
|
||||
{reportState.status === AsyncStatus.Error && (
|
||||
<Text style={{ color: color.Critical.Main }} size="T300">
|
||||
Failed to report message! Please try again.
|
||||
</Text>
|
||||
)}
|
||||
{reportState.status === AsyncStatus.Success && (
|
||||
<Text style={{ color: color.Success.Main }} size="T300">
|
||||
Message has been reported to server.
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="Critical"
|
||||
before={
|
||||
reportState.status === AsyncStatus.Loading ? (
|
||||
<Spinner fill="Solid" variant="Critical" size="200" />
|
||||
) : undefined
|
||||
}
|
||||
aria-disabled={
|
||||
reportState.status === AsyncStatus.Loading ||
|
||||
reportState.status === AsyncStatus.Success
|
||||
}
|
||||
>
|
||||
<Text size="B400">
|
||||
{reportState.status === AsyncStatus.Loading ? 'Reporting...' : 'Report'}
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import React from 'react';
|
||||
import { Room, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { MenuItem, Icon, Icons, Text } from 'folds';
|
||||
import { TextViewer } from '../../../components/text-viewer';
|
||||
import { getEventEdits } from '../../../utils/room';
|
||||
import { modalAtom, ModalType } from '../../../state/modal';
|
||||
import * as css from '../../../features/room/message/styles.css';
|
||||
|
||||
export function MessageSourceCodeItem({ room, mEvent }: { room: Room; mEvent: MatrixEvent }) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
|
||||
return (
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.BlockCode} />}
|
||||
radii="300"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setModal({
|
||||
type: ModalType.Source,
|
||||
room,
|
||||
mEvent
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
View Source
|
||||
</Text>
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
type MessageSourceInternalProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function MessageSourceInternal({ room, mEvent, onClose }: MessageSourceInternalProps) {
|
||||
const getContent = (evt: MatrixEvent) =>
|
||||
evt.isEncrypted()
|
||||
? {
|
||||
[`<== DECRYPTED_EVENT ==>`]: evt.getEffectiveEvent(),
|
||||
[`<== ORIGINAL_EVENT ==>`]: evt.event,
|
||||
}
|
||||
: evt.event;
|
||||
|
||||
const getText = (): string => {
|
||||
const evtId = mEvent.getId()!;
|
||||
const evtTimeline = room.getTimelineForEvent(evtId);
|
||||
const edits =
|
||||
evtTimeline &&
|
||||
getEventEdits(evtTimeline.getTimelineSet(), evtId, mEvent.getType())?.getRelations();
|
||||
|
||||
if (!edits) return JSON.stringify(getContent(mEvent), null, 2);
|
||||
|
||||
const content: Record<string, unknown> = {
|
||||
'<== MAIN_EVENT ==>': getContent(mEvent),
|
||||
};
|
||||
|
||||
edits.forEach((editEvt, index) => {
|
||||
content[`<== REPLACEMENT_EVENT_${index + 1} ==>`] = getContent(editEvt);
|
||||
});
|
||||
|
||||
return JSON.stringify(content, null, 2);
|
||||
};
|
||||
|
||||
return (
|
||||
<TextViewer
|
||||
name="Source Code"
|
||||
langName="json"
|
||||
text={getText()}
|
||||
requestClose={onClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -16,7 +16,6 @@ export const TypingDot = recipe({
|
||||
display: 'inline-block',
|
||||
backgroundColor: 'currentColor',
|
||||
borderRadius: '50%',
|
||||
zIndex: 10,
|
||||
transform: 'translateY(15%)',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -13,7 +13,11 @@ export const TypingIndicator = as<'div', TypingIndicatorProps>(
|
||||
as="span"
|
||||
alignItems="Center"
|
||||
shrink="No"
|
||||
style={{ gap: toRem(size === '300' ? 1 : 2), ...style }}
|
||||
style={{
|
||||
gap: toRem(size === '300' ? 1 : 2),
|
||||
zIndex: 10,
|
||||
...style
|
||||
}}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
|
||||
@@ -1141,6 +1141,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
onReplyClick={handleReplyClick}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
senderId={senderId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
onEditId={handleEdit}
|
||||
reply={
|
||||
replyEventId && (
|
||||
@@ -1197,6 +1198,9 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
const { replyEventId, threadRootId } = mEvent;
|
||||
const highlighted = focusItem?.index === item && focusItem.highlight;
|
||||
const senderId = mEvent.getSender() ?? '';
|
||||
const senderDisplayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
|
||||
|
||||
return (
|
||||
<Message
|
||||
@@ -1221,6 +1225,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
onReactionToggle={handleReactionToggle}
|
||||
onEditId={handleEdit}
|
||||
senderId={senderId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
reply={
|
||||
replyEventId && (
|
||||
<Reply
|
||||
@@ -1273,8 +1278,6 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
editedEvent?.getContent()['m.new_content'] ??
|
||||
mEvent.getContent()) as GetContentCallback;
|
||||
|
||||
const senderDisplayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
return (
|
||||
<RenderMessageContent
|
||||
displayName={senderDisplayName}
|
||||
@@ -1312,6 +1315,8 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
const hasReactions = reactions && reactions.length > 0;
|
||||
const highlighted = focusItem?.index === item && focusItem.highlight;
|
||||
const senderId = mEvent.getSender() ?? '';
|
||||
const senderDisplayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
|
||||
return (
|
||||
<Message
|
||||
@@ -1334,6 +1339,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
onReplyClick={handleReplyClick}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
senderId={senderId}
|
||||
senderDisplayName={senderDisplayName}
|
||||
reactions={
|
||||
reactionRelations && (
|
||||
<Reactions
|
||||
|
||||
@@ -27,6 +27,7 @@ import { BackRouteHandler } from '../../components/BackRouteHandler';
|
||||
import { useOpenRoomSettings } from '../../state/hooks/roomSettings';
|
||||
import { useSpaceOptionally } from '../../hooks/useSpace';
|
||||
import { RoomSettingsPage } from '../../state/roomSettings';
|
||||
import { GlobalModalManager } from '../../components/message/modals/GlobalModalManager';
|
||||
|
||||
const FN_KEYS_REGEX = /^F\d+$/;
|
||||
const shouldFocusMessageField = (evt: KeyboardEvent): boolean => {
|
||||
@@ -128,6 +129,7 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
|
||||
editor={editor}
|
||||
/>
|
||||
<RoomViewTyping room={room} />
|
||||
<GlobalModalManager />
|
||||
</Box>
|
||||
<Box shrink="No" direction="Column">
|
||||
<div style={{ padding: `0 ${config.space.S400}` }}>
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
import {
|
||||
Avatar,
|
||||
Box,
|
||||
Button,
|
||||
Dialog,
|
||||
Header,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Input,
|
||||
Line,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Modal,
|
||||
Overlay,
|
||||
OverlayBackdrop,
|
||||
OverlayCenter,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Spinner,
|
||||
Text,
|
||||
as,
|
||||
color,
|
||||
config,
|
||||
} from 'folds';
|
||||
import React, {
|
||||
FormEventHandler,
|
||||
MouseEventHandler,
|
||||
ReactNode,
|
||||
useCallback,
|
||||
@@ -38,7 +27,6 @@ import { useHover, useFocusWithin } from 'react-aria';
|
||||
import { MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
|
||||
import classNames from 'classnames';
|
||||
import parse from 'html-react-parser';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { RoomPinnedEventsEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import {
|
||||
@@ -53,13 +41,10 @@ import {
|
||||
} from '../../../components/message';
|
||||
import {
|
||||
canEditEvent,
|
||||
getEventEdits,
|
||||
getMemberAvatarMxc,
|
||||
getMemberDisplayName,
|
||||
} from '../../../utils/room';
|
||||
import {
|
||||
getCanonicalAliasOrRoomId,
|
||||
getMxIdLocalPart,
|
||||
isRoomAlias,
|
||||
mxcUrlToHttp,
|
||||
} from '../../../utils/matrix';
|
||||
@@ -68,11 +53,7 @@ import { nicknamesAtom, setNicknameAtom } from '../../../state/nicknames';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { useRecentEmoji } from '../../../hooks/useRecentEmoji';
|
||||
import * as css from './styles.css';
|
||||
import { EventReaders } from '../../../components/event-readers';
|
||||
import { TextViewer } from '../../../components/text-viewer';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
import { EmojiBoard } from '../../../components/emoji-board';
|
||||
import { ReactionViewer } from '../reaction-viewer';
|
||||
import { MessageEditor } from './MessageEditor';
|
||||
import { UserAvatar } from '../../../components/user-avatar';
|
||||
import { copyToClipboard } from '../../../utils/dom';
|
||||
@@ -90,6 +71,11 @@ import { mobileOrTablet } from '../../../utils/user-agent';
|
||||
import { useUserProfile } from '../../../hooks/useUserProfile';
|
||||
import { useSetting } from '../../../state/hooks/settings';
|
||||
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 { MessageDeleteItem } from '../../../components/message/modals/MessageDelete';
|
||||
import { MessageReportItem } from '../../../components/message/modals/MessageReport';
|
||||
|
||||
export type ReactionHandler = (keyOrMxc: string, shortcode: string) => void;
|
||||
|
||||
@@ -136,200 +122,6 @@ export const MessageQuickReactions = as<'div', MessageQuickReactionsProps>(
|
||||
}
|
||||
);
|
||||
|
||||
export const MessageAllReactionItem = as<
|
||||
'button',
|
||||
{
|
||||
room: Room;
|
||||
relations: Relations;
|
||||
onClose?: () => void;
|
||||
}
|
||||
>(({ room, relations, onClose, ...props }, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay
|
||||
onContextMenu={(evt: any) => {
|
||||
evt.stopPropagation();
|
||||
}}
|
||||
open={open}
|
||||
backdrop={<OverlayBackdrop />}
|
||||
>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
returnFocusOnDeactivate: false,
|
||||
onDeactivate: () => handleClose(),
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Modal variant="Surface" size="300">
|
||||
<ReactionViewer
|
||||
room={room}
|
||||
relations={relations}
|
||||
requestClose={() => setOpen(false)}
|
||||
/>
|
||||
</Modal>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.Smile} />}
|
||||
radii="300"
|
||||
onClick={() => setOpen(true)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
aria-pressed={open}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
View Reactions
|
||||
</Text>
|
||||
</MenuItem>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
export const MessageReadReceiptItem = as<
|
||||
'button',
|
||||
{
|
||||
room: Room;
|
||||
eventId: string;
|
||||
onClose?: () => void;
|
||||
}
|
||||
>(({ room, eventId, onClose, ...props }, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: handleClose,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Modal variant="Surface" size="300">
|
||||
<EventReaders room={room} eventId={eventId} requestClose={handleClose} />
|
||||
</Modal>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.CheckTwice} />}
|
||||
radii="300"
|
||||
onClick={() => setOpen(true)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
aria-pressed={open}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Read Receipts
|
||||
</Text>
|
||||
</MenuItem>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
export const MessageSourceCodeItem = as<
|
||||
'button',
|
||||
{
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose?: () => void;
|
||||
}
|
||||
>(({ room, mEvent, onClose, ...props }, ref) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const getContent = (evt: MatrixEvent) =>
|
||||
evt.isEncrypted()
|
||||
? {
|
||||
[`<== DECRYPTED_EVENT ==>`]: evt.getEffectiveEvent(),
|
||||
[`<== ORIGINAL_EVENT ==>`]: evt.event,
|
||||
}
|
||||
: evt.event;
|
||||
|
||||
const getText = (): string => {
|
||||
const evtId = mEvent.getId()!;
|
||||
const evtTimeline = room.getTimelineForEvent(evtId);
|
||||
const edits =
|
||||
evtTimeline &&
|
||||
getEventEdits(evtTimeline.getTimelineSet(), evtId, mEvent.getType())?.getRelations();
|
||||
|
||||
if (!edits) return JSON.stringify(getContent(mEvent), null, 2);
|
||||
|
||||
const content: Record<string, unknown> = {
|
||||
'<== MAIN_EVENT ==>': getContent(mEvent),
|
||||
};
|
||||
|
||||
edits.forEach((editEvt, index) => {
|
||||
content[`<== REPLACEMENT_EVENT_${index + 1} ==>`] = getContent(editEvt);
|
||||
});
|
||||
|
||||
return JSON.stringify(content, null, 2);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: handleClose,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Modal variant="Surface" size="500">
|
||||
<TextViewer
|
||||
name="Source Code"
|
||||
langName="json"
|
||||
text={getText()}
|
||||
requestClose={handleClose}
|
||||
/>
|
||||
</Modal>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.BlockCode} />}
|
||||
radii="300"
|
||||
onClick={() => setOpen(true)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
aria-pressed={open}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
View Source
|
||||
</Text>
|
||||
</MenuItem>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
export const MessageCopyLinkItem = as<
|
||||
'button',
|
||||
{
|
||||
@@ -405,269 +197,6 @@ export const MessagePinItem = as<
|
||||
);
|
||||
});
|
||||
|
||||
export const MessageDeleteItem = as<
|
||||
'button',
|
||||
{
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose?: () => void;
|
||||
}
|
||||
>(({ room, mEvent, onClose, ...props }, ref) => {
|
||||
const mx = useMatrixClient();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [deleteState, deleteMessage] = useAsyncCallback(
|
||||
useCallback(
|
||||
(eventId: string, reason?: string) =>
|
||||
mx.redactEvent(room.roomId, eventId, undefined, reason ? { reason } : undefined),
|
||||
[mx, room]
|
||||
)
|
||||
);
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
const eventId = mEvent.getId();
|
||||
if (
|
||||
!eventId ||
|
||||
deleteState.status === AsyncStatus.Loading ||
|
||||
deleteState.status === AsyncStatus.Success
|
||||
)
|
||||
return;
|
||||
const target = evt.target as HTMLFormElement | undefined;
|
||||
const reasonInput = target?.reasonInput as HTMLInputElement | undefined;
|
||||
const reason = reasonInput && reasonInput.value.trim();
|
||||
deleteMessage(eventId, reason);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: handleClose,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<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">Delete Message</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={handleClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box
|
||||
as="form"
|
||||
onSubmit={handleSubmit}
|
||||
style={{ padding: config.space.S400 }}
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<Text priority="400">
|
||||
This action is irreversible! Are you sure that you want to delete this message?
|
||||
</Text>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">
|
||||
Reason{' '}
|
||||
<Text as="span" size="T200">
|
||||
(optional)
|
||||
</Text>
|
||||
</Text>
|
||||
<Input name="reasonInput" variant="Background" />
|
||||
{deleteState.status === AsyncStatus.Error && (
|
||||
<Text style={{ color: color.Critical.Main }} size="T300">
|
||||
Failed to delete message! Please try again.
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="Critical"
|
||||
before={
|
||||
deleteState.status === AsyncStatus.Loading ? (
|
||||
<Spinner fill="Solid" variant="Critical" size="200" />
|
||||
) : undefined
|
||||
}
|
||||
aria-disabled={deleteState.status === AsyncStatus.Loading}
|
||||
>
|
||||
<Text size="B400">
|
||||
{deleteState.status === AsyncStatus.Loading ? 'Deleting...' : 'Delete'}
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
<Button
|
||||
variant="Critical"
|
||||
fill="None"
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.Delete} />}
|
||||
radii="300"
|
||||
onClick={() => setOpen(true)}
|
||||
aria-pressed={open}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Delete
|
||||
</Text>
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
export const MessageReportItem = as<
|
||||
'button',
|
||||
{
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
onClose?: () => void;
|
||||
}
|
||||
>(({ room, mEvent, onClose, ...props }, ref) => {
|
||||
const mx = useMatrixClient();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [reportState, reportMessage] = useAsyncCallback(
|
||||
useCallback(
|
||||
(eventId: string, score: number, reason: string) =>
|
||||
mx.reportEvent(room.roomId, eventId, score, reason),
|
||||
[mx, room]
|
||||
)
|
||||
);
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
const eventId = mEvent.getId();
|
||||
if (
|
||||
!eventId ||
|
||||
reportState.status === AsyncStatus.Loading ||
|
||||
reportState.status === AsyncStatus.Success
|
||||
)
|
||||
return;
|
||||
const target = evt.target as HTMLFormElement | undefined;
|
||||
const reasonInput = target?.reasonInput as HTMLInputElement | undefined;
|
||||
const reason = reasonInput && reasonInput.value.trim();
|
||||
if (reasonInput) reasonInput.value = '';
|
||||
reportMessage(eventId, reason ? -100 : -50, reason || 'No reason provided');
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: handleClose,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<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">Report Message</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={handleClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
<Box
|
||||
as="form"
|
||||
onSubmit={handleSubmit}
|
||||
style={{ padding: config.space.S400 }}
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<Text priority="400">
|
||||
Report this message to server, which may then notify the appropriate people to
|
||||
take action.
|
||||
</Text>
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Reason</Text>
|
||||
<Input name="reasonInput" variant="Background" required />
|
||||
{reportState.status === AsyncStatus.Error && (
|
||||
<Text style={{ color: color.Critical.Main }} size="T300">
|
||||
Failed to report message! Please try again.
|
||||
</Text>
|
||||
)}
|
||||
{reportState.status === AsyncStatus.Success && (
|
||||
<Text style={{ color: color.Success.Main }} size="T300">
|
||||
Message has been reported to server.
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="Critical"
|
||||
before={
|
||||
reportState.status === AsyncStatus.Loading ? (
|
||||
<Spinner fill="Solid" variant="Critical" size="200" />
|
||||
) : undefined
|
||||
}
|
||||
aria-disabled={
|
||||
reportState.status === AsyncStatus.Loading ||
|
||||
reportState.status === AsyncStatus.Success
|
||||
}
|
||||
>
|
||||
<Text size="B400">
|
||||
{reportState.status === AsyncStatus.Loading ? 'Reporting...' : 'Report'}
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
<Button
|
||||
variant="Critical"
|
||||
fill="None"
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.Warning} />}
|
||||
radii="300"
|
||||
onClick={() => setOpen(true)}
|
||||
aria-pressed={open}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<Text className={css.MessageMenuItemText} as="span" size="T300" truncate>
|
||||
Report
|
||||
</Text>
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
export type MessageProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
@@ -697,6 +226,7 @@ export type MessageProps = {
|
||||
hour24Clock: boolean;
|
||||
dateFormatString: string;
|
||||
senderId: string;
|
||||
senderDisplayName: string;
|
||||
content?: string;
|
||||
};
|
||||
|
||||
@@ -781,6 +311,7 @@ function MessageInternal(
|
||||
dateFormatString,
|
||||
children,
|
||||
senderId,
|
||||
senderDisplayName,
|
||||
...props
|
||||
}: MessageProps & { className?: string; children?: ReactNode },
|
||||
ref: any
|
||||
@@ -817,13 +348,6 @@ function MessageInternal(
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const setNickname = useSetAtom(setNicknameAtom);
|
||||
|
||||
const senderDisplayName =
|
||||
nicknames[senderId] ??
|
||||
profile.displayName ??
|
||||
getMemberDisplayName(room, senderId) ??
|
||||
getMxIdLocalPart(senderId) ??
|
||||
senderId;
|
||||
|
||||
const tagIconSrc = memberPowerTag?.icon
|
||||
? getPowerTagIconSrc(mx, useAuthentication, memberPowerTag.icon)
|
||||
: undefined;
|
||||
@@ -921,8 +445,10 @@ function MessageInternal(
|
||||
return mEvent.getContent().body || '';
|
||||
}, [mEvent]);
|
||||
|
||||
const MSG_CONTENT_STYLE = { maxWidth: '100%' };
|
||||
|
||||
const msgContentJSX = (
|
||||
<Box direction="Column" alignSelf="Start" style={{ maxWidth: '100%' }}>
|
||||
<Box direction="Column" alignSelf="Start" style={MSG_CONTENT_STYLE}>
|
||||
{reply}
|
||||
{edit && onEditId ? (
|
||||
<MessageEditor
|
||||
@@ -965,7 +491,11 @@ function MessageInternal(
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
const target = evt.currentTarget.parentElement?.parentElement ?? evt.currentTarget;
|
||||
setMenuAnchor(target.getBoundingClientRect());
|
||||
const rect = target.getBoundingClientRect();
|
||||
|
||||
window.requestAnimationFrame(() => {
|
||||
setMenuAnchor(rect);
|
||||
});
|
||||
};
|
||||
|
||||
const closeMenu = () => {
|
||||
@@ -1142,13 +672,7 @@ function MessageInternal(
|
||||
</Text>
|
||||
</MenuItem>
|
||||
)}
|
||||
{relations && (
|
||||
<MessageAllReactionItem
|
||||
room={room}
|
||||
relations={relations}
|
||||
onClose={closeMenu}
|
||||
/>
|
||||
)}
|
||||
{relations && <MessageAllReactionItem room={room} relations={relations} />}
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.ReplyArrow} />}
|
||||
@@ -1211,18 +735,10 @@ function MessageInternal(
|
||||
</MenuItem>
|
||||
)}
|
||||
{!hideReadReceipts && (
|
||||
<MessageReadReceiptItem
|
||||
room={room}
|
||||
eventId={mEvent.getId() ?? ''}
|
||||
onClose={closeMenu}
|
||||
/>
|
||||
<MessageReadReceiptItem room={room} eventId={mEvent.getId() ?? ''} />
|
||||
)}
|
||||
{showDeveloperTools && (
|
||||
<MessageSourceCodeItem
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
onClose={closeMenu}
|
||||
/>
|
||||
<MessageSourceCodeItem room={room} mEvent={mEvent} />
|
||||
)}
|
||||
<MessageCopyLinkItem room={room} mEvent={mEvent} onClose={closeMenu} />
|
||||
{canPinEvent && (
|
||||
@@ -1286,28 +802,25 @@ function MessageInternal(
|
||||
)
|
||||
)}
|
||||
</Box>
|
||||
{((!mEvent.isRedacted() && canDelete) ||
|
||||
mEvent.getSender() !== mx.getUserId()) && (
|
||||
<>
|
||||
<Line size="300" />
|
||||
<Box direction="Column" gap="100" className={css.MessageMenuGroup}>
|
||||
{!mEvent.isRedacted() && canDelete && (
|
||||
<MessageDeleteItem
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
onClose={closeMenu}
|
||||
/>
|
||||
)}
|
||||
{mEvent.getSender() !== mx.getUserId() && (
|
||||
<MessageReportItem
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
onClose={closeMenu}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
{((!mEvent.isRedacted() && canDelete) || mEvent.getSender() !== mx.getUserId()) && (
|
||||
<>
|
||||
<Line size="300" />
|
||||
<Box direction="Column" gap="100" className={css.MessageMenuGroup}>
|
||||
{!mEvent.isRedacted() && canDelete && (
|
||||
<MessageDeleteItem
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
/>
|
||||
)}
|
||||
{mEvent.getSender() !== mx.getUserId() && (
|
||||
<MessageReportItem
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</Menu>
|
||||
</FocusTrap>
|
||||
}
|
||||
@@ -1415,7 +928,11 @@ export const Event = as<'div', EventProps>(
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
const target = evt.currentTarget.parentElement?.parentElement ?? evt.currentTarget;
|
||||
setMenuAnchor(target.getBoundingClientRect());
|
||||
const rect = target.getBoundingClientRect();
|
||||
|
||||
window.requestAnimationFrame(() => {
|
||||
setMenuAnchor(rect);
|
||||
});
|
||||
};
|
||||
|
||||
const closeMenu = () => {
|
||||
|
||||
@@ -46,7 +46,7 @@ export function About({ requestClose }: AboutProps) {
|
||||
<Box direction="Column" gap="100">
|
||||
<Box gap="100" alignItems="End">
|
||||
<Text size="H3">Sable</Text>
|
||||
<Text size="T200">v1.1.4</Text>
|
||||
<Text size="T200">v1.1.5</Text>
|
||||
</Box>
|
||||
<Text>Yet another matrix client fork(ed from cinny).</Text>
|
||||
</Box>
|
||||
|
||||
@@ -15,7 +15,7 @@ export function AuthFooter() {
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
v1.1.4
|
||||
v1.1.5
|
||||
</Text>
|
||||
<Text as="a" size="T300" href="https://twitter.com/cinnyapp" target="_blank" rel="noreferrer">
|
||||
Twitter
|
||||
|
||||
@@ -24,7 +24,7 @@ export function WelcomePage() {
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
>
|
||||
v1.1.4
|
||||
v1.1.5
|
||||
</a>
|
||||
</span>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { atom } from 'jotai';
|
||||
import { MatrixEvent, Room } from 'matrix-js-sdk';
|
||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
|
||||
|
||||
export enum ModalType {
|
||||
Delete = 'delete',
|
||||
Report = 'report',
|
||||
Source = 'source',
|
||||
Reactions = 'reactions',
|
||||
ReadReceipts = 'read_receipts',
|
||||
}
|
||||
|
||||
export type ModalState =
|
||||
| { type: ModalType.Delete; 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 }
|
||||
| { type: ModalType.ReadReceipts; room: Room; eventId: string }
|
||||
| null;
|
||||
|
||||
export const modalAtom = atom<ModalState>(null);
|
||||
Reference in new issue
Block a user