diff --git a/src/components/users.js b/src/components/users.js
index a6889b2..1cd1ef8 100644
--- a/src/components/users.js
+++ b/src/components/users.js
@@ -36,6 +36,8 @@ import {
ExportButton,
TopToolbar,
sanitizeListRestProps,
+ ImageInput,
+ ImageField,
} from "react-admin";
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
import { DeviceRemoveButton } from "./devices";
@@ -221,6 +223,9 @@ export const UserEdit = props => {
+
+
+
({
- data: res.map(json),
- }));
+
+ // In case there is a avatar_file object, save it in the media repository
+ // and update the avatar_url.
+ const f = params?.data?.avatar_file?.rawFile;
+ if (f instanceof File) {
+ const file_endpoint =
+ homeserver + "/_matrix/media/r0/upload?filename=" + f.name;
+ const headers = new Headers();
+ headers.append("Content-Type", f.type);
+ const options = {
+ method: "POST",
+ body: f,
+ headers: headers,
+ };
+ return jsonClient(file_endpoint, options).then(r => {
+ params.data.avatar_url = r.json.content_uri;
+
+ return jsonClient(`${endpoint_url}/${params.data.id}`, {
+ method: "PUT",
+ body: JSON.stringify(params.data, filterNullValues),
+ }).then(({ json }) => ({
+ data: res.map(json),
+ }));
+ });
+ } else {
+ return jsonClient(`${endpoint_url}/${params.data.id}`, {
+ method: "PUT",
+ body: JSON.stringify(params.data, filterNullValues),
+ }).then(({ json }) => ({
+ data: res.map(json),
+ }));
+ }
},
updateMany: (resource, params) => {