2022-01-13 14:00:43 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import { twemojify } from '../../../util/twemojify';
|
|
|
|
|
|
|
|
import initMatrix from '../../../client/initMatrix';
|
2022-04-24 12:23:10 +02:00
|
|
|
import { openInviteUser, openNavigation } from '../../../client/action/navigation';
|
2022-01-13 14:00:43 +01:00
|
|
|
import * as roomActions from '../../../client/action/room';
|
2022-03-18 04:39:14 +01:00
|
|
|
import { markAsRead } from '../../../client/action/notifications';
|
2022-01-13 14:00:43 +01:00
|
|
|
|
|
|
|
import { MenuHeader, MenuItem } from '../../atoms/context-menu/ContextMenu';
|
|
|
|
import RoomNotification from '../room-notification/RoomNotification';
|
|
|
|
|
|
|
|
import TickMarkIC from '../../../../public/res/ic/outlined/tick-mark.svg';
|
|
|
|
import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg';
|
|
|
|
import LeaveArrowIC from '../../../../public/res/ic/outlined/leave-arrow.svg';
|
|
|
|
|
|
|
|
function RoomOptions({ roomId, afterOptionSelect }) {
|
|
|
|
const mx = initMatrix.matrixClient;
|
|
|
|
const room = mx.getRoom(roomId);
|
|
|
|
const canInvite = room?.canInvite(mx.getUserId());
|
|
|
|
|
|
|
|
const handleMarkAsRead = () => {
|
2022-03-18 04:39:14 +01:00
|
|
|
markAsRead(roomId);
|
2022-01-13 14:00:43 +01:00
|
|
|
afterOptionSelect();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleInviteClick = () => {
|
|
|
|
openInviteUser(roomId);
|
|
|
|
afterOptionSelect();
|
|
|
|
};
|
|
|
|
const handleLeaveClick = () => {
|
2022-04-18 05:25:16 +02:00
|
|
|
if (confirm('Are you sure that you want to leave this room?')) {
|
2022-01-13 14:00:43 +01:00
|
|
|
roomActions.leave(roomId);
|
|
|
|
afterOptionSelect();
|
2022-04-24 12:23:10 +02:00
|
|
|
openNavigation();
|
2022-01-13 14:00:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-01-30 06:11:18 +01:00
|
|
|
<div style={{ maxWidth: '256px' }}>
|
2022-01-13 14:00:43 +01:00
|
|
|
<MenuHeader>{twemojify(`Options for ${initMatrix.matrixClient.getRoom(roomId)?.name}`)}</MenuHeader>
|
|
|
|
<MenuItem iconSrc={TickMarkIC} onClick={handleMarkAsRead}>Mark as read</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
iconSrc={AddUserIC}
|
|
|
|
onClick={handleInviteClick}
|
|
|
|
disabled={!canInvite}
|
|
|
|
>
|
|
|
|
Invite
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem iconSrc={LeaveArrowIC} variant="danger" onClick={handleLeaveClick}>Leave</MenuItem>
|
|
|
|
<MenuHeader>Notification</MenuHeader>
|
|
|
|
<RoomNotification roomId={roomId} />
|
2022-01-30 06:11:18 +01:00
|
|
|
</div>
|
2022-01-13 14:00:43 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomOptions.defaultProps = {
|
|
|
|
afterOptionSelect: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
RoomOptions.propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
afterOptionSelect: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomOptions;
|