diff --git a/src/App.js b/src/App.js index 567d211..3879c14 100644 --- a/src/App.js +++ b/src/App.js @@ -4,7 +4,7 @@ import polyglotI18nProvider from "ra-i18n-polyglot"; import authProvider from "./synapse/authProvider"; import dataProvider from "./synapse/dataProvider"; import { UserList, UserCreate, UserEdit } from "./components/users"; -import { RoomList } from "./components/rooms"; +import { RoomList, RoomCreate } from "./components/rooms"; import LoginPage from "./components/LoginPage"; import UserIcon from "@material-ui/icons/Group"; import { ViewListIcon as RoomIcon } from "@material-ui/icons/ViewList"; @@ -40,7 +40,11 @@ const App = () => ( edit={UserEdit} icon={UserIcon} /> - + ); diff --git a/src/components/rooms.js b/src/components/rooms.js index 8cac414..f8612b6 100644 --- a/src/components/rooms.js +++ b/src/components/rooms.js @@ -1,5 +1,14 @@ import React from "react"; -import { Datagrid, List, TextField, Pagination } from "react-admin"; +import { + BooleanInput, + Create, + Datagrid, + List, + Pagination, + SimpleForm, + TextField, + TextInput, +} from "react-admin"; const RoomPagination = props => ( @@ -15,3 +24,27 @@ export const RoomList = props => ( ); + +function generateRoomRecord() { + return { + room_name: "", + public: true, + } +} + +const validateDisplayName = fieldval => fieldval === undefined ? "synapseadmin.rooms.room_name_required" : fieldval.length === 0 ? "synapseadmin.rooms.room_name_required" : undefined; + +const removeLeadingWhitespace = fieldVal => fieldVal === undefined ? undefined : fieldVal.trimStart(); + +export const RoomCreate = props => ( + + + + + + +); diff --git a/src/i18n/de.js b/src/i18n/de.js index 59bfafc..4e4b67c 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -16,6 +16,12 @@ export default { invalid_user_id: "Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver", }, + rooms: { + room_name: "Raumname", + make_public: "Öffentlicher Raum", + room_name_required: + "Muss angegeben werden", + } }, resources: { users: { diff --git a/src/i18n/en.js b/src/i18n/en.js index 7adda39..d8cb0a4 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -16,6 +16,12 @@ export default { invalid_user_id: "Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver", }, + rooms: { + room_name: "Room Name", + make_public: "Make room public", + room_name_required: + "Must be provided", + } }, resources: { users: { diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index da33383..d47576d 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -67,6 +67,36 @@ function filterNullValues(key, value) { return value; } +const roomCreationMap = { + path: "/_matrix/client/r0/createRoom", + map: r => ({ + room_id: r.room_id + }) +}; + +const roomCreationProvider = { + create: (resource, params) => { + const homeserver = localStorage.getItem("home_server"); + + const homeserver_url = "https://" + homeserver + roomCreationMap.path; + + const newParams = { ...params.data, + public: undefined, + room_name: undefined, + + name: params.data.room_name, + visibility: params.data.public ? "public" : "private", + } + + return jsonClient(homeserver_url, { + method: "POST", + body: JSON.stringify(newParams, filterNullValues), + }).then(({ json }) => ({ + data: roomCreationMap.map(json), + })); + } +}; + const dataProvider = { getList: (resource, params) => { console.log("getList " + resource); @@ -211,6 +241,16 @@ const dataProvider = { const res = resourceMap[resource]; const homeserver_url = homeserver + res.path; + + /* Special handling for rooms, as creating a room + is a POST request rather than put, and goes through + the client-server API rather than the admin API. */ + if (resource === "rooms") { + console.log("want to create a room!"); + console.log(params); + return roomCreationProvider.create(resource, params); + } + return jsonClient(`${homeserver_url}/${params.data.id}`, { method: "PUT", body: JSON.stringify(params.data, filterNullValues),