From 9353251b3f7c6c34fc301a45fe663cd27af4d875 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Sat, 2 Dec 2023 16:31:20 +0900 Subject: [PATCH] =?UTF-8?q?display=5Furl,=20expanded=5Furl=20=E3=81=AE?= =?UTF-8?q?=E4=B8=8D=E8=B6=B3=E3=81=97=E3=81=9FEntity=E3=81=A7=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=AB=E3=81=AA=E3=82=8B=E4=B8=8D=E5=85=B7?= =?UTF-8?q?=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://egg.5ch.net/test/read.cgi/software/1700747346/50-52n --- CHANGELOG.txt | 2 + .../Api/GraphQL/TwitterGraphqlUserTest.cs | 15 +++ OpenTween.Tests/OpenTween.Tests.csproj | 3 + .../User_EntityWithoutDisplayUrl.json | 125 ++++++++++++++++++ OpenTween/Api/GraphQL/TimelineTweet.cs | 4 +- OpenTween/Api/GraphQL/TwitterGraphqlUser.cs | 8 +- 6 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 OpenTween.Tests/Resources/Responses/User_EntityWithoutDisplayUrl.json diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 278e8e472..41d29e9b1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,8 @@ * NEW: graphqlエンドポイントに対するレートリミットの表示に対応 * CHG: タイムライン更新時に全件ではなく新着投稿のみ差分を取得する動作に変更 * FIX: 設定したタイムアウト時間を超えてAPI接続が持続する場合がある不具合を修正 + * FIX: プロフィール情報のURL欄のパースに失敗する場合がある不具合を修正 + - この問題が起きるユーザーのツイートが含まれているとタイムラインの読み込みに失敗する問題も改善されます ==== Ver 3.8.0(2023/11/29) * NEW: graphqlエンドポイントを使用した検索タイムラインの取得に対応 diff --git a/OpenTween.Tests/Api/GraphQL/TwitterGraphqlUserTest.cs b/OpenTween.Tests/Api/GraphQL/TwitterGraphqlUserTest.cs index 5448ecc76..c88b53e17 100644 --- a/OpenTween.Tests/Api/GraphQL/TwitterGraphqlUserTest.cs +++ b/OpenTween.Tests/Api/GraphQL/TwitterGraphqlUserTest.cs @@ -51,5 +51,20 @@ public void ToTwitterUser_Test() Assert.Equal("514241801", user.IdStr); Assert.Equal("opentween", user.ScreenName); } + + [Fact] + public void ToTwitterUser_EntityWithoutDisplayUrlTest() + { + var userElm = this.LoadResponseDocument("User_EntityWithoutDisplayUrl.json"); + var graphqlUser = new TwitterGraphqlUser(userElm); + var user = graphqlUser.ToTwitterUser(); + + Assert.Equal("4104111", user.IdStr); + var urlEntity = user.Entities?.Url?.Urls.First()!; + Assert.Equal("http://earthquake.transrain.net/", urlEntity.Url); + Assert.Equal(new[] { 0, 32 }, urlEntity.Indices); + Assert.Null(urlEntity.DisplayUrl); + Assert.Null(urlEntity.ExpandedUrl); + } } } diff --git a/OpenTween.Tests/OpenTween.Tests.csproj b/OpenTween.Tests/OpenTween.Tests.csproj index e4472eafe..f9444e3b6 100644 --- a/OpenTween.Tests/OpenTween.Tests.csproj +++ b/OpenTween.Tests/OpenTween.Tests.csproj @@ -100,6 +100,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/OpenTween.Tests/Resources/Responses/User_EntityWithoutDisplayUrl.json b/OpenTween.Tests/Resources/Responses/User_EntityWithoutDisplayUrl.json new file mode 100644 index 000000000..56e515d12 --- /dev/null +++ b/OpenTween.Tests/Resources/Responses/User_EntityWithoutDisplayUrl.json @@ -0,0 +1,125 @@ +{ + "__typename": "User", + "id": "VXNlcjo0MTA0MTEx", + "rest_id": "4104111", + "affiliates_highlighted_label": { + "label": { + "badge": { + "url": "https://pbs.twimg.com/semantic_core_img/1428827730364096519/4ZXpTBhS?format=png&name=orig" + }, + "description": "Automated", + "longDescription": { + "text": "Automated by @ariela", + "entities": [ + { + "fromIndex": 13, + "toIndex": 20, + "ref": { + "type": "TimelineRichTextMention", + "screen_name": "ariela", + "mention_results": { + "result": { + "__typename": "User", + "legacy": { + "screen_name": "ariela" + }, + "rest_id": "3486871" + } + } + } + } + ] + }, + "userLabelType": "AutomatedLabel" + } + }, + "has_graduated_access": true, + "is_blue_verified": true, + "profile_image_shape": "Circle", + "legacy": { + "can_dm": false, + "can_media_tag": false, + "created_at": "Wed Apr 11 01:33:52 +0000 2007", + "default_profile": false, + "default_profile_image": false, + "description": "警戒:震度1以上 もしくは M3以上の地震情報を提供しています。 基本的に返事は行いません。問い合わせは@ariela もしくはyuki at https://t.co/DrMBNu9mAfにどうぞ。 非公式RTを繰り返すBOTはブロックします。", + "entities": { + "description": { + "urls": [ + { + "display_url": "transrain.net", + "expanded_url": "http://transrain.net", + "url": "https://t.co/DrMBNu9mAf", + "indices": [ + 72, + 95 + ] + } + ] + }, + "url": { + "urls": [ + { + "url": "http://earthquake.transrain.net/", + "indices": [ + 0, + 32 + ] + } + ] + } + }, + "fast_followers_count": 0, + "favourites_count": 1, + "followers_count": 3219441, + "friends_count": 5, + "has_custom_timelines": false, + "is_translator": false, + "listed_count": 44208, + "location": "", + "media_count": 0, + "name": "地震速報", + "normal_followers_count": 3219441, + "pinned_tweet_ids_str": [ + "1623494931666046977" + ], + "possibly_sensitive": false, + "profile_image_url_https": "https://pbs.twimg.com/profile_images/368358807/eqjp_normal.png", + "profile_interstitial_type": "", + "screen_name": "earthquake_jp", + "statuses_count": 59090, + "translator_type": "none", + "url": "http://earthquake.transrain.net/", + "verified": false, + "want_retweets": false, + "withheld_in_countries": [] + }, + "smart_blocked_by": false, + "smart_blocking": false, + "legacy_extended_profile": {}, + "is_profile_translatable": true, + "verification_info": { + "reason": { + "description": { + "text": "This account is verified. Learn more", + "entities": [ + { + "from_index": 26, + "to_index": 36, + "ref": { + "url": "https://help.twitter.com/managing-your-account/about-twitter-verified-accounts", + "url_type": "ExternalUrl" + } + } + ] + }, + "verified_since_msec": "1682244679134" + } + }, + "highlights_info": { + "can_highlight_tweets": true, + "highlighted_tweets": "0" + }, + "business_account": {}, + "creator_subscriptions_count": 0 +} diff --git a/OpenTween/Api/GraphQL/TimelineTweet.cs b/OpenTween/Api/GraphQL/TimelineTweet.cs index 375a87d1c..dd20e3401 100644 --- a/OpenTween/Api/GraphQL/TimelineTweet.cs +++ b/OpenTween/Api/GraphQL/TimelineTweet.cs @@ -138,8 +138,8 @@ static string GetText(XElement elm, string name) .Select(x => new TwitterEntityUrl() { Indices = x.XPathSelectElements("indices/item").Select(x => int.Parse(x.Value)).ToArray(), - DisplayUrl = GetText(x, "display_url"), - ExpandedUrl = GetText(x, "expanded_url"), + DisplayUrl = GetTextOrNull(x, "display_url"), + ExpandedUrl = GetTextOrNull(x, "expanded_url"), Url = GetText(x, "url"), }) .ToArray(), diff --git a/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs b/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs index 96ab805c1..22221b646 100644 --- a/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs +++ b/OpenTween/Api/GraphQL/TwitterGraphqlUser.cs @@ -96,8 +96,8 @@ static string GetText(XElement elm, string name) .Select(x => new TwitterEntityUrl() { Indices = x.XPathSelectElements("indices/item").Select(x => int.Parse(x.Value)).ToArray(), - DisplayUrl = GetText(x, "display_url"), - ExpandedUrl = GetText(x, "expanded_url"), + DisplayUrl = GetTextOrNull(x, "display_url"), + ExpandedUrl = GetTextOrNull(x, "expanded_url"), Url = GetText(x, "url"), }) .ToArray(), @@ -108,8 +108,8 @@ static string GetText(XElement elm, string name) .Select(x => new TwitterEntityUrl() { Indices = x.XPathSelectElements("indices/item").Select(x => int.Parse(x.Value)).ToArray(), - DisplayUrl = GetText(x, "display_url"), - ExpandedUrl = GetText(x, "expanded_url"), + DisplayUrl = GetTextOrNull(x, "display_url"), + ExpandedUrl = GetTextOrNull(x, "expanded_url"), Url = GetText(x, "url"), }) .ToArray(),