Skip to content

Commit

Permalink
Merge pull request #222 from opentween/fix-tweet-with-visibility
Browse files Browse the repository at this point in the history
リプライ制限されたツイートのRTがParseTweetでエラーになる不具合の修正
  • Loading branch information
upsilon authored Jul 6, 2023
2 parents 1ad40af + 6bfccee commit 8421350
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 14 additions & 9 deletions OpenTween/Api/GraphQL/TimelineTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ public TwitterStatus ToTwitterStatus()
try
{
var resultElm = this.Element.Element("tweet_results")?.Element("result") ?? throw CreateParseError();
var tweetElm = resultElm.Element("__typename")?.Value switch
{
"Tweet" => resultElm,
"TweetWithVisibilityResults" => resultElm.Element("tweet") ?? throw CreateParseError(),
_ => throw CreateParseError(),
};

return this.ParseTweet(tweetElm);
return this.ParseTweetUnion(resultElm);
}
catch (WebApiException ex)
{
Expand All @@ -69,6 +62,18 @@ public TwitterStatus ToTwitterStatus()
}
}

private TwitterStatus ParseTweetUnion(XElement tweetUnionElm)
{
var tweetElm = tweetUnionElm.Element("__typename")?.Value switch
{
"Tweet" => tweetUnionElm,
"TweetWithVisibilityResults" => tweetUnionElm.Element("tweet") ?? throw CreateParseError(),
_ => throw CreateParseError(),
};

return this.ParseTweet(tweetElm);
}

private TwitterStatus ParseTweet(XElement tweetElm)
{
var tweetLegacyElm = tweetElm.Element("legacy") ?? throw CreateParseError();
Expand Down Expand Up @@ -142,7 +147,7 @@ static string GetText(XElement elm, string name)
ScreenName = GetText(userLegacyElm, "screen_name"),
Protected = GetTextOrNull(userLegacyElm, "protected") == "true",
},
RetweetedStatus = retweetedTweetElm != null ? this.ParseTweet(retweetedTweetElm) : null,
RetweetedStatus = retweetedTweetElm != null ? this.ParseTweetUnion(retweetedTweetElm) : null,
};
}

Expand Down
1 change: 1 addition & 0 deletions OpenTween/Resources/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
更新履歴

==== Unreleased
* FIX: リプライ制限されたツイートのRTがリストのタイムラインに含まれているとエラーになる不具合を修正

==== Ver 3.6.1(2023/07/07)
* CHG: graphqlエンドポイントからのレスポンスの読み込み失敗時に問題の起きたツイートをErrorLogsに書き出す機能を追加
Expand Down

0 comments on commit 8421350

Please sign in to comment.