2020-10-07 21:50:10 +03:00
|
|
|
import React, { Fragment } from "react";
|
2020-07-03 23:28:19 +03:00
|
|
|
import { connect } from "react-redux";
|
2020-05-23 18:43:33 +03:00
|
|
|
import {
|
2020-07-07 22:28:20 +03:00
|
|
|
BooleanField,
|
2021-05-04 14:52:43 +03:00
|
|
|
BulkDeleteButton,
|
2021-05-04 14:57:41 +03:00
|
|
|
DateField,
|
2020-05-23 18:43:33 +03:00
|
|
|
Datagrid,
|
2021-02-11 22:24:17 +03:00
|
|
|
DeleteButton,
|
2020-07-03 23:28:19 +03:00
|
|
|
Filter,
|
2020-05-23 18:43:33 +03:00
|
|
|
List,
|
2021-05-08 20:10:51 +03:00
|
|
|
NumberField,
|
2020-05-23 18:43:33 +03:00
|
|
|
Pagination,
|
2020-08-06 22:43:19 +03:00
|
|
|
ReferenceField,
|
|
|
|
ReferenceManyField,
|
2020-11-12 16:56:21 +03:00
|
|
|
SearchInput,
|
2020-07-07 22:28:20 +03:00
|
|
|
SelectField,
|
|
|
|
Show,
|
|
|
|
Tab,
|
|
|
|
TabbedShowLayout,
|
|
|
|
TextField,
|
2021-02-11 22:24:17 +03:00
|
|
|
TopToolbar,
|
2021-05-05 21:24:15 +03:00
|
|
|
useRecordContext,
|
2020-07-01 23:36:15 +03:00
|
|
|
useTranslate,
|
2020-05-23 18:43:33 +03:00
|
|
|
} from "react-admin";
|
2020-07-01 23:36:15 +03:00
|
|
|
import get from "lodash/get";
|
2021-05-05 21:24:15 +03:00
|
|
|
import PropTypes from "prop-types";
|
2021-05-08 20:10:51 +03:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2020-07-03 23:28:19 +03:00
|
|
|
import { Tooltip, Typography, Chip } from "@material-ui/core";
|
2021-05-08 20:10:51 +03:00
|
|
|
import FastForwardIcon from "@material-ui/icons/FastForward";
|
2020-07-01 23:36:15 +03:00
|
|
|
import HttpsIcon from "@material-ui/icons/Https";
|
|
|
|
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
|
2020-07-07 22:28:20 +03:00
|
|
|
import PageviewIcon from "@material-ui/icons/Pageview";
|
2020-08-06 22:43:19 +03:00
|
|
|
import UserIcon from "@material-ui/icons/Group";
|
2020-07-07 22:28:20 +03:00
|
|
|
import ViewListIcon from "@material-ui/icons/ViewList";
|
|
|
|
import VisibilityIcon from "@material-ui/icons/Visibility";
|
2021-05-04 14:57:41 +03:00
|
|
|
import EventIcon from "@material-ui/icons/Event";
|
2021-05-04 14:52:43 +03:00
|
|
|
import {
|
|
|
|
RoomDirectoryBulkDeleteButton,
|
|
|
|
RoomDirectoryBulkSaveButton,
|
|
|
|
RoomDirectoryDeleteButton,
|
|
|
|
RoomDirectorySaveButton,
|
|
|
|
} from "./RoomDirectory";
|
2020-03-27 23:02:37 +03:00
|
|
|
|
2021-05-08 20:10:51 +03:00
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
helper_forward_extremities: {
|
|
|
|
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
|
|
|
|
margin: "0.5em",
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2020-03-27 23:02:37 +03:00
|
|
|
const RoomPagination = props => (
|
|
|
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
|
|
|
);
|
2020-02-07 18:19:01 +03:00
|
|
|
|
2020-07-01 23:36:15 +03:00
|
|
|
const EncryptionField = ({ source, record = {}, emptyText }) => {
|
|
|
|
const translate = useTranslate();
|
|
|
|
const value = get(record, source);
|
|
|
|
let ariaLabel = value === false ? "ra.boolean.false" : "ra.boolean.true";
|
|
|
|
|
|
|
|
if (value === false || value === true) {
|
|
|
|
return (
|
|
|
|
<Typography component="span" variant="body2">
|
|
|
|
<Tooltip title={translate(ariaLabel, { _: ariaLabel })}>
|
|
|
|
{value === true ? (
|
|
|
|
<HttpsIcon data-testid="true" htmlColor="limegreen" />
|
|
|
|
) : (
|
|
|
|
<NoEncryptionIcon data-testid="false" color="error" />
|
|
|
|
)}
|
|
|
|
</Tooltip>
|
|
|
|
</Typography>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Typography component="span" variant="body2">
|
|
|
|
{emptyText}
|
|
|
|
</Typography>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-07 22:28:20 +03:00
|
|
|
const RoomTitle = ({ record }) => {
|
|
|
|
const translate = useTranslate();
|
2020-07-03 23:28:19 +03:00
|
|
|
var name = "";
|
2020-07-07 22:28:20 +03:00
|
|
|
if (record) {
|
2020-07-03 23:28:19 +03:00
|
|
|
name = record.name !== "" ? record.name : record.id;
|
2020-07-07 22:28:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{translate("resources.rooms.name", 1)} {name}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-11 22:24:17 +03:00
|
|
|
const RoomShowActions = ({ basePath, data, resource }) => {
|
2021-05-04 14:52:43 +03:00
|
|
|
var roomDirectoryStatus = "";
|
|
|
|
if (data) {
|
|
|
|
roomDirectoryStatus = data.public;
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:24:17 +03:00
|
|
|
return (
|
|
|
|
<TopToolbar>
|
2021-05-04 14:52:43 +03:00
|
|
|
{roomDirectoryStatus === false && (
|
|
|
|
<RoomDirectorySaveButton record={data} />
|
|
|
|
)}
|
|
|
|
{roomDirectoryStatus === true && (
|
|
|
|
<RoomDirectoryDeleteButton record={data} />
|
|
|
|
)}
|
2021-02-11 22:24:17 +03:00
|
|
|
<DeleteButton
|
|
|
|
basePath={basePath}
|
|
|
|
record={data}
|
|
|
|
resource={resource}
|
2021-05-04 14:52:43 +03:00
|
|
|
mutationMode="pessimistic"
|
|
|
|
confirmTitle="resources.rooms.action.erase.title"
|
|
|
|
confirmContent="resources.rooms.action.erase.content"
|
2021-02-11 22:24:17 +03:00
|
|
|
/>
|
|
|
|
</TopToolbar>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-07 22:28:20 +03:00
|
|
|
export const RoomShow = props => {
|
2021-05-08 20:10:51 +03:00
|
|
|
const classes = useStyles({ props });
|
2020-07-07 22:28:20 +03:00
|
|
|
const translate = useTranslate();
|
|
|
|
return (
|
2021-02-11 22:24:17 +03:00
|
|
|
<Show {...props} actions={<RoomShowActions />} title={<RoomTitle />}>
|
2020-07-07 22:28:20 +03:00
|
|
|
<TabbedShowLayout>
|
|
|
|
<Tab label="synapseadmin.rooms.tabs.basic" icon={<ViewListIcon />}>
|
|
|
|
<TextField source="room_id" />
|
|
|
|
<TextField source="name" />
|
|
|
|
<TextField source="canonical_alias" />
|
2021-05-04 14:57:41 +03:00
|
|
|
<ReferenceField source="creator" reference="users">
|
|
|
|
<TextField source="id" />
|
|
|
|
</ReferenceField>
|
2020-07-07 22:28:20 +03:00
|
|
|
</Tab>
|
|
|
|
|
|
|
|
<Tab
|
|
|
|
label="synapseadmin.rooms.tabs.detail"
|
|
|
|
icon={<PageviewIcon />}
|
|
|
|
path="detail"
|
|
|
|
>
|
|
|
|
<TextField source="joined_members" />
|
|
|
|
<TextField source="joined_local_members" />
|
2021-05-04 14:49:20 +03:00
|
|
|
<TextField source="joined_local_devices" />
|
2020-07-07 22:28:20 +03:00
|
|
|
<TextField source="state_events" />
|
|
|
|
<TextField source="version" />
|
|
|
|
<TextField
|
|
|
|
source="encryption"
|
|
|
|
emptyText={translate("resources.rooms.enums.unencrypted")}
|
|
|
|
/>
|
|
|
|
</Tab>
|
|
|
|
|
2020-08-06 22:43:19 +03:00
|
|
|
<Tab label="synapseadmin.rooms.tabs.members" icon={<UserIcon />}>
|
|
|
|
<ReferenceManyField
|
|
|
|
reference="room_members"
|
|
|
|
target="room_id"
|
|
|
|
addLabel={false}
|
|
|
|
>
|
|
|
|
<Datagrid
|
|
|
|
style={{ width: "100%" }}
|
|
|
|
rowClick={(id, basePath, record) => "/users/" + id}
|
|
|
|
>
|
|
|
|
<TextField
|
|
|
|
source="id"
|
|
|
|
sortable={false}
|
|
|
|
label="resources.users.fields.id"
|
|
|
|
/>
|
|
|
|
<ReferenceField
|
|
|
|
label="resources.users.fields.displayname"
|
|
|
|
source="id"
|
|
|
|
reference="users"
|
|
|
|
sortable={false}
|
|
|
|
link=""
|
|
|
|
>
|
|
|
|
<TextField source="displayname" sortable={false} />
|
|
|
|
</ReferenceField>
|
|
|
|
</Datagrid>
|
|
|
|
</ReferenceManyField>
|
|
|
|
</Tab>
|
|
|
|
|
2020-07-07 22:28:20 +03:00
|
|
|
<Tab
|
|
|
|
label="synapseadmin.rooms.tabs.permission"
|
|
|
|
icon={<VisibilityIcon />}
|
|
|
|
path="permission"
|
|
|
|
>
|
|
|
|
<BooleanField source="federatable" />
|
|
|
|
<BooleanField source="public" />
|
|
|
|
<SelectField
|
|
|
|
source="join_rules"
|
|
|
|
choices={[
|
|
|
|
{ id: "public", name: "resources.rooms.enums.join_rules.public" },
|
|
|
|
{ id: "knock", name: "resources.rooms.enums.join_rules.knock" },
|
|
|
|
{ id: "invite", name: "resources.rooms.enums.join_rules.invite" },
|
|
|
|
{
|
|
|
|
id: "private",
|
|
|
|
name: "resources.rooms.enums.join_rules.private",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<SelectField
|
|
|
|
source="guest_access"
|
|
|
|
choices={[
|
|
|
|
{
|
|
|
|
id: "can_join",
|
|
|
|
name: "resources.rooms.enums.guest_access.can_join",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "forbidden",
|
|
|
|
name: "resources.rooms.enums.guest_access.forbidden",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<SelectField
|
|
|
|
source="history_visibility"
|
|
|
|
choices={[
|
|
|
|
{
|
|
|
|
id: "invited",
|
|
|
|
name: "resources.rooms.enums.history_visibility.invited",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "joined",
|
|
|
|
name: "resources.rooms.enums.history_visibility.joined",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "shared",
|
|
|
|
name: "resources.rooms.enums.history_visibility.shared",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "world_readable",
|
|
|
|
name: "resources.rooms.enums.history_visibility.world_readable",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Tab>
|
2021-05-08 20:10:51 +03:00
|
|
|
|
2021-05-04 14:57:41 +03:00
|
|
|
<Tab
|
|
|
|
label={translate("resources.room_state.name", { smart_count: 2 })}
|
|
|
|
icon={<EventIcon />}
|
|
|
|
path="state"
|
|
|
|
>
|
|
|
|
<ReferenceManyField
|
|
|
|
reference="room_state"
|
|
|
|
target="room_id"
|
|
|
|
addLabel={false}
|
|
|
|
>
|
|
|
|
<Datagrid style={{ width: "100%" }}>
|
|
|
|
<TextField source="type" sortable={false} />
|
|
|
|
<DateField
|
|
|
|
source="origin_server_ts"
|
|
|
|
showTime
|
|
|
|
options={{
|
|
|
|
year: "numeric",
|
|
|
|
month: "2-digit",
|
|
|
|
day: "2-digit",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit",
|
|
|
|
}}
|
|
|
|
sortable={false}
|
|
|
|
/>
|
|
|
|
<TextField source="content" sortable={false} />
|
|
|
|
<ReferenceField
|
|
|
|
source="sender"
|
|
|
|
reference="users"
|
|
|
|
sortable={false}
|
|
|
|
>
|
|
|
|
<TextField source="id" />
|
|
|
|
</ReferenceField>
|
|
|
|
</Datagrid>
|
|
|
|
</ReferenceManyField>
|
2021-05-08 20:10:51 +03:00
|
|
|
</Tab>
|
|
|
|
|
|
|
|
<Tab
|
|
|
|
label="resources.forward_extremities.name"
|
|
|
|
icon={<FastForwardIcon />}
|
|
|
|
path="forward_extremities"
|
|
|
|
>
|
|
|
|
<div className={classes.helper_forward_extremities}>
|
|
|
|
{translate("resources.rooms.helper.forward_extremities")}
|
|
|
|
</div>
|
|
|
|
<ReferenceManyField
|
|
|
|
reference="forward_extremities"
|
|
|
|
target="room_id"
|
|
|
|
addLabel={false}
|
|
|
|
>
|
|
|
|
<Datagrid style={{ width: "100%" }}>
|
|
|
|
<TextField source="id" sortable={false} />
|
|
|
|
<DateField
|
|
|
|
source="received_ts"
|
|
|
|
showTime
|
|
|
|
options={{
|
|
|
|
year: "numeric",
|
|
|
|
month: "2-digit",
|
|
|
|
day: "2-digit",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit",
|
|
|
|
}}
|
|
|
|
sortable={false}
|
|
|
|
/>
|
|
|
|
<NumberField source="depth" sortable={false} />
|
|
|
|
<TextField source="state_group" sortable={false} />
|
|
|
|
</Datagrid>
|
|
|
|
</ReferenceManyField>
|
2021-05-04 14:57:41 +03:00
|
|
|
</Tab>
|
2020-07-07 22:28:20 +03:00
|
|
|
</TabbedShowLayout>
|
|
|
|
</Show>
|
|
|
|
);
|
|
|
|
};
|
2020-10-07 22:42:19 +03:00
|
|
|
|
|
|
|
const RoomBulkActionButtons = props => (
|
2020-11-12 16:56:21 +03:00
|
|
|
<Fragment>
|
2021-05-04 14:52:43 +03:00
|
|
|
<RoomDirectoryBulkSaveButton {...props} />
|
|
|
|
<RoomDirectoryBulkDeleteButton {...props} />
|
|
|
|
<BulkDeleteButton
|
|
|
|
{...props}
|
|
|
|
confirmTitle="resources.rooms.action.erase.title"
|
|
|
|
confirmContent="resources.rooms.action.erase.content"
|
|
|
|
undoable={false}
|
|
|
|
/>
|
2020-11-12 16:56:21 +03:00
|
|
|
</Fragment>
|
2020-10-07 22:42:19 +03:00
|
|
|
);
|
|
|
|
|
2020-07-03 23:28:19 +03:00
|
|
|
const RoomFilter = ({ ...props }) => {
|
|
|
|
const translate = useTranslate();
|
|
|
|
return (
|
|
|
|
<Filter {...props}>
|
2020-11-12 16:56:21 +03:00
|
|
|
<SearchInput source="search_term" alwaysOn />
|
2020-07-03 23:28:19 +03:00
|
|
|
<Chip
|
|
|
|
label={translate("resources.rooms.fields.joined_local_members")}
|
|
|
|
source="joined_local_members"
|
|
|
|
defaultValue={false}
|
|
|
|
style={{ marginBottom: 8 }}
|
|
|
|
/>
|
|
|
|
<Chip
|
|
|
|
label={translate("resources.rooms.fields.state_events")}
|
|
|
|
source="state_events"
|
|
|
|
defaultValue={false}
|
|
|
|
style={{ marginBottom: 8 }}
|
|
|
|
/>
|
|
|
|
<Chip
|
|
|
|
label={translate("resources.rooms.fields.version")}
|
|
|
|
source="version"
|
|
|
|
defaultValue={false}
|
|
|
|
style={{ marginBottom: 8 }}
|
|
|
|
/>
|
|
|
|
<Chip
|
|
|
|
label={translate("resources.rooms.fields.federatable")}
|
|
|
|
source="federatable"
|
|
|
|
defaultValue={false}
|
|
|
|
style={{ marginBottom: 8 }}
|
|
|
|
/>
|
|
|
|
</Filter>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-05-05 21:24:15 +03:00
|
|
|
const RoomNameField = props => {
|
|
|
|
const { source } = props;
|
|
|
|
const record = useRecordContext(props);
|
|
|
|
return (
|
|
|
|
<span>{record[source] || record["canonical_alias"] || record["id"]}</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
RoomNameField.propTypes = {
|
|
|
|
label: PropTypes.string,
|
|
|
|
record: PropTypes.object,
|
|
|
|
source: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-05-04 17:04:26 +03:00
|
|
|
const FilterableRoomList = ({ roomFilters, dispatch, ...props }) => {
|
|
|
|
const filter = roomFilters;
|
2020-07-03 23:28:19 +03:00
|
|
|
const localMembersFilter =
|
|
|
|
filter && filter.joined_local_members ? true : false;
|
|
|
|
const stateEventsFilter = filter && filter.state_events ? true : false;
|
|
|
|
const versionFilter = filter && filter.version ? true : false;
|
|
|
|
const federateableFilter = filter && filter.federatable ? true : false;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<List
|
|
|
|
{...props}
|
|
|
|
pagination={<RoomPagination />}
|
|
|
|
sort={{ field: "name", order: "ASC" }}
|
|
|
|
filters={<RoomFilter />}
|
2021-05-04 14:52:43 +03:00
|
|
|
bulkActionButtons={<RoomBulkActionButtons />}
|
2020-07-03 23:28:19 +03:00
|
|
|
>
|
|
|
|
<Datagrid rowClick="show">
|
|
|
|
<EncryptionField
|
|
|
|
source="is_encrypted"
|
|
|
|
sortBy="encryption"
|
|
|
|
label={<HttpsIcon />}
|
|
|
|
/>
|
2021-05-05 21:24:15 +03:00
|
|
|
<RoomNameField source="name" />
|
2020-07-03 23:28:19 +03:00
|
|
|
<TextField source="joined_members" />
|
|
|
|
{localMembersFilter && <TextField source="joined_local_members" />}
|
|
|
|
{stateEventsFilter && <TextField source="state_events" />}
|
|
|
|
{versionFilter && <TextField source="version" />}
|
|
|
|
{federateableFilter && <BooleanField source="federatable" />}
|
|
|
|
<BooleanField source="public" />
|
|
|
|
</Datagrid>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
roomFilters: state.admin.resources.rooms.list.params.displayedFilters,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RoomList = connect(mapStateToProps)(FilterableRoomList);
|