Skip to content

Commit

Permalink
Merge pull request #238 from opentween/fix-self-thread
Browse files Browse the repository at this point in the history
SelfThreadのツイートを取得できない不具合を修正
  • Loading branch information
upsilon authored Jul 19, 2023
2 parents 8f0a33f + bd9b5fa commit f76e0e3
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

==== Unreleased
* FIX: Cookie使用時に複数回ツイートを投稿するとDelaying?のエラーが表示される不具合を修正
* FIX: 自己リプライのスレッドに含まれるツイートを発言一覧で選択するとエラーが発生する不具合を修正

==== Ver 3.7.0(2023/07/19)
* NEW: Cookie使用時のツイート投稿・削除に対応
Expand Down
13 changes: 13 additions & 0 deletions OpenTween.Tests/Api/GraphQL/TimelineTweetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,18 @@ public void ToStatus_WithTwitterPostFactory_TweetWithVisibility_Test()
Assert.Equal("1602775353088524288", post.StatusId.Id);
Assert.Equal(357750891L, post.UserId);
}

[Fact]
public void ToStatus_WithTwitterPostFactory_SelfThread_Test()
{
var rootElm = this.LoadResponseDocument("TimelineTweet_SelfThread.json");
var timelineTweet = new TimelineTweet(rootElm);
var status = timelineTweet.ToTwitterStatus();
var postFactory = new TwitterPostFactory(this.CreateTabInfo());
var post = postFactory.CreateFromStatus(status, selfUserId: 1L, new HashSet<long>());

Assert.Equal("1511751702684499968", post.StatusId.Id);
Assert.Equal(40480664L, post.UserId);
}
}
}
3 changes: 3 additions & 0 deletions OpenTween.Tests/OpenTween.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
<None Update="Resources\Responses\TweetDetail.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\TimelineTweet_SelfThread.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
124 changes: 124 additions & 0 deletions OpenTween.Tests/Resources/Responses/TimelineTweet_SelfThread.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"itemType": "TimelineTweet",
"__typename": "TimelineTweet",
"tweet_results": {
"result": {
"__typename": "Tweet",
"rest_id": "1511751702684499968",
"has_birdwatch_notes": false,
"core": {
"user_results": {
"result": {
"__typename": "User",
"id": "VXNlcjo0MDQ4MDY2NA==",
"rest_id": "40480664",
"affiliates_highlighted_label": {},
"has_graduated_access": true,
"is_blue_verified": false,
"profile_image_shape": "Circle",
"legacy": {
"followed_by": true,
"following": true,
"can_dm": true,
"can_media_tag": true,
"created_at": "Sat May 16 15:20:01 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "OpenTween Project 言い出しっぺ",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "m.upsilo.net/@upsilon",
"expanded_url": "https://m.upsilo.net/@upsilon",
"url": "https://t.co/vNMmyHHOQD",
"indices": [
0,
23
]
}
]
}
},
"fast_followers_count": 0,
"favourites_count": 216205,
"followers_count": 1304,
"friends_count": 917,
"has_custom_timelines": false,
"is_translator": false,
"listed_count": 92,
"location": "Funabashi, Chiba, Japan",
"media_count": 1040,
"name": "upsilon",
"normal_followers_count": 1304,
"pinned_tweet_ids_str": [],
"possibly_sensitive": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/40480664/1349188016",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/719076434/____normal.png",
"profile_interstitial_type": "",
"screen_name": "kim_upsilon",
"statuses_count": 10096,
"translator_type": "regular",
"url": "https://t.co/vNMmyHHOQD",
"verified": false,
"want_retweets": true,
"withheld_in_countries": []
}
}
}
},
"edit_control": {
"edit_tweet_ids": [
"1511751702684499968"
],
"editable_until_msecs": "1649266467565",
"is_edit_eligible": true,
"edits_remaining": "5"
},
"edit_perspective": {
"favorited": false,
"retweeted": false
},
"is_translatable": true,
"views": {
"state": "Enabled"
},
"source": "<a href=\"https://www.opentween.org/\" rel=\"nofollow\">OpenTween (dev)</a>",
"legacy": {
"bookmark_count": 0,
"bookmarked": false,
"created_at": "Wed Apr 06 17:04:27 +0000 2022",
"conversation_id_str": "1511751702684499968",
"display_text_range": [
0,
45
],
"entities": {
"user_mentions": [],
"urls": [],
"hashtags": [],
"symbols": []
},
"favorite_count": 1,
"favorited": false,
"full_text": "OpenTweenそろそろ次のリリースしたいんだけど今のAPI規制下で出してもねえ、という",
"is_quote_status": false,
"lang": "ja",
"quote_count": 0,
"reply_count": 1,
"retweet_count": 0,
"retweeted": false,
"user_id_str": "40480664",
"id_str": "1511751702684499968"
},
"quick_promote_eligibility": {
"eligibility": "IneligibleNotProfessional"
}
}
},
"tweetDisplayType": "SelfThread",
"hasModeratedReplies": false
}
2 changes: 1 addition & 1 deletion OpenTween/Api/GraphQL/TimelineTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static Exception CreateParseError()

public static TimelineTweet[] ExtractTimelineTweets(XElement element)
{
return element.XPathSelectElements($"//itemContent[itemType[text()='{TypeName}']][tweetDisplayType[text()='Tweet']]")
return element.XPathSelectElements($"//itemContent[itemType[text()='{TypeName}']][tweetDisplayType[text()='Tweet' or text()='SelfThread']]")
.Select(x => new TimelineTweet(x))
.ToArray();
}
Expand Down
4 changes: 3 additions & 1 deletion OpenTween/Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ public async Task<PostClass> GetStatusApi(bool read, TwitterStatusId id)
FocalTweetId = id,
};
var tweets = await request.Send(this.Api.Connection).ConfigureAwait(false);
status = tweets.Select(x => x.ToTwitterStatus()).Where(x => x.IdStr == id.Id).First();
status = tweets.Select(x => x.ToTwitterStatus())
.Where(x => x.IdStr == id.Id)
.FirstOrDefault() ?? throw new WebApiException("Empty result set");
}
else
{
Expand Down

0 comments on commit f76e0e3

Please sign in to comment.