2026-05-20 21:11:38 -04:00
|
|
|
import React, { useCallback, useMemo, useRef } from 'react';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { Box, Text, config } from 'folds';
|
2026-03-07 18:03:32 +11:00
|
|
|
import { EventType } from 'matrix-js-sdk';
|
2024-07-18 18:50:20 +05:30
|
|
|
import { ReactEditor } from 'slate-react';
|
|
|
|
|
import { isKeyHotkey } from 'is-hotkey';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { useStateEvent } from '../../hooks/useStateEvent';
|
|
|
|
|
import { StateEvent } from '../../../types/matrix/room';
|
2025-08-12 19:42:30 +05:30
|
|
|
import { usePowerLevelsContext } from '../../hooks/usePowerLevels';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
|
|
|
|
import { useEditor } from '../../components/editor';
|
|
|
|
|
import { RoomInputPlaceholder } from './RoomInputPlaceholder';
|
|
|
|
|
import { RoomTimeline } from './RoomTimeline';
|
|
|
|
|
import { RoomViewTyping } from './RoomViewTyping';
|
|
|
|
|
import { RoomTombstone } from './RoomTombstone';
|
|
|
|
|
import { RoomInput } from './RoomInput';
|
2025-02-26 21:44:53 +11:00
|
|
|
import { RoomViewFollowing, RoomViewFollowingPlaceholder } from './RoomViewFollowing';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { Page } from '../../components/page';
|
2026-05-13 21:17:59 -04:00
|
|
|
import { useSetting } from '../../state/hooks/settings';
|
2026-05-13 21:51:19 -04:00
|
|
|
import { settingsAtom } from '../../state/settings';
|
2026-06-15 01:02:46 -04:00
|
|
|
import { useTheme, ThemeKind } from '../../hooks/useTheme';
|
|
|
|
|
import { getChatBg } from '../lotus/chatBackground';
|
2024-07-18 18:50:20 +05:30
|
|
|
import { useKeyDown } from '../../hooks/useKeyDown';
|
|
|
|
|
import { editableActiveElement } from '../../utils/dom';
|
2025-08-12 19:42:30 +05:30
|
|
|
import { useRoomPermissions } from '../../hooks/useRoomPermissions';
|
|
|
|
|
import { useRoomCreators } from '../../hooks/useRoomCreators';
|
2026-03-07 18:03:32 +11:00
|
|
|
import { useRoom } from '../../hooks/useRoom';
|
2024-07-18 18:50:20 +05:30
|
|
|
|
2025-02-26 21:42:42 +11:00
|
|
|
const FN_KEYS_REGEX = /^F\d+$/;
|
2024-07-18 18:50:20 +05:30
|
|
|
const shouldFocusMessageField = (evt: KeyboardEvent): boolean => {
|
|
|
|
|
const { code } = evt;
|
|
|
|
|
if (evt.metaKey || evt.altKey || evt.ctrlKey) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-04 11:06:42 +05:30
|
|
|
|
2025-02-26 21:42:42 +11:00
|
|
|
if (FN_KEYS_REGEX.test(code)) return false;
|
2024-07-18 18:50:20 +05:30
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
code.startsWith('OS') ||
|
|
|
|
|
code.startsWith('Meta') ||
|
|
|
|
|
code.startsWith('Shift') ||
|
|
|
|
|
code.startsWith('Alt') ||
|
|
|
|
|
code.startsWith('Control') ||
|
|
|
|
|
code.startsWith('Arrow') ||
|
2024-08-04 11:06:42 +05:30
|
|
|
code.startsWith('Page') ||
|
|
|
|
|
code.startsWith('End') ||
|
|
|
|
|
code.startsWith('Home') ||
|
2024-07-18 18:50:20 +05:30
|
|
|
code === 'Tab' ||
|
|
|
|
|
code === 'Space' ||
|
|
|
|
|
code === 'Enter' ||
|
|
|
|
|
code === 'NumLock' ||
|
|
|
|
|
code === 'ScrollLock'
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2024-05-31 19:49:46 +05:30
|
|
|
|
2026-03-07 18:03:32 +11:00
|
|
|
export function RoomView({ eventId }: { eventId?: string }) {
|
2026-05-22 13:24:07 -04:00
|
|
|
const roomInputRef = useRef<HTMLDivElement>(null) as React.RefObject<HTMLDivElement>;
|
|
|
|
|
const roomViewRef = useRef<HTMLDivElement>(null) as React.RefObject<HTMLDivElement>;
|
2026-05-13 21:17:59 -04:00
|
|
|
const [chatBackground] = useSetting(settingsAtom, 'chatBackground');
|
2026-05-16 01:34:20 -04:00
|
|
|
const [lotusTerminal] = useSetting(settingsAtom, 'lotusTerminal');
|
2026-06-15 01:02:46 -04:00
|
|
|
const [pauseAnimations] = useSetting(settingsAtom, 'pauseAnimations');
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isDark = theme.kind === ThemeKind.Dark;
|
2024-05-31 19:49:46 +05:30
|
|
|
|
2025-02-26 21:44:53 +11:00
|
|
|
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
|
|
|
|
|
2026-03-07 18:03:32 +11:00
|
|
|
const room = useRoom();
|
2024-05-31 19:49:46 +05:30
|
|
|
const { roomId } = room;
|
|
|
|
|
const editor = useEditor();
|
|
|
|
|
|
|
|
|
|
const mx = useMatrixClient();
|
|
|
|
|
|
|
|
|
|
const tombstoneEvent = useStateEvent(room, StateEvent.RoomTombstone);
|
|
|
|
|
const powerLevels = usePowerLevelsContext();
|
2025-08-12 19:42:30 +05:30
|
|
|
const creators = useRoomCreators(room);
|
2024-05-31 19:49:46 +05:30
|
|
|
|
2025-08-12 19:42:30 +05:30
|
|
|
const permissions = useRoomPermissions(creators, powerLevels);
|
|
|
|
|
const canMessage = permissions.event(EventType.RoomMessage, mx.getSafeUserId());
|
2025-03-23 22:09:29 +11:00
|
|
|
|
2024-07-18 18:50:20 +05:30
|
|
|
useKeyDown(
|
|
|
|
|
window,
|
|
|
|
|
useCallback(
|
|
|
|
|
(evt) => {
|
|
|
|
|
if (editableActiveElement()) return;
|
2025-09-12 17:22:51 +05:30
|
|
|
const portalContainer = document.getElementById('portalContainer');
|
|
|
|
|
if (portalContainer && portalContainer.children.length > 0) {
|
2024-07-18 18:50:20 +05:30
|
|
|
return;
|
|
|
|
|
}
|
2024-07-21 11:13:33 +05:30
|
|
|
if (shouldFocusMessageField(evt) || isKeyHotkey('mod+v', evt)) {
|
2024-07-18 18:50:20 +05:30
|
|
|
ReactEditor.focus(editor);
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-05-21 23:30:50 -04:00
|
|
|
[editor],
|
|
|
|
|
),
|
2024-07-18 18:50:20 +05:30
|
|
|
);
|
|
|
|
|
|
2026-06-15 01:02:46 -04:00
|
|
|
// Apply the background directly to Page so it overrides PageRoot's opaque
|
|
|
|
|
// Background.Container color. SidebarNav mirrors it onto document.body separately
|
|
|
|
|
// so the glassmorphism sidebar can blur through it.
|
2026-06-14 18:09:03 -04:00
|
|
|
const chatBgStyle = useMemo(() => {
|
2026-06-15 01:02:46 -04:00
|
|
|
if (chatBackground !== 'none') return getChatBg(chatBackground, isDark, pauseAnimations);
|
|
|
|
|
if (lotusTerminal) return getChatBg('tactical', isDark, pauseAnimations);
|
|
|
|
|
return {};
|
|
|
|
|
}, [chatBackground, lotusTerminal, isDark, pauseAnimations]);
|
2026-05-20 21:11:38 -04:00
|
|
|
|
2024-05-31 19:49:46 +05:30
|
|
|
return (
|
2026-05-20 21:11:38 -04:00
|
|
|
<Page ref={roomViewRef} style={chatBgStyle}>
|
2024-05-31 19:49:46 +05:30
|
|
|
<Box grow="Yes" direction="Column">
|
|
|
|
|
<RoomTimeline
|
|
|
|
|
key={roomId}
|
|
|
|
|
room={room}
|
|
|
|
|
eventId={eventId}
|
|
|
|
|
roomInputRef={roomInputRef}
|
|
|
|
|
editor={editor}
|
|
|
|
|
/>
|
|
|
|
|
<RoomViewTyping room={room} />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box shrink="No" direction="Column">
|
|
|
|
|
<div style={{ padding: `0 ${config.space.S400}` }}>
|
|
|
|
|
{tombstoneEvent ? (
|
|
|
|
|
<RoomTombstone
|
|
|
|
|
roomId={roomId}
|
|
|
|
|
body={tombstoneEvent.getContent().body}
|
|
|
|
|
replacementRoomId={tombstoneEvent.getContent().replacement_room}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{canMessage && (
|
|
|
|
|
<RoomInput
|
|
|
|
|
room={room}
|
|
|
|
|
editor={editor}
|
|
|
|
|
roomId={roomId}
|
|
|
|
|
fileDropContainerRef={roomViewRef}
|
|
|
|
|
ref={roomInputRef}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{!canMessage && (
|
|
|
|
|
<RoomInputPlaceholder
|
|
|
|
|
style={{ padding: config.space.S200 }}
|
|
|
|
|
alignItems="Center"
|
|
|
|
|
justifyContent="Center"
|
|
|
|
|
>
|
|
|
|
|
<Text align="Center">You do not have permission to post in this room</Text>
|
|
|
|
|
</RoomInputPlaceholder>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-02-26 21:44:53 +11:00
|
|
|
{hideActivity ? <RoomViewFollowingPlaceholder /> : <RoomViewFollowing room={room} />}
|
2024-05-31 19:49:46 +05:30
|
|
|
</Box>
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|