Offer room creation form
A choice of public or private is offered, which maps to matrix' visibility parameter. A name can also be provided. Change-Id: I34d99acbc4624a9ed54ca6f6609573d5fc1049da
This commit is contained in:
parent
e9c3901b68
commit
ca15435625
@ -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}
|
||||
/>
|
||||
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
||||
<Resource
|
||||
name="rooms"
|
||||
list={RoomList}
|
||||
create={RoomCreate}
|
||||
icon={RoomIcon} />
|
||||
<Resource name="connections" />
|
||||
</Admin>
|
||||
);
|
||||
|
@ -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 => (
|
||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||
@ -15,3 +24,27 @@ export const RoomList = props => (
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
||||
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 => (
|
||||
<Create record={generateRoomRecord()} {...props}>
|
||||
<SimpleForm>
|
||||
<TextInput source="room_name"
|
||||
label="synapseadmin.rooms.room_name"
|
||||
parse={removeLeadingWhitespace}
|
||||
validate={validateDisplayName}/>
|
||||
<BooleanInput source="public"
|
||||
label="synapseadmin.rooms.make_public"/>
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
|
@ -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: {
|
||||
|
@ -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: {
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user