Skip to content

Commit

Permalink
Fix room state events display (#100)
Browse files Browse the repository at this point in the history
* Fix room state events table display

* update readme
  • Loading branch information
aine-etke authored Oct 23, 2024
1 parent 865e533 commit 28ef08d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The following changes are already implemented:
* [Custom Menu Items](https://github.com/etkecc/synapse-admin/pull/79)
* [Add user profile to the top menu](https://github.com/etkecc/synapse-admin/pull/80)
* [Enable visual customization](https://github.com/etkecc/synapse-admin/pull/81)
* [Fix room state events display](https://github.com/etkecc/synapse-admin/pull/100)

_the list will be updated as new changes are added_

Expand Down
2 changes: 1 addition & 1 deletion src/resources/rooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const RoomShow = (props: ShowProps) => {
<Datagrid style={{ width: "100%" }} bulkActionButtons={false}>
<TextField source="type" sortable={false} />
<DateField source="origin_server_ts" showTime options={DATE_FORMAT} sortable={false} />
<TextField source="content" sortable={false} />
<FunctionField source="content" sortable={false} render={record => `${JSON.stringify(record.content, null, 2)}`} />
<ReferenceField source="sender" reference="users" sortable={false}>
<TextField source="id" />
</ReferenceField>
Expand Down
2 changes: 1 addition & 1 deletion src/synapse/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const authProvider: AuthProvider = {

response = await fetchUtils.fetchJson(login_api_url, options);
const json = response.json;
storage.setItem("home_server", accessToken ? base_url : json.home_server);
storage.setItem("home_server", accessToken ? json.user_id.split(":")[1] : json.home_server);
storage.setItem("user_id", json.user_id);
storage.setItem("access_token", accessToken ? accessToken : json.access_token);
storage.setItem("device_id", json.device_id);
Expand Down
23 changes: 19 additions & 4 deletions src/synapse/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,28 @@ const baseDataProvider: SynapseDataProvider = {

getMany: async (resource, params) => {
console.log("getMany " + resource);
const homeserver = storage.getItem("base_url");
if (!homeserver || !(resource in resourceMap)) throw Error("Homerserver not set");
const base_url = storage.getItem("base_url");
const homeserver = storage.getItem("home_server");
if (!base_url || !(resource in resourceMap)) throw Error("base_url not set");

const res = resourceMap[resource];

const endpoint_url = homeserver + res.path;
const responses = await Promise.all(params.ids.map(id => jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`)));
const endpoint_url = base_url + res.path;
const responses = await Promise.all(params.ids.map(id => {
// edge case: when user is external / federated, homeserver will return error, as querying external users via
// /_synapse/admin/v2/users is not allowed.
// That leads to an issue when a user is referenced (e.g., in room state datagrid) - the user cell is just empty.
// To avoid that, we fake the response with one specific field (name) which is used in the datagrid.
if (homeserver && resource === "users") {
if (!(<string>id).endsWith(homeserver)) {
const json = {
name: id,
};
return Promise.resolve({ json });
}
}
return jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`);
}));
return {
data: responses.map(({ json }) => res.map(json)),
total: responses.length,
Expand Down

0 comments on commit 28ef08d

Please sign in to comment.