-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Better handle avatars #7498
Better handle avatars #7498
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7498 +/- ##
============================================
+ Coverage 51.16% 51.17% +<.01%
- Complexity 24883 24886 +3
============================================
Files 1602 1602
Lines 94730 94750 +20
Branches 1368 1368
============================================
+ Hits 48470 48485 +15
- Misses 46260 46265 +5
|
Before, if a display name was given when calling Also, if the problem is the flash caused when the placeholder is replaced by the image, another option could be to show the placeholder and then, when the image is loaded, fade out the placeholder and fade in the image. Or maybe both, I mean, show the loading icon instead of the placeholder and also fade out the loading icon while fading in the avatar image once it is loaded (although as the animation should be pretty short it could end causing a flash anyway...). In any case, with the current code if a display name is given and the avatar image fails to load no avatar is shown at all, but if no display name is given and the avatar image fails to load then a placeholder is shown; at the very least the behaviour should be the same in both cases. @nextcloud/designers |
@danxuliu I'm afraid my JS and design skills are lacking here. So feel free to hack in a loading animation :) |
Done |
Ok let get this in before it becomes to much of a mess :) |
lib/public/IAvatar.php
Outdated
@@ -77,4 +77,10 @@ public function remove(); | |||
* @since 9.0.0 | |||
*/ | |||
public function getFile($size); | |||
|
|||
/** | |||
* Is this a generated avatar |
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.
It looks like the comment is wrong 😉
core/js/jquery.avatar.js
Outdated
var img = new Image(); | ||
|
||
// If the new image loads successfully set it. | ||
img.onload = function() { | ||
$div.show(); | ||
$div.text(''); | ||
$div.append(img); | ||
$div.clearimageplaceholder(); |
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.
I guess this is then also not needed anymore.
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.
Yes it is because the div is cleared with the loading class as well
I think it could also interfer with the uploading of a new avatar.
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.
Code makes sense, tested and works 👍
@skjnldsv you forgot to sign off ;) |
8df6129
to
4a90ff9
Compare
Rebased and ready to 🚢 |
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.
The loading icon should be shown too when avatar()
is called without a display name.
If a display name is given and the avatar image fails to load no avatar is shown at all, but if no display name is given and the avatar image fails to load then a placeholder is shown; the behaviour should be the same in both cases.
In the user settings the button to delete the avatar image is shown even if the image was auto-generated, and removing the auto-generated image just recreates it again, so it looks like nothing happened when clicking the button (except for a loading icon being shown). However I do not know if we have any way to distinguish between a user uploaded image and an auto-generated image in the avatars... @rullzer
I pushed two commits to fix the issues described by @danxuliu. I reduced the complexity of the avatar function quite a bit. We don't rely on the displayname for avatar placeholders anymore, therefore we can totally get rid of the old code path for placeholder generation. Also for setups without gd installed i keep generating the placeholder in case there is a displayname provided to the avatar plugin. |
Nice, thanks! :-D But... unsigned commit (first one) and failing tests :-) And another detail: the callback should be called too when an error happens (like it was done in the old code path). Also I am wondering if we should write a log to the console or maybe a warning when |
Sure. But this will have to go into a list of breaking changes as it forces app that use this to move to a NC14 only version. But fine by me. |
Failing tests are due to image mocking of the image function magic... lets see if we can somehow solve that properly :S |
Fixed the tests I think |
The js and php code differ ever so slightly. So having the placeholder for a second and then the image is just weird. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
With the new avatar endpoint there is no difference between unknown users and errors when generating the placeholder avatar. Therefore the avatar function will now show the old placeholder if both a user and displayname was given as parameters. In case there is no displayname provided we cannot build the proper placeholder so the unknown user placeholder is shown. The displayname is not required for the avatar anymore, so we can get rid of the old code path for placeholders. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1c04131
to
0ff3c81
Compare
@danxuliu I think your comments are addressed. Can you verify? |
Changed code
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.
Tested and works 👍
Fixes #7497
Fixes #7500
Future work: