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

Commit d9de8f6

Browse files
More tweaks and fixes
1 parent de8da0d commit d9de8f6

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

src/GitHub.App/Models/SuggestionItem.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ namespace GitHub.Models
1010
/// </summary>
1111
public class SuggestionItem
1212
{
13-
public SuggestionItem() // So this can be deserialized from cache
14-
{
15-
}
16-
17-
public SuggestionItem(string name, Uri iconCacheKey)
18-
{
19-
Guard.ArgumentNotEmptyString(name, "name");
20-
Guard.ArgumentNotNull(iconCacheKey, "iconCacheKey");
21-
22-
Name = name;
23-
IconKey = iconCacheKey;
24-
}
25-
2613
public SuggestionItem(string name, string description)
2714
{
2815
Guard.ArgumentNotEmptyString(name, "name");
@@ -32,14 +19,13 @@ public SuggestionItem(string name, string description)
3219
Description = description;
3320
}
3421

35-
public SuggestionItem(string name, string description, Uri iconCacheKey)
22+
public SuggestionItem(string name, string description, string imageUrl)
3623
{
3724
Guard.ArgumentNotEmptyString(name, "name");
38-
Guard.ArgumentNotNull(iconCacheKey, "iconCacheKey");
3925

4026
Name = name;
4127
Description = description;
42-
IconKey = iconCacheKey;
28+
ImageUrl = imageUrl;
4329
}
4430

4531
/// <summary>
@@ -53,9 +39,9 @@ public SuggestionItem(string name, string description, Uri iconCacheKey)
5339
public string Description { get; set; }
5440

5541
/// <summary>
56-
/// A key to lookup when displaying the icon for this entry
42+
/// An image url for this entry
5743
/// </summary>
58-
public Uri IconKey { get; set; }
44+
public string ImageUrl { get; set; }
5945

6046
/// <summary>
6147
/// The date this suggestion was last modified according to the API.

src/GitHub.App/Services/IssuesAutoCompleteSource.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public IObservable<AutoCompleteSuggestion> GetSuggestions()
4545
.Select(repository =>
4646
repository.Issues(null, null, null, null, null, null, null)
4747
.AllPages()
48-
.Select(issue => new SuggestionItem("#" + issue.Number, issue.Title))
48+
.Select(issue => new SuggestionItem("#" + issue.Number, issue.Title)
49+
{
50+
LastModifiedDate = issue.LastEditedAt
51+
})
4952
.ToList())
5053
.Compile();
5154
}

src/GitHub.App/Services/MentionsAutoCompleteSource.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace GitHub.Services
2222
[PartCreationPolicy(CreationPolicy.Shared)]
2323
public class MentionsAutoCompleteSource : IAutoCompleteSource
2424
{
25+
const string DefaultAvatar = "pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png";
26+
2527
readonly ITeamExplorerContext teamExplorerContext;
2628
readonly IGraphQLClientFactory graphqlFactory;
2729
readonly IAvatarProvider avatarProvider;
@@ -58,7 +60,7 @@ public IObservable<AutoCompleteSuggestion> GetSuggestions()
5860
.Select(sourceItem =>
5961
new SuggestionItem(sourceItem.Login,
6062
sourceItem.Name ?? "(unknown)",
61-
GetUrlSafe(sourceItem.AvatarUrl(null))))
63+
sourceItem.AvatarUrl(null)))
6264
.ToList())
6365
.Compile();
6466
}
@@ -75,20 +77,21 @@ public IObservable<AutoCompleteSuggestion> GetSuggestions()
7577
var suggestions = await connection.Run(query, variables);
7678
return suggestions.Select(suggestion => new AutoCompleteSuggestion(suggestion.Name,
7779
suggestion.Description,
78-
ResolveImage(suggestion.IconKey.ToString()),
80+
ResolveImage(suggestion),
7981
Prefix));
8082
}).SelectMany(enumerable => enumerable);
8183
}
8284

83-
private IObservable<BitmapSource> ResolveImage(string uri) => avatarProvider.GetAvatar(uri);
84-
85-
public string Prefix => "@";
86-
87-
static Uri GetUrlSafe(string url)
85+
IObservable<BitmapSource> ResolveImage(SuggestionItem uri)
8886
{
89-
Uri uri;
90-
Uri.TryCreate(url, UriKind.Absolute, out uri);
91-
return uri;
87+
if (uri.ImageUrl != null)
88+
{
89+
return avatarProvider.GetAvatar(uri.ImageUrl);
90+
}
91+
92+
return Observable.Return(AvatarProvider.CreateBitmapImage(DefaultAvatar));
9293
}
94+
95+
public string Prefix => "@";
9396
}
9497
}

0 commit comments

Comments
 (0)