2021-12-22 20:18:32 +05:30
|
|
|
import React, { useEffect, useRef } from 'react';
|
2021-07-28 18:45:52 +05:30
|
|
|
import PropTypes from 'prop-types';
|
2021-08-31 18:43:31 +05:30
|
|
|
import './RoomView.scss';
|
2023-06-12 21:15:23 +10:00
|
|
|
import { Text, config } from 'folds';
|
2021-07-28 18:45:52 +05:30
|
|
|
|
|
|
|
|
import EventEmitter from 'events';
|
|
|
|
|
|
2021-12-22 20:18:32 +05:30
|
|
|
import cons from '../../../client/state/cons';
|
|
|
|
|
import navigation from '../../../client/state/navigation';
|
|
|
|
|
|
2021-08-31 18:43:31 +05:30
|
|
|
import RoomViewHeader from './RoomViewHeader';
|
|
|
|
|
import RoomViewContent from './RoomViewContent';
|
|
|
|
|
import RoomViewFloating from './RoomViewFloating';
|
|
|
|
|
import RoomViewCmdBar from './RoomViewCmdBar';
|
2023-06-12 21:15:23 +10:00
|
|
|
import { RoomInput } from './RoomInput';
|
|
|
|
|
import { useStateEvent } from '../../hooks/useStateEvent';
|
|
|
|
|
import { StateEvent } from '../../../types/matrix/room';
|
|
|
|
|
import { RoomTombstone } from './RoomTombstone';
|
|
|
|
|
import { usePowerLevels } from '../../hooks/usePowerLevels';
|
|
|
|
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
|
|
|
|
import { RoomInputPlaceholder } from './RoomInputPlaceholder';
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2021-08-04 15:22:59 +05:30
|
|
|
const viewEvent = new EventEmitter();
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
function RoomView({ room, roomTimeline, eventId }) {
|
|
|
|
|
const roomInputRef = useRef(null);
|
2021-12-22 20:18:32 +05:30
|
|
|
const roomViewRef = useRef(null);
|
2021-12-03 18:32:10 +05:30
|
|
|
// eslint-disable-next-line react/prop-types
|
|
|
|
|
const { roomId } = roomTimeline;
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
const mx = useMatrixClient();
|
|
|
|
|
const tombstoneEvent = useStateEvent(room, StateEvent.RoomTombstone);
|
|
|
|
|
const { getPowerLevel, canSendEvent } = usePowerLevels(room);
|
|
|
|
|
const myUserId = mx.getUserId();
|
|
|
|
|
const canMessage = myUserId ? canSendEvent(undefined, getPowerLevel(myUserId)) : false;
|
|
|
|
|
|
2021-12-22 20:18:32 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
const settingsToggle = (isVisible) => {
|
|
|
|
|
const roomView = roomViewRef.current;
|
|
|
|
|
roomView.classList.toggle('room-view--dropped');
|
|
|
|
|
|
|
|
|
|
const roomViewContent = roomView.children[1];
|
2021-12-23 10:03:20 +05:30
|
|
|
if (isVisible) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (!navigation.isRoomSettings) return;
|
|
|
|
|
roomViewContent.style.visibility = 'hidden';
|
|
|
|
|
}, 200);
|
|
|
|
|
} else roomViewContent.style.visibility = 'visible';
|
2021-12-22 20:18:32 +05:30
|
|
|
};
|
|
|
|
|
navigation.on(cons.events.navigation.ROOM_SETTINGS_TOGGLED, settingsToggle);
|
|
|
|
|
return () => {
|
|
|
|
|
navigation.removeListener(cons.events.navigation.ROOM_SETTINGS_TOGGLED, settingsToggle);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2021-07-28 18:45:52 +05:30
|
|
|
return (
|
2021-12-22 20:18:32 +05:30
|
|
|
<div className="room-view" ref={roomViewRef}>
|
2021-08-31 18:43:31 +05:30
|
|
|
<RoomViewHeader roomId={roomId} />
|
|
|
|
|
<div className="room-view__content-wrapper">
|
|
|
|
|
<div className="room-view__scrollable">
|
2021-12-03 18:32:10 +05:30
|
|
|
<RoomViewContent
|
|
|
|
|
eventId={eventId}
|
|
|
|
|
roomTimeline={roomTimeline}
|
2023-06-12 21:15:23 +10:00
|
|
|
roomInputRef={roomInputRef}
|
2021-12-03 18:32:10 +05:30
|
|
|
/>
|
2023-06-12 21:15:23 +10:00
|
|
|
<RoomViewFloating roomId={roomId} roomTimeline={roomTimeline} />
|
2021-12-03 18:32:10 +05:30
|
|
|
</div>
|
|
|
|
|
<div className="room-view__sticky">
|
2023-06-12 21:15:23 +10:00
|
|
|
<div className="room-view__editor">
|
|
|
|
|
{tombstoneEvent ? (
|
|
|
|
|
<RoomTombstone
|
|
|
|
|
roomId={roomId}
|
|
|
|
|
body={tombstoneEvent.getContent().body}
|
|
|
|
|
replacementRoomId={tombstoneEvent.getContent().replacement_room}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{canMessage && (
|
|
|
|
|
<RoomInput roomId={roomId} roomViewRef={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>
|
|
|
|
|
<RoomViewCmdBar roomId={roomId} roomTimeline={roomTimeline} viewEvent={viewEvent} />
|
2021-07-28 18:45:52 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-12-03 18:32:10 +05:30
|
|
|
|
|
|
|
|
RoomView.defaultProps = {
|
|
|
|
|
eventId: null,
|
|
|
|
|
};
|
2021-08-31 18:43:31 +05:30
|
|
|
RoomView.propTypes = {
|
2023-06-12 21:15:23 +10:00
|
|
|
room: PropTypes.shape({}).isRequired,
|
2021-12-03 18:32:10 +05:30
|
|
|
roomTimeline: PropTypes.shape({}).isRequired,
|
|
|
|
|
eventId: PropTypes.string,
|
2021-07-28 18:45:52 +05:30
|
|
|
};
|
|
|
|
|
|
2021-08-31 18:43:31 +05:30
|
|
|
export default RoomView;
|