2026-05-23 23:01:13 -04:00
|
|
|
import React, { ChangeEvent, useCallback, useState } from 'react';
|
2026-05-15 13:37:03 -04:00
|
|
|
import FocusTrap from 'focus-trap-react';
|
|
|
|
|
import {
|
2026-05-23 23:01:13 -04:00
|
|
|
Avatar,
|
2026-05-15 13:37:03 -04:00
|
|
|
Box,
|
|
|
|
|
config,
|
|
|
|
|
Input,
|
|
|
|
|
Line,
|
|
|
|
|
MenuItem,
|
|
|
|
|
Modal,
|
|
|
|
|
Overlay,
|
|
|
|
|
OverlayBackdrop,
|
|
|
|
|
OverlayCenter,
|
|
|
|
|
Scroll,
|
2026-05-23 23:01:13 -04:00
|
|
|
Spinner,
|
2026-05-15 13:37:03 -04:00
|
|
|
Text,
|
|
|
|
|
} from 'folds';
|
2026-05-23 23:01:13 -04:00
|
|
|
import { MatrixEvent, Room } from 'matrix-js-sdk';
|
|
|
|
|
import { useAtomValue } from 'jotai';
|
2026-05-15 13:37:03 -04:00
|
|
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
|
|
|
|
import { stopPropagation } from '../../../utils/keyboard';
|
2026-05-23 23:01:13 -04:00
|
|
|
import { mDirectAtom } from '../../../state/mDirectList';
|
|
|
|
|
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
|
|
|
|
import { mxcUrlToHttp } from '../../../utils/matrix';
|
|
|
|
|
import { RoomAvatar, RoomIcon } from '../../../components/room-avatar';
|
|
|
|
|
|
|
|
|
|
type RoomRowProps = {
|
|
|
|
|
room: Room;
|
|
|
|
|
dm: boolean;
|
|
|
|
|
useAuthentication: boolean;
|
|
|
|
|
onClick: () => void;
|
|
|
|
|
sending: boolean;
|
|
|
|
|
};
|
|
|
|
|
function RoomRow({ room, dm, useAuthentication, onClick, sending }: RoomRowProps) {
|
|
|
|
|
const mx = useMatrixClient();
|
|
|
|
|
const avatarMxc = room.getMxcAvatarUrl();
|
|
|
|
|
const avatarUrl = avatarMxc
|
|
|
|
|
? (mxcUrlToHttp(mx, avatarMxc, useAuthentication, 48, 48, 'crop') ?? undefined)
|
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<MenuItem
|
|
|
|
|
size="300"
|
|
|
|
|
radii="300"
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
disabled={sending}
|
|
|
|
|
before={
|
|
|
|
|
<Avatar size="200" radii="300">
|
|
|
|
|
<RoomAvatar
|
|
|
|
|
roomId={room.roomId}
|
|
|
|
|
src={avatarUrl}
|
|
|
|
|
alt={room.name}
|
|
|
|
|
renderFallback={() => (
|
2026-05-23 23:22:49 -04:00
|
|
|
<RoomIcon roomType={room.getType()} size="100" joinRule={room.getJoinRule()} filled />
|
2026-05-23 23:01:13 -04:00
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Avatar>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Box direction="Column">
|
|
|
|
|
<Text size="T300" truncate>
|
|
|
|
|
{room.name}
|
|
|
|
|
</Text>
|
|
|
|
|
{dm && (
|
|
|
|
|
<Text size="T200" priority="300" truncate>
|
|
|
|
|
Direct Message
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</MenuItem>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-15 13:37:03 -04:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
mEvent: MatrixEvent;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
|
|
|
|
const mx = useMatrixClient();
|
2026-05-23 23:01:13 -04:00
|
|
|
const directs = useAtomValue(mDirectAtom);
|
|
|
|
|
const useAuthentication = useMediaAuthentication();
|
2026-05-15 13:37:03 -04:00
|
|
|
const [query, setQuery] = useState('');
|
2026-05-23 23:01:13 -04:00
|
|
|
const [sending, setSending] = useState(false);
|
2026-05-15 13:37:03 -04:00
|
|
|
const [sentTo, setSentTo] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
const allRooms = mx
|
|
|
|
|
.getRooms()
|
|
|
|
|
.filter((r) => r.getMyMembership() === 'join' && !r.isSpaceRoom())
|
|
|
|
|
.sort((a, b) => (b.getLastActiveTimestamp() ?? 0) - (a.getLastActiveTimestamp() ?? 0));
|
|
|
|
|
|
|
|
|
|
const filtered = query
|
|
|
|
|
? allRooms.filter((r) => r.name.toLowerCase().includes(query.toLowerCase()))
|
|
|
|
|
: allRooms;
|
|
|
|
|
|
2026-05-23 23:01:13 -04:00
|
|
|
const forward = useCallback(
|
|
|
|
|
async (room: Room) => {
|
|
|
|
|
if (sending) return;
|
|
|
|
|
setSending(true);
|
|
|
|
|
const fwdContent: Record<string, unknown> = { ...mEvent.getContent() };
|
|
|
|
|
delete fwdContent['m.relates_to'];
|
|
|
|
|
try {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
await (mx as any).sendEvent(room.roomId, mEvent.getType(), fwdContent);
|
|
|
|
|
setSentTo(room.name);
|
|
|
|
|
setTimeout(onClose, 1400);
|
|
|
|
|
} catch {
|
|
|
|
|
setSending(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[mx, mEvent, onClose, sending],
|
|
|
|
|
);
|
2026-05-15 13:37:03 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Overlay open backdrop={<OverlayBackdrop />}>
|
|
|
|
|
<OverlayCenter>
|
|
|
|
|
<FocusTrap
|
|
|
|
|
focusTrapOptions={{
|
|
|
|
|
initialFocus: false,
|
|
|
|
|
onDeactivate: onClose,
|
|
|
|
|
clickOutsideDeactivates: true,
|
|
|
|
|
escapeDeactivates: stopPropagation,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Modal
|
|
|
|
|
size="400"
|
2026-05-21 20:49:33 -04:00
|
|
|
style={{
|
2026-05-23 23:01:13 -04:00
|
|
|
maxHeight: '480px',
|
2026-05-21 20:49:33 -04:00
|
|
|
borderRadius: config.radii.R500,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
}}
|
2026-05-15 13:37:03 -04:00
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
direction="Column"
|
|
|
|
|
gap="200"
|
|
|
|
|
shrink="No"
|
|
|
|
|
style={{ padding: config.space.S400, paddingBottom: config.space.S200 }}
|
|
|
|
|
>
|
|
|
|
|
<Text size="H5">Forward message</Text>
|
2026-05-23 23:01:13 -04:00
|
|
|
{!sentTo && (
|
|
|
|
|
<Input
|
|
|
|
|
variant="Background"
|
|
|
|
|
size="400"
|
|
|
|
|
radii="400"
|
|
|
|
|
outlined
|
|
|
|
|
placeholder="Search rooms…"
|
|
|
|
|
value={query}
|
|
|
|
|
onChange={(e: ChangeEvent<HTMLInputElement>) => setQuery(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-05-15 13:37:03 -04:00
|
|
|
</Box>
|
|
|
|
|
<Line size="300" />
|
|
|
|
|
{sentTo ? (
|
|
|
|
|
<Box
|
|
|
|
|
grow="Yes"
|
|
|
|
|
alignItems="Center"
|
|
|
|
|
justifyContent="Center"
|
2026-05-23 23:01:13 -04:00
|
|
|
gap="300"
|
2026-05-15 13:37:03 -04:00
|
|
|
style={{ padding: config.space.S400 }}
|
|
|
|
|
>
|
|
|
|
|
<Text size="T300">✓ Forwarded to {sentTo}</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
) : (
|
|
|
|
|
<Box grow="Yes" style={{ minHeight: 0 }}>
|
|
|
|
|
<Scroll size="300" hideTrack visibility="Hover">
|
2026-05-21 20:49:33 -04:00
|
|
|
<Box direction="Column" gap="100" style={{ padding: config.space.S200 }}>
|
2026-05-15 13:37:03 -04:00
|
|
|
{filtered.slice(0, 60).map((room) => (
|
2026-05-23 23:01:13 -04:00
|
|
|
<RoomRow
|
2026-05-15 13:37:03 -04:00
|
|
|
key={room.roomId}
|
2026-05-23 23:01:13 -04:00
|
|
|
room={room}
|
|
|
|
|
dm={directs.has(room.roomId)}
|
|
|
|
|
useAuthentication={useAuthentication}
|
|
|
|
|
onClick={() => forward(room)}
|
|
|
|
|
sending={sending}
|
|
|
|
|
/>
|
2026-05-15 13:37:03 -04:00
|
|
|
))}
|
|
|
|
|
{filtered.length === 0 && (
|
|
|
|
|
<Box
|
|
|
|
|
alignItems="Center"
|
|
|
|
|
justifyContent="Center"
|
|
|
|
|
style={{ padding: config.space.S400 }}
|
|
|
|
|
>
|
|
|
|
|
<Text size="T300" priority="300">
|
|
|
|
|
No rooms found
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Scroll>
|
2026-05-23 23:01:13 -04:00
|
|
|
{sending && (
|
|
|
|
|
<Box
|
|
|
|
|
alignItems="Center"
|
|
|
|
|
justifyContent="Center"
|
|
|
|
|
style={{
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
inset: 0,
|
|
|
|
|
background: 'rgba(0,0,0,0.18)',
|
|
|
|
|
borderRadius: config.radii.R500,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Spinner variant="Secondary" size="400" />
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2026-05-15 13:37:03 -04:00
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Modal>
|
|
|
|
|
</FocusTrap>
|
|
|
|
|
</OverlayCenter>
|
|
|
|
|
</Overlay>
|
|
|
|
|
);
|
|
|
|
|
}
|