-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose user avatar URL field in the UI #61
base: master
Are you sure you want to change the base?
Conversation
To be able to change a avatar the URL field needs to be exposed but changing the URL alone is difficult. This patch adds a image upload field to the edit view of a user. If there is a file detected it uploads it to the servers media repository and sets that new URL as the avatar URL one. This way a admin can change any users avatar which is especially nice for bridged users like in the IRC bridge and bots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments.
@@ -32,6 +32,7 @@ const resourceMap = { | |||
...u, | |||
id: u.name, | |||
avatar_src: mxcUrlToHttp(u.avatar_url), | |||
avatar_url: u.avatar_url, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implicitly handled by line 32
|
||
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the update
function pretty complicated. I suggest to add another function upload
to the DataProvider and use it directly in the UserEdit component (https://marmelab.com/react-admin/Actions.html#usedataprovider-hook). Then you can upload the file directly when it's selected and provide appropriate feedback (e.g. file is too large).
is this (or something similar likely to be implemented? it's a nice quality-of-life enhancement, imo |
To be able to change a avatar the URL field needs to be exposed but changing the URL alone is difficult. This patch adds a image upload field to the edit view of a user. If there is a file detected it uploads it to the servers media repository and sets that new URL as the avatar URL one. This way a admin can change any users avatar which is especially nice for bridged users like in the IRC bridge and bots.
Fixes #60