Cleanup room creation

Change-Id: Ieb5189513d21606f8d0bea5692112350a68f2e14
This commit is contained in:
Manuel Stahl
2020-04-21 14:03:35 +02:00
parent d3cd2e9e33
commit 0823976edd
5 changed files with 78 additions and 102 deletions

View File

@@ -45,9 +45,17 @@ const resourceMap = {
members: r.joined_members,
}),
data: "rooms",
total: json => {
return json.total_rooms;
},
total: json => json.total_rooms,
create: params => ({
method: "POST",
endpoint: "/_matrix/client/r0/createRoom",
body: {
name: params.data.name,
room_alias_name: params.data.canonical_alias,
visibility: params.data.public ? "public" : "private",
},
map: r => ({ id: r.room_id }),
}),
},
connections: {
path: "/_synapse/admin/v1/whois",
@@ -67,38 +75,6 @@ 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_url");
const homeserver_url = "https://" + homeserver + roomCreationMap.path;
const newParams = { ...params.data,
public: undefined,
room_name: undefined,
alias: undefined,
name: params.data.room_name,
room_alias_name: params.data.alias,
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);
@@ -242,23 +218,24 @@ 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);
if ("create" in res) {
const create = res["create"](params);
const homeserver_url = homeserver + create.endpoint;
return jsonClient(homeserver_url, {
method: create.method,
body: JSON.stringify(create.body, filterNullValues),
}).then(({ json }) => ({
data: create.map(json),
}));
} else {
const homeserver_url = homeserver + res.path;
return jsonClient(`${homeserver_url}/${params.data.id}`, {
method: "PUT",
body: JSON.stringify(params.data, filterNullValues),
}).then(({ json }) => ({
data: res.map(json),
}));
}
return jsonClient(`${homeserver_url}/${params.data.id}`, {
method: "PUT",
body: JSON.stringify(params.data, filterNullValues),
}).then(({ json }) => ({
data: res.map(json),
}));
},
delete: (resource, params) => {