Skip to content
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

Merged
merged 10 commits into from
Dec 20, 2017
Merged

Better handle avatars #7498

merged 10 commits into from
Dec 20, 2017

Conversation

rullzer
Copy link
Member

@rullzer rullzer commented Dec 13, 2017

Fixes #7497
Fixes #7500

  • Do not use placeholder code to avoid flashing of the image
  • Actually delete generated avatar on displayname change
  • Refresh avatar after displayname change in settings
  • Show loading icon
  • Allow deletion of profile picture Deleting profile pictures is not possible #7500

Future work:

  • Not all letters are properly centerered

@codecov
Copy link

codecov bot commented Dec 13, 2017

Codecov Report

Merging #7498 into master will increase coverage by <.01%.
The diff coverage is 76.19%.

@@             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
Impacted Files Coverage Δ Complexity Δ
lib/private/Template/JSConfigHelper.php 0% <0%> (ø) 17 <0> (ø) ⬇️
lib/private/Avatar.php 77.65% <66.66%> (-0.56%) 46 <3> (+3)
lib/private/Server.php 81.55% <90.9%> (+0.09%) 134 <2> (ø) ⬇️

@danxuliu
Copy link
Member

danxuliu commented Dec 14, 2017

Do not use placeholder code to avoid flashing of the image

Before, if a display name was given when calling avatar(), a placeholder was shown until the avatar image was loaded; now nothing is shown until the avatar image is loaded. Maybe it would be better to replace the placeholder with a loading icon instead? The same approach could be used too when calling avatar() without giving a display name (even before this change nothing was shown in that case until the image loaded).

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

@rullzer
Copy link
Member Author

rullzer commented Dec 14, 2017

@danxuliu I'm afraid my JS and design skills are lacking here. So feel free to hack in a loading animation :)

@skjnldsv
Copy link
Member

skjnldsv commented Dec 14, 2017

@danxuliu I'm afraid my JS and design skills are lacking here. So feel free to hack in a loading animation :)

Done

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 14, 2017
@rullzer rullzer requested a review from skjnldsv December 14, 2017 09:17
@rullzer
Copy link
Member Author

rullzer commented Dec 14, 2017

Ok let get this in before it becomes to much of a mess :)

skjnldsv
skjnldsv previously approved these changes Dec 14, 2017
@@ -77,4 +77,10 @@ public function remove();
* @since 9.0.0
*/
public function getFile($size);

/**
* Is this a generated avatar
Copy link
Member

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 😉

var img = new Image();

// If the new image loads successfully set it.
img.onload = function() {
$div.show();
$div.text('');
$div.append(img);
$div.clearimageplaceholder();
Copy link
Member

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.

Copy link
Member

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.

MorrisJobke
MorrisJobke previously approved these changes Dec 14, 2017
Copy link
Member

@MorrisJobke MorrisJobke left a 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 👍

@rullzer
Copy link
Member Author

rullzer commented Dec 14, 2017

@skjnldsv you forgot to sign off ;)

@skjnldsv skjnldsv force-pushed the fix_7497 branch 2 times, most recently from 8df6129 to 4a90ff9 Compare December 14, 2017 11:21
@skjnldsv
Copy link
Member

skjnldsv commented Dec 14, 2017

Rebased and ready to 🚢

@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Dec 14, 2017
Copy link
Member

@danxuliu danxuliu left a 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

@MorrisJobke MorrisJobke added the 2. developing Work in progress label Dec 14, 2017
@juliusknorr
Copy link
Member

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.

@danxuliu
Copy link
Member

I pushed two commits to fix the issues described by @danxuliu.

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 ie8fix and hidedefault parameters are given to make app developers aware that those parameter are no longer used and that they will be removed for Nextcloud 14.

@rullzer
Copy link
Member Author

rullzer commented Dec 19, 2017

Also I am wondering if we should write a log to the console or maybe a warning when ie8fix and hidedefault parameters are given to make app developers aware that those parameter are no longer used and that they will be removed for Nextcloud 14.

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.

@rullzer
Copy link
Member Author

rullzer commented Dec 19, 2017

Failing tests are due to image mocking of the image function magic... lets see if we can somehow solve that properly :S

@rullzer
Copy link
Member Author

rullzer commented Dec 19, 2017

Fixed the tests I think

rullzer and others added 10 commits December 19, 2017 18:49
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: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 19, 2017
@rullzer
Copy link
Member Author

rullzer commented Dec 19, 2017

@danxuliu I think your comments are addressed. Can you verify?

@MorrisJobke MorrisJobke dismissed stale reviews from skjnldsv, danxuliu, and themself December 20, 2017 10:52

Changed code

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

@MorrisJobke
Copy link
Member

@danxuliu @skjnldsv @blizzz Please review

@MorrisJobke MorrisJobke merged commit dc8809e into master Dec 20, 2017
@MorrisJobke MorrisJobke deleted the fix_7497 branch December 20, 2017 11:38
@MorrisJobke MorrisJobke mentioned this pull request Jan 2, 2018
30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants