Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Conversation

@grokys
Copy link
Contributor

@grokys grokys commented Aug 22, 2018

Image requests to enterprise hosts over https always fail currently, so just display the default avatar (see #1547).

This was already fixed for the REST portion of the application in #1579 by remembering which hosts image downloads have already failed for and making sure not to try again, however the framework of AvatarProvider/ImageCache/ImageDownloader used there assumes a fixed image size of 32x32, causing #1603.

The whole thing needs a major revamp, which is a little tricky while we're still using a combination of REST and GraphQL, so for the moment just don't try to download images from enterprise hosts that are using https: this should be OK because this will currently never work anyway.

Fixes #1870.

@meaghanlewis
Copy link
Contributor

LGTM. Thanks for fixing this!

Copy link
Collaborator

@jcansdale jcansdale left a comment

Choose a reason for hiding this comment

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

Is this potentially swallowing exceptions unnecessarily?

AvatarProvider.CreateBitmapImage(DefaultAvatar);
AvatarUrl = model?.AvatarUrl ?? DefaultAvatar;

if (model?.AvatarUrl != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I find the new if (model?.AvatarUrl is string avatarUrl) syntax more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, what do you find more readable about that? I use the new syntax a lot, but only when a cast is involved. AvatarUrl is already typed to string so there is no cast, and so it's just a comparison with null...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just find that it reads well in my head: "if model?.AvatarUrl is a string then call it avatarUrl and do stuff with it".

Maybe I'm a little over obsessive about putting things in variables. Previously I'd have been inclined to do:

var avatarUrl = model?.AvatarUrl;
if (avatarUrl != null)
{
    ...
}

I'm now happy with the conciseness and expressiveness of if (model?.AvatarUrl is string avatarUrl). I know you can also do if (model?.AvatarUrl is var avatarUrl), but is var looks a little strange to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I dunno... The problem for me with "if model?.AvatarUrl is a string then call it avatarUrl and do stuff with it" is that it's always a string. That pattern should be used for casting IMO, not just checking for null, and it surprises me when there isn't actually a cast.

Copy link
Collaborator

@jcansdale jcansdale Aug 23, 2018

Choose a reason for hiding this comment

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

Do you think if (model?.AvatarUrl is var avatarUrl) is any better because it's more obvious that is var isn't a cast?

Avatar = new BitmapImage(new Uri(AvatarUrl));
}
}
catch { }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the catch { } required with the above url checks? If I'm reading it correctly, an exception here would be unexpected and we should log it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the catch is in case the URL is somehow an invalid format. And yes we should probably be logging that ;)

@grokys grokys merged commit d8980c3 into master Aug 23, 2018
@grokys grokys deleted the fixes/1870-enterprise-avatars branch August 23, 2018 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No user avatars displayed for enterprise repositories

4 participants