diff --git a/OpenTween/Api/DataModel/TwitterUser.cs b/OpenTween/Api/DataModel/TwitterUser.cs index f5dfc1e07..971f05045 100644 --- a/OpenTween/Api/DataModel/TwitterUser.cs +++ b/OpenTween/Api/DataModel/TwitterUser.cs @@ -85,8 +85,10 @@ public class TwitterUserEntity [DataMember(Name = "profile_banner_url")] public string ProfileBannerUrl { get; set; } + // ProfileImageUrlHttps が null になる場合があるらしい + // 参照: https://sourceforge.jp/ticket/browse.php?group_id=6526&tid=33871 [DataMember(Name = "profile_image_url_https")] - public string ProfileImageUrlHttps { get; set; } + public string? ProfileImageUrlHttps { get; set; } [DataMember(Name = "protected")] public bool Protected { get; set; } @@ -120,7 +122,7 @@ public static TwitterUser CreateUnknownUser() IdStr = "0", ScreenName = "?????", Name = "Unknown User", - ProfileImageUrlHttps = "", + ProfileImageUrlHttps = null, }; } } diff --git a/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs b/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs index cc6a506aa..4d3af4eb5 100644 --- a/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs +++ b/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs @@ -75,7 +75,7 @@ static string GetText(XElement elm, string name) { IdStr = GetText(userElm, "rest_id"), Name = GetText(userLegacyElm, "name"), - ProfileImageUrlHttps = GetText(userLegacyElm, "profile_image_url_https"), + ProfileImageUrlHttps = GetTextOrNull(userLegacyElm, "profile_image_url_https"), ScreenName = GetText(userLegacyElm, "screen_name"), Protected = GetTextOrNull(userLegacyElm, "protected") == "true", Verified = GetTextOrNull(userLegacyElm, "verified") == "true", diff --git a/OpenTween/Models/PostClass.cs b/OpenTween/Models/PostClass.cs index 873e53b37..33357e731 100644 --- a/OpenTween/Models/PostClass.cs +++ b/OpenTween/Models/PostClass.cs @@ -53,7 +53,7 @@ double Latitude /// スクリーンリーダーでの読み上げを考慮したテキスト public string AccessibleText { get; init; } = ""; - public string ImageUrl { get; init; } = ""; + public string? ImageUrl { get; init; } public string ScreenName { get; init; } = ""; diff --git a/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs b/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs index c6419e41c..c23c876de 100644 --- a/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs +++ b/OpenTween/SocialProtocol/Twitter/TwitterPostFactory.cs @@ -137,7 +137,9 @@ public PostClass CreateFromStatus( // 他の発言と重複しやすい (共通化できる) 文字列は string.Intern を通す var screenName = string.Intern(originalStatusUser.ScreenName); var nickname = string.Intern(originalStatusUser.Name); - var imageUrl = string.Intern(originalStatusUser.ProfileImageUrlHttps); + var imageUrl = originalStatusUser.ProfileImageUrlHttps is { } profileImageUrl + ? string.Intern(profileImageUrl) + : null; // Source整形 var (sourceText, sourceUri) = ParseSource(originalStatus.Source); @@ -265,7 +267,9 @@ bool firstLoad // 他の発言と重複しやすい (共通化できる) 文字列は string.Intern を通す var screenName = string.Intern(displayUser.ScreenName); var nickname = string.Intern(displayUser.Name); - var imageUrl = string.Intern(displayUser.ProfileImageUrlHttps); + var imageUrl = displayUser.ProfileImageUrlHttps is { } imageUrlStr + ? string.Intern(imageUrlStr) + : null; var source = (string?)null; var sourceUri = (Uri?)null; diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index 1785a744d..7a2b5b607 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -972,8 +972,11 @@ private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCo var bText = sb.ToString(); if (MyCommon.IsNullOrEmpty(bText)) return; - var image = this.iconCache.TryGetFromCache(post.ImageUrl); - this.gh.Notify(nt, post.StatusId.Id, title.ToString(), bText, image?.Image, post.ImageUrl); + var image = post.ImageUrl is { } imageUrl + ? this.iconCache.TryGetFromCache(imageUrl) + : null; + + this.gh.Notify(nt, post.StatusId.Id, title.ToString(), bText, image?.Image); } } else diff --git a/OpenTween/TweetDetailsView.cs b/OpenTween/TweetDetailsView.cs index 9cfa79129..cfb7a4f1e 100644 --- a/OpenTween/TweetDetailsView.cs +++ b/OpenTween/TweetDetailsView.cs @@ -268,7 +268,7 @@ public HtmlElement[] GetLinkElements() .ToArray(); } - private async Task SetUserPictureAsync(string normalImageUrl, bool force = false) + private async Task SetUserPictureAsync(string? normalImageUrl, bool force = false) { if (MyCommon.IsNullOrEmpty(normalImageUrl)) return; @@ -627,7 +627,7 @@ private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e) this.ReloadIconToolStripMenuItem.Enabled = true; - if (this.IconCache.TryGetFromCache(this.CurrentPost.ImageUrl) != null) + if (this.CurrentPost.ImageUrl is { } imageUrl && this.IconCache.TryGetFromCache(imageUrl) != null) { this.SaveIconPictureToolStripMenuItem.Enabled = true; } diff --git a/OpenTween/UserInfo.cs b/OpenTween/UserInfo.cs index a725fbdd1..c23d0f265 100644 --- a/OpenTween/UserInfo.cs +++ b/OpenTween/UserInfo.cs @@ -47,14 +47,9 @@ public UserInfo(TwitterUser user) this.ScreenName = user.ScreenName; this.Location = WebUtility.HtmlDecode(user.Location); this.Description = WebUtility.HtmlDecode(user.Description); - try - { - this.ImageUrl = new Uri(user.ProfileImageUrlHttps); - } - catch (Exception) - { - this.ImageUrl = null; - } + this.ImageUrl = user.ProfileImageUrlHttps is { } imageUrlStr + ? new Uri(imageUrlStr) + : null; this.Url = user.Url ?? ""; this.Protect = user.Protected; this.FriendsCount = user.FriendsCount; diff --git a/OpenTween/UserInfoDialog.cs b/OpenTween/UserInfoDialog.cs index 9b99236e6..f720bb422 100644 --- a/OpenTween/UserInfoDialog.cs +++ b/OpenTween/UserInfoDialog.cs @@ -194,14 +194,12 @@ private async Task SetDescriptionAsync(string? descriptionText, TwitterEntities? } } - private async Task SetUserImageAsync(string imageUri, CancellationToken cancellationToken) + private async Task SetUserImageAsync(string? imageUri, CancellationToken cancellationToken) { var oldImage = this.UserPicture.Image; this.UserPicture.Image = null; oldImage?.Dispose(); - // ProfileImageUrlHttps が null になる場合があるらしい - // 参照: https://sourceforge.jp/ticket/browse.php?group_id=6526&tid=33871 if (imageUri == null) return; @@ -468,6 +466,9 @@ private async void ButtonSearchPosts_Click(object sender, EventArgs e) private async void UserPicture_Click(object sender, EventArgs e) { var imageUrl = this.displayUser.ProfileImageUrlHttps; + if (imageUrl == null) + return; + imageUrl = TwitterLegacy.CreateProfileImageUrl(imageUrl, "original"); await MyCommon.OpenInBrowserAsync(this, imageUrl);