From ab04db5baf1ee7f4abeedced471112ac72c345d9 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Wed, 10 Jun 2020 14:59:55 +0200 Subject: [PATCH] Get avatar_url and displayname from v2/users API API was added by synapse v1.13.0. Change-Id: I927b81882fa20e5b3de3d9fc216e2136f7036bba --- src/components/users.js | 251 +++++++++++++++++++----------------- src/i18n/de.js | 1 + src/i18n/en.js | 1 + src/synapse/dataProvider.js | 18 ++- 4 files changed, 149 insertions(+), 122 deletions(-) diff --git a/src/components/users.js b/src/components/users.js index ff21436..c18555c 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -1,4 +1,5 @@ import React, { Fragment } from "react"; +import Avatar from "@material-ui/core/Avatar"; import PersonPinIcon from "@material-ui/icons/PersonPin"; import ContactMailIcon from "@material-ui/icons/ContactMail"; import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent"; @@ -18,7 +19,6 @@ import { FormTab, BooleanField, BooleanInput, - ImageField, PasswordInput, TextField, TextInput, @@ -32,6 +32,19 @@ import { Pagination, } from "react-admin"; import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices"; +import { makeStyles } from "@material-ui/core/styles"; + +const useStyles = makeStyles({ + small: { + height: "40px", + width: "40px", + }, + large: { + height: "120px", + width: "120px", + float: "right", + }, +}); const UserPagination = props => ( @@ -62,40 +75,36 @@ const UserBulkActionButtons = props => { ); }; -export const UserList = props => ( - } - filterDefaultValues={{ guests: true, deactivated: false }} - bulkActionButtons={} - pagination={} - > - - - - - - {/* Hack since the users endpoint does not give displaynames in the list*/} - - - - - - - - +const AvatarField = ({ source, className, record = {} }) => ( + ); +export const UserList = props => { + const classes = useStyles(); + return ( + } + filterDefaultValues={{ guests: true, deactivated: false }} + bulkActionButtons={} + pagination={} + > + + + + + + + + + + ); +}; + // https://matrix.org/docs/spec/appendices#user-identifiers const validateUser = regex( /^@[a-z0-9._=\-/]+:.*/, @@ -148,89 +157,97 @@ const UserTitle = ({ record }) => { ); }; -export const UserEdit = props => ( - }> - }> - }> - - - - - - - - - } - path="threepid" - > - - - - - - - - } - path="connections" - > - { + const classes = useStyles(); + return ( + }> + }> + }> + + + + + + + + + + } + path="threepid" > - + + + + + + + } + path="connections" + > + - - - - - - - - - - -); + + + + + + + + + + + + ); +}; diff --git a/src/i18n/de.js b/src/i18n/de.js index 5ec9947..cc75b68 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -36,6 +36,7 @@ export default { displayname: "Anzeigename", password: "Passwort", avatar_url: "Avatar URL", + avatar_src: "Avatar", medium: "Medium", threepids: "3PIDs", address: "Adresse", diff --git a/src/i18n/en.js b/src/i18n/en.js index 2b29701..3c0fd7c 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -35,6 +35,7 @@ export default { displayname: "Displayname", password: "Password", avatar_url: "Avatar URL", + avatar_src: "Avatar", medium: "Medium", threepids: "3PIDs", address: "Address", diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index 21748fd..cebc413 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -14,12 +14,24 @@ const jsonClient = (url, options = {}) => { return fetchUtils.fetchJson(url, options); }; +const mxcUrlToHttp = mxcUrl => { + const homeserver = localStorage.getItem("base_url"); + const re = /^mxc:\/\/([^/]+)\/(\w+)/; + var ret = re.exec(mxcUrl); + console.log("mxcClient " + ret); + if (ret == null) return null; + const serverName = ret[1]; + const mediaId = ret[2]; + return `${homeserver}/_matrix/media/r0/thumbnail/${serverName}/${mediaId}?width=24&height=24&method=scale`; +}; + const resourceMap = { users: { path: "/_synapse/admin/v2/users", map: u => ({ ...u, id: u.name, + avatar_src: mxcUrlToHttp(u.avatar_url), is_guest: !!u.is_guest, admin: !!u.admin, deactivated: !!u.deactivated, @@ -27,11 +39,7 @@ const resourceMap = { creation_ts_ms: u.creation_ts * 1000, }), data: "users", - total: (json, from, perPage) => { - return json.next_token - ? parseInt(json.next_token, 10) + perPage - : from + json.users.length; - }, + total: json => json.total, create: data => ({ endpoint: `/_synapse/admin/v2/users/${data.id}`, body: data,