Skip to content

Commit

Permalink
Merge pull request #257 from opentween/user-tweets-and-replies
Browse files Browse the repository at this point in the history
ユーザータイムラインにリプライが含まれない不具合を修正
  • Loading branch information
upsilon authored Nov 28, 2023
2 parents 2001d4a + e0df326 commit 3708077
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,27 @@

namespace OpenTween.Api.GraphQL
{
public class UserTweetsRequestTest
public class UserTweetsAndRepliesRequestTest
{
[Fact]
public async Task Send_Test()
{
using var responseStream = File.OpenRead("Resources/Responses/UserTweets_SimpleTweet.json");
using var responseStream = File.OpenRead("Resources/Responses/UserTweetsAndReplies_SimpleTweet.json");

var mock = new Mock<IApiConnection>();
mock.Setup(x =>
x.GetStreamAsync(It.IsAny<Uri>(), It.IsAny<IDictionary<string, string>>())
)
.Callback<Uri, IDictionary<string, string>>((url, param) =>
{
Assert.Equal(new("https://twitter.com/i/api/graphql/2GIWTr7XwadIixZDtyXd4A/UserTweets"), url);
Assert.Equal(3, param.Count);
Assert.Equal("""{"userId":"40480664","count":20,"includePromotedContent":true,"withQuickPromoteEligibilityTweetFields":true,"withVoice":true,"withV2Timeline":true}""", param["variables"]);
Assert.Equal(new("https://twitter.com/i/api/graphql/YlkSUg0mRBx7-EkxCvc-bw/UserTweetsAndReplies"), url);
Assert.Equal(2, param.Count);
Assert.Equal("""{"userId":"40480664","count":20,"includePromotedContent":true,"withCommunity":true,"withVoice":true,"withV2Timeline":true}""", param["variables"]);
Assert.True(param.ContainsKey("features"));
Assert.True(param.ContainsKey("fieldToggles"));
})
.ReturnsAsync(responseStream);

var request = new UserTweetsRequest(userId: "40480664")
var request = new UserTweetsAndRepliesRequest(userId: "40480664")
{
Count = 20,
};
Expand All @@ -67,23 +66,22 @@ public async Task Send_Test()
[Fact]
public async Task Send_RequestCursor_Test()
{
using var responseStream = File.OpenRead("Resources/Responses/UserTweets_SimpleTweet.json");
using var responseStream = File.OpenRead("Resources/Responses/UserTweetsAndReplies_SimpleTweet.json");

var mock = new Mock<IApiConnection>();
mock.Setup(x =>
x.GetStreamAsync(It.IsAny<Uri>(), It.IsAny<IDictionary<string, string>>())
)
.Callback<Uri, IDictionary<string, string>>((url, param) =>
{
Assert.Equal(new("https://twitter.com/i/api/graphql/2GIWTr7XwadIixZDtyXd4A/UserTweets"), url);
Assert.Equal(3, param.Count);
Assert.Equal("""{"userId":"40480664","count":20,"includePromotedContent":true,"withQuickPromoteEligibilityTweetFields":true,"withVoice":true,"withV2Timeline":true,"cursor":"aaa"}""", param["variables"]);
Assert.Equal(new("https://twitter.com/i/api/graphql/YlkSUg0mRBx7-EkxCvc-bw/UserTweetsAndReplies"), url);
Assert.Equal(2, param.Count);
Assert.Equal("""{"userId":"40480664","count":20,"includePromotedContent":true,"withCommunity":true,"withVoice":true,"withV2Timeline":true,"cursor":"aaa"}""", param["variables"]);
Assert.True(param.ContainsKey("features"));
Assert.True(param.ContainsKey("fieldToggles"));
})
.ReturnsAsync(responseStream);

var request = new UserTweetsRequest(userId: "40480664")
var request = new UserTweetsAndRepliesRequest(userId: "40480664")
{
Count = 20,
Cursor = "aaa",
Expand Down
2 changes: 1 addition & 1 deletion OpenTween.Tests/OpenTween.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<None Update="Resources\Responses\UserByScreenName.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\UserTweets_SimpleTweet.json">
<None Update="Resources\Responses\UserTweetsAndReplies_SimpleTweet.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
],
"metadata": {
"scribeConfig": {
"page": "profileBest"
"page": "profileAll"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@

namespace OpenTween.Api.GraphQL
{
public class UserTweetsRequest
public class UserTweetsAndRepliesRequest
{
private static readonly Uri EndpointUri = new("https://twitter.com/i/api/graphql/2GIWTr7XwadIixZDtyXd4A/UserTweets");
private static readonly Uri EndpointUri = new("https://twitter.com/i/api/graphql/YlkSUg0mRBx7-EkxCvc-bw/UserTweetsAndReplies");

public string UserId { get; set; }

public int Count { get; set; } = 20;

public string? Cursor { get; set; }

public UserTweetsRequest(string userId)
public UserTweetsAndRepliesRequest(string userId)
=> this.UserId = userId;

public Dictionary<string, string> CreateParameters()
Expand All @@ -54,18 +54,15 @@ public Dictionary<string, string> CreateParameters()
{
["variables"] = "{" +
$@"""userId"":""{JsonUtils.EscapeJsonString(this.UserId)}""," +
$@"""count"":20," +
$@"""count"":{this.Count}," +
$@"""includePromotedContent"":true," +
$@"""withQuickPromoteEligibilityTweetFields"":true," +
$@"""withCommunity"":true," +
$@"""withVoice"":true," +
$@"""withV2Timeline"":true" +
(this.Cursor != null ? $@",""cursor"":""{JsonUtils.EscapeJsonString(this.Cursor)}""" : "") +
"}",
["features"] = """
{"rweb_lists_timeline_redesign_enabled":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"tweetypie_unmention_optimization_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":false,"tweet_awards_web_tipping_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_media_download_video_enabled":false,"responsive_web_enhance_cards_enabled":false}
""",
["fieldToggles"] = """
{"withAuxiliaryUserLabels":false,"withArticleRichContentState":false}
{"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"responsive_web_home_pinned_timelines_enabled":true,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"c9s_tweet_anatomy_moderator_badge_enabled":true,"tweetypie_unmention_optimization_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":false,"tweet_awards_web_tipping_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_media_download_video_enabled":false,"responsive_web_enhance_cards_enabled":false}
""",
};
}
Expand Down
3 changes: 2 additions & 1 deletion OpenTween/Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public async Task GetUserTimelineApi(bool read, UserTimelineTabModel tab, bool m
tab.UserId = user.IdStr;
}

var request = new UserTweetsRequest(userId)
var request = new UserTweetsAndRepliesRequest(userId)
{
Count = count,
Cursor = more ? tab.CursorBottom : null,
Expand All @@ -690,6 +690,7 @@ public async Task GetUserTimelineApi(bool read, UserTimelineTabModel tab, bool m
statuses = response.Tweets
.Where(x => !x.IsTombstone)
.Select(x => x.ToTwitterStatus())
.Where(x => x.User.IdStr == userId) // リプライツリーに含まれる他ユーザーのツイートを除外
.ToArray();

tab.CursorBottom = response.CursorBottom;
Expand Down

0 comments on commit 3708077

Please sign in to comment.