Skip to content

Commit

Permalink
display_url, expanded_url の不足したEntityでエラーになる不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Dec 2, 2023
1 parent a83f2bf commit 9353251
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* NEW: graphqlエンドポイントに対するレートリミットの表示に対応
* CHG: タイムライン更新時に全件ではなく新着投稿のみ差分を取得する動作に変更
* FIX: 設定したタイムアウト時間を超えてAPI接続が持続する場合がある不具合を修正
* FIX: プロフィール情報のURL欄のパースに失敗する場合がある不具合を修正
- この問題が起きるユーザーのツイートが含まれているとタイムラインの読み込みに失敗する問題も改善されます

==== Ver 3.8.0(2023/11/29)
* NEW: graphqlエンドポイントを使用した検索タイムラインの取得に対応
Expand Down
15 changes: 15 additions & 0 deletions OpenTween.Tests/Api/GraphQL/TwitterGraphqlUserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 3 additions & 0 deletions OpenTween.Tests/OpenTween.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<None Update="Resources\Responses\UserByScreenName_Suspended.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\User_EntityWithoutDisplayUrl.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\User_Simple.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
125 changes: 125 additions & 0 deletions OpenTween.Tests/Resources/Responses/User_EntityWithoutDisplayUrl.json
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions OpenTween/Api/GraphQL/TimelineTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions OpenTween/Api/GraphQL/TwitterGraphqlUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 9353251

Please sign in to comment.