From c4e641422941e446ad2648297838b956d3326733 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Fri, 20 Jan 2023 10:46:50 -0500 Subject: [PATCH] fix IsThread --- src/BirdsiteLive.Twitter/TwitterTweetsService.cs | 6 +++++- src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index fef0167..688c738 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -179,6 +179,10 @@ namespace BirdsiteLive.Twitter string inReplyToUser = null; long? inReplyToPostId = null; + string userName = tweet.GetProperty("content").GetProperty("itemContent") + .GetProperty("tweet_results").GetProperty("result").GetProperty("core").GetProperty("user_results") + .GetProperty("result").GetProperty("legacy").GetProperty("screen_name").GetString(); + bool isReply = tweet.GetProperty("content").GetProperty("itemContent") .GetProperty("tweet_results").GetProperty("result").GetProperty("legacy") .TryGetProperty("in_reply_to_status_id_str", out inReplyToPostIdElement); @@ -291,7 +295,7 @@ namespace BirdsiteLive.Twitter MessageContent = MessageContent.Trim(), CreatedAt = DateTime.ParseExact(creationTime, "ddd MMM dd HH:mm:ss yyyy", System.Globalization.CultureInfo.InvariantCulture), IsReply = isReply, - IsThread = false, + IsThread = userName == inReplyToUser, IsRetweet = isRetweet, Media = Media.Count() == 0 ? null : Media.ToArray(), RetweetUrl = "https://t.co/123", diff --git a/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs index 6a3fe71..51c2e40 100644 --- a/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs +++ b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs @@ -85,13 +85,25 @@ namespace BirdsiteLive.ActivityPub.Tests } [TestMethod] - public async Task SimpleReply() + public async Task SimpleThread() { var tweet = await _tweetService.GetTweetAsync(1445468404815597573); Assert.AreEqual(tweet.InReplyToAccount, "punk6529"); Assert.AreEqual(tweet.InReplyToStatusId, 1445468401745289235); Assert.IsTrue(tweet.IsReply); + Assert.IsTrue(tweet.IsThread); + } + + [TestMethod] + public async Task SimpleReply() + { + var tweet = await _tweetService.GetTweetAsync(1612622335546363904); + + Assert.AreEqual(tweet.InReplyToAccount, "DriveTeslaca"); + Assert.AreEqual(tweet.InReplyToStatusId, 1612610060194312193); + Assert.IsTrue(tweet.IsReply); + Assert.IsFalse(tweet.IsThread); } } }