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
Profile picture generation in the frontend #1202
Comments
First of all, I would recommend that we look into full libravatar support (including federated avatars) as well as providing a avatar generator in HedgeDoc itself. Here we can benefit from the work I did for Libravatar this year: https://git.linux-kernel.at/oliver/ivatar/-/issues/72 Edit: Sorry for the mess here, my browser decided that buttons and text fields shouldn't have the same "action area" as their display representation. |
If this issue is just about anonymous users, how does libravatar support help here? Both dicebear and jdenticon look suitable to deterministically generate a profile picture from the random ID we have for each anonymous user, although dicebear seems to be a bit more actively maintained. |
I misunderstood the issue to be about replacing the existing endpoint which covers more than just anonymous users. However my pointer was towards similar efforts, avatar generation, on libravatar's side, so we don't have to do the whole library research ourselves. And while libravatar seems to require an email address, since the backend isn't aware what was passed through the md5 or sha256 function, it can work with any string (besides that libravatar itself usually requires either an e-mail address or an OpenID identifier when you want to benefit from accounts or federated discovery, but that's not important now). |
@ErikMichelson and myself had an idea: |
Okay, so we need to:
|
Which part of the project should be enhanced?
user service, photo generation
Is your enhancement request related to a problem? Please describe.
We need to create photos for user that don't have any.
In 1.x we did it this way (thanks to @ErikMichelson for the disection):
HedgeDoc 1.x uses three places where (sometimes different) avatar images are used:
There is no possibility to upload an own avatar to HedgeDoc 1.x, however the image to use is determined like this:
When a user account is created, the profile data of the external provider (usually the OAuth2 /userinfo endpoint) is stringified into the
profile
column of the database. Local (email) users have an emptyprofile
.The
/me
route as well as the realtime code responsible for extracting the user that last changed a note both call thegetProfile
method of an User object, that tries to parse the databaseprofile
column and then determines the profile picture from that as following:profile.provider
is set to an auth provider that serves the profile pictures of the user. In that case this will be just taken. (Applies to Facebook, Twitter, GitHub, GitLab, Mattermost, Google)profile.provider
is set to an auth provider that does not serve the users' profile picture OR the user has no profile picture on one of the previous providers ORprofile.provider
is not set. In that casegenerateAvatarURL
method is called, which does the following differentiation:profile.email
) ANDconfig.allowGravatar
is enabled. In that case the email address is md5'ed and given to Libravatar for retrieving the picture.config.allowGravatar
is enabled. In that case the username is prepended before "@example.com" and given to Libravatar./user/<username>/avatar.svg
is returned.<username>
in this case is either the localpart of the email address or the username if no email is set or the md5 hash of the email address (WHY?).The API route mentioned above does the following:
The status list icon inside the editor only checks if a user from the list of users returned by the websocket action
online users
contains aphoto
property (which it only does if the login provider has provided one, seeupdateUserData
method). If so, it takes this, otherwise it uses a randomly generated color as background-image for the profile picture placeholder container.Describe the solution you'd like
Generating a data-URI with a svg in it, that shall be used for logged-in users without an image.
Anonymous users could, just give themselves (or rather the frontend give sthem) a random name and a random color. This way the could be clearly distinguished from logged-in users.
It seems reasonable to include a deterministic way of generating images, so a user always get's the same image. As such it probably should be based on the
userName
, because that won't change for a user…Also we probably won't want to build our own image generation lib, because there are ton out there.
@mrdrogdrog suggested using either
https://avatars.dicebear.com/ with human, avataaars or bottts (see Licenses)
or
https://jdenticon.com/, possibly limiting ourselves to the hedgedoc color scheme (see here)
Describe alternatives you've considered
Eh. I don't know.
Additional context
Relevant code segments (1.x Code)
hedgedoc/lib/web/userRouter.js
Line 125 in dcf7214
hedgedoc/lib/letter-avatars.js
Line 8 in dcf7214
hedgedoc/lib/letter-avatars.js
Line 28 in dcf7214
hedgedoc/lib/models/user.js
Line 93 in dcf7214
hedgedoc/public/js/cover.js
Line 74 in dcf7214
hedgedoc/public/js/index.js
Line 2753 in dcf7214
hedgedoc/public/js/extra.js
Line 73 in dcf7214
The text was updated successfully, but these errors were encountered: