From 23e17dd88c34aed57ea02a7e250d1e35f5a765b0 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sun, 8 May 2022 18:06:02 -0400 Subject: [PATCH] better parsing --- .../Extractors/TweetExtractor.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs index 20c5267..b38861e 100644 --- a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs +++ b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs @@ -16,17 +16,47 @@ namespace BirdsiteLive.Twitter.Extractors { public ExtractedTweet Extract(JsonElement tweet) { + bool IsRetweet = false; + bool IsReply = false; + long? replyId = null; + JsonElement replyAccount; + string? replyAccountString = null; + JsonElement referenced_tweets; + if(tweet.TryGetProperty("referenced_tweets", out replyAccount)) + { + replyAccountString = replyAccount.GetString(); + + } + if(tweet.TryGetProperty("referenced_tweets", out referenced_tweets)) + { + var first = referenced_tweets.EnumerateArray().ToList()[0]; + if (first.GetProperty("type").GetString() == "retweeted") + { + IsRetweet = true; + } + if (first.GetProperty("type").GetString() == "replied_to") + { + IsReply = true; + replyId = first.GetProperty("id").GetInt64(); + } + if (first.GetProperty("type").GetString() == "quoted") + { + IsReply = true; + replyId = first.GetProperty("id").GetInt64(); + } + } + var extractedTweet = new ExtractedTweet { Id = Int64.Parse(tweet.GetProperty("id").GetString()), - InReplyToStatusId = null, //tweet.GetProperty("in_reply_to_status_id").GetInt64(), - InReplyToAccount = null, //tweet.GetProperty("in_reply_to_user_id").GetString(), + InReplyToStatusId = replyId, + InReplyToAccount = replyAccountString, MessageContent = ExtractMessage(tweet), Media = ExtractMedia(tweet), CreatedAt = DateTime.Now, // tweet.GetProperty("data").GetProperty("in_reply_to_status_id").GetDateTime(), - IsReply = false, + IsReply = IsReply, IsThread = false, - IsRetweet = false, + IsRetweet = IsRetweet, RetweetUrl = ExtractRetweetUrl(tweet) };