refactoring

This commit is contained in:
Vincent Cloutier 2022-05-08 19:21:39 -04:00
parent 8244b1edf7
commit 8d64720933

View file

@ -108,60 +108,6 @@ namespace BirdsiteLive.Twitter
};
}
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("in_reply_to_user_id", 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;
var statusId = Int64.Parse(first.GetProperty("id").GetString());
var extracted = GetTweet(statusId);
extracted.IsRetweet = true;
return extracted;
}
if (first.GetProperty("type").GetString() == "replied_to")
{
IsReply = true;
replyId = Int64.Parse(first.GetProperty("id").GetString());
}
if (first.GetProperty("type").GetString() == "quoted")
{
IsReply = true;
replyId = Int64.Parse(first.GetProperty("id").GetString());
}
}
var extractedTweet = new ExtractedTweet
{
Id = Int64.Parse(tweet.GetProperty("id").GetString()),
InReplyToStatusId = replyId,
InReplyToAccount = replyAccountString,
MessageContent = tweet.GetProperty("text").GetString(),
Media = Array.Empty<ExtractedMedia>(),
CreatedAt = DateTime.Now, // tweet.GetProperty("data").GetProperty("in_reply_to_status_id").GetDateTime(),
IsReply = IsReply,
IsThread = false,
IsRetweet = IsRetweet,
RetweetUrl = "https://t.co/123"
};
return extractedTweet;
}
public bool IsUserApiRateLimited()
{
// Retrieve limit from tooling