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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user