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

Commit 067d66c

Browse files
committed
Display default avatar for avatars from enterprise hosts.
Fixes #1870.
1 parent 23e48d1 commit 067d66c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/GitHub.App/ViewModels/ActorViewModel.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Windows.Media.Imaging;
33
using GitHub.Models;
4+
using GitHub.Primitives;
45
using GitHub.Services;
56

67
namespace GitHub.ViewModels
@@ -16,10 +17,30 @@ public ActorViewModel()
1617
public ActorViewModel(ActorModel model)
1718
{
1819
Login = model?.Login ?? "[unknown]";
19-
Avatar = model?.AvatarUrl != null ?
20-
new BitmapImage(new Uri(model.AvatarUrl)) :
21-
AvatarProvider.CreateBitmapImage(DefaultAvatar);
22-
AvatarUrl = model?.AvatarUrl ?? DefaultAvatar;
20+
21+
if (model?.AvatarUrl != null)
22+
{
23+
try
24+
{
25+
var uri = new Uri(model.AvatarUrl);
26+
27+
// Image requests to enterprise hosts over https always fail currently,
28+
// so just display the default avatar. See #1547.
29+
if (uri.Scheme != "https" ||
30+
uri.Host.EndsWith("githubusercontent.com", StringComparison.OrdinalIgnoreCase))
31+
{
32+
AvatarUrl = model.AvatarUrl;
33+
Avatar = new BitmapImage(new Uri(AvatarUrl));
34+
}
35+
}
36+
catch { }
37+
}
38+
39+
if (AvatarUrl == null)
40+
{
41+
Avatar = AvatarProvider.CreateBitmapImage(DefaultAvatar);
42+
AvatarUrl = DefaultAvatar;
43+
}
2344
}
2445

2546
public BitmapSource Avatar { get; set; }

0 commit comments

Comments
 (0)