Expose user avatar URL field in the UI#61
Open
jeena wants to merge 1 commit intoAwesome-Technologies:masterfrom
Open
Expose user avatar URL field in the UI#61jeena wants to merge 1 commit intoAwesome-Technologies:masterfrom
jeena wants to merge 1 commit intoAwesome-Technologies:masterfrom
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.
awesome-manuel
requested changes
Aug 17, 2020
| ...u, | ||
| id: u.name, | ||
| avatar_src: mxcUrlToHttp(u.avatar_url), | ||
| avatar_url: u.avatar_url, |
Member
There was a problem hiding this comment.
This is implicitly handled by line 32
Comment on lines
+206
to
+230
|
|
||
| // 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 { |
Member
There was a problem hiding this comment.
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 |
4624efc to
e6228d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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