added tweet author

This commit is contained in:
Vincent Cloutier 2023-06-18 16:55:11 -04:00
parent 7c2dcdbcec
commit 38aa9f2c62
4 changed files with 14 additions and 1 deletions

View file

@ -17,5 +17,6 @@ namespace BirdsiteLive.Twitter.Models
public string RetweetUrl { get; set; } public string RetweetUrl { get; set; }
public long RetweetId { get; set; } public long RetweetId { get; set; }
public TwitterUser OriginalAuthor { get; set; } public TwitterUser OriginalAuthor { get; set; }
public TwitterUser Author { get; set; }
} }
} }

View file

@ -179,6 +179,7 @@ namespace BirdsiteLive.Twitter
JsonElement retweet; JsonElement retweet;
TwitterUser OriginalAuthor; TwitterUser OriginalAuthor;
TwitterUser author = null;
JsonElement inReplyToPostIdElement; JsonElement inReplyToPostIdElement;
JsonElement inReplyToUserElement; JsonElement inReplyToUserElement;
string inReplyToUser = null; string inReplyToUser = null;
@ -189,6 +190,12 @@ namespace BirdsiteLive.Twitter
.GetProperty("tweet_results").GetProperty("result").GetProperty("core").GetProperty("user_results") .GetProperty("tweet_results").GetProperty("result").GetProperty("core").GetProperty("user_results")
.GetProperty("result").GetProperty("legacy").GetProperty("screen_name").GetString(); .GetProperty("result").GetProperty("legacy").GetProperty("screen_name").GetString();
JsonElement userDoc = tweet.GetProperty("content").GetProperty("itemContent")
.GetProperty("tweet_results").GetProperty("result").GetProperty("core")
.GetProperty("user_results").GetProperty("result");
author = _twitterUserService.Extract(userDoc);
bool isReply = tweet.GetProperty("content").GetProperty("itemContent") bool isReply = tweet.GetProperty("content").GetProperty("itemContent")
.GetProperty("tweet_results").GetProperty("result").GetProperty("legacy") .GetProperty("tweet_results").GetProperty("result").GetProperty("legacy")
.TryGetProperty("in_reply_to_status_id_str", out inReplyToPostIdElement); .TryGetProperty("in_reply_to_status_id_str", out inReplyToPostIdElement);
@ -218,6 +225,7 @@ namespace BirdsiteLive.Twitter
.GetProperty("text").GetString(); .GetProperty("text").GetString();
} }
OriginalAuthor = null; OriginalAuthor = null;
} }
else else
{ {
@ -323,6 +331,7 @@ namespace BirdsiteLive.Twitter
quoteTweetLink = quoteTweetLink.Replace("/status/", "/statuses/"); quoteTweetLink = quoteTweetLink.Replace("/status/", "/statuses/");
MessageContent = MessageContent + "\n\n" + quoteTweetLink; MessageContent = MessageContent + "\n\n" + quoteTweetLink;
} }
var extractedTweet = new ExtractedTweet var extractedTweet = new ExtractedTweet
{ {
Id = Int64.Parse(tweet.GetProperty("entryId").GetString().Replace("tweet-", "")), Id = Int64.Parse(tweet.GetProperty("entryId").GetString().Replace("tweet-", "")),
@ -337,6 +346,7 @@ namespace BirdsiteLive.Twitter
RetweetUrl = "https://t.co/123", RetweetUrl = "https://t.co/123",
RetweetId = retweetId, RetweetId = retweetId,
OriginalAuthor = OriginalAuthor, OriginalAuthor = OriginalAuthor,
Author = author,
}; };
return extractedTweet; return extractedTweet;

View file

@ -57,12 +57,13 @@ namespace BirdsiteLive.ActivityPub.Tests
{ {
var tweets = await _tweetService.GetTimelineAsync("grantimahara", default); var tweets = await _tweetService.GetTimelineAsync("grantimahara", default);
Assert.IsTrue(tweets[0].IsReply); Assert.IsTrue(tweets[0].IsReply);
Assert.IsTrue(tweets.Length > 30); Assert.IsTrue(tweets.Length > 10);
Assert.AreEqual(tweets[2].MessageContent, "Liftoff!"); Assert.AreEqual(tweets[2].MessageContent, "Liftoff!");
Assert.AreEqual(tweets[2].RetweetId, 1266812530833240064); Assert.AreEqual(tweets[2].RetweetId, 1266812530833240064);
Assert.AreEqual(tweets[2].Id, 1266813644626489345); Assert.AreEqual(tweets[2].Id, 1266813644626489345);
Assert.AreEqual(tweets[2].OriginalAuthor.Acct, "SpaceX"); Assert.AreEqual(tweets[2].OriginalAuthor.Acct, "SpaceX");
Assert.AreEqual(tweets[2].Author.Acct, "grantimahara");
Assert.IsTrue(tweets[2].IsRetweet); Assert.IsTrue(tweets[2].IsRetweet);
} }

View file

@ -107,6 +107,7 @@ namespace BirdsiteLive.ActivityPub.Tests
var tweet = await _tweetService.GetTweetAsync(1610807139089383427); var tweet = await _tweetService.GetTweetAsync(1610807139089383427);
Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\n\nhttps://domain.name/users/kadhim/statuses/1610706613207285773"); Assert.AreEqual(tweet.MessageContent, "When you gave them your keys you gave them your coins.\n\nhttps://domain.name/users/kadhim/statuses/1610706613207285773");
Assert.AreEqual(tweet.Author.Acct, "RyanSAdams");
} }
[TestMethod] [TestMethod]