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

Commit 20453cb

Browse files
author
Meaghan Lewis
authored
Merge branch 'master' into fixes/1305-better-failures
2 parents fb726dd + d8980c3 commit 20453cb

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/GitHub.App/ViewModels/ActorViewModel.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using System;
22
using System.Windows.Media.Imaging;
3+
using GitHub.Logging;
34
using GitHub.Models;
5+
using GitHub.Primitives;
46
using GitHub.Services;
7+
using Serilog;
58

69
namespace GitHub.ViewModels
710
{
811
public class ActorViewModel : ViewModelBase, IActorViewModel
912
{
1013
const string DefaultAvatar = "pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png";
14+
static readonly ILogger log = LogManager.ForContext<ActorViewModel>();
1115

1216
public ActorViewModel()
1317
{
@@ -16,10 +20,33 @@ public ActorViewModel()
1620
public ActorViewModel(ActorModel model)
1721
{
1822
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;
23+
24+
if (model?.AvatarUrl != null)
25+
{
26+
try
27+
{
28+
var uri = new Uri(model.AvatarUrl);
29+
30+
// Image requests to enterprise hosts over https always fail currently,
31+
// so just display the default avatar. See #1547.
32+
if (uri.Scheme != "https" ||
33+
uri.Host.EndsWith("githubusercontent.com", StringComparison.OrdinalIgnoreCase))
34+
{
35+
AvatarUrl = model.AvatarUrl;
36+
Avatar = new BitmapImage(uri);
37+
}
38+
}
39+
catch (Exception ex)
40+
{
41+
log.Error(ex, "Invalid avatar URL");
42+
}
43+
}
44+
45+
if (AvatarUrl == null)
46+
{
47+
Avatar = AvatarProvider.CreateBitmapImage(DefaultAvatar);
48+
AvatarUrl = DefaultAvatar;
49+
}
2350
}
2451

2552
public BitmapSource Avatar { get; set; }

0 commit comments

Comments
 (0)