started working on RT

This commit is contained in:
Vincent Cloutier 2022-05-08 19:10:08 -04:00
parent 03414613dd
commit 49efcd1f97
4 changed files with 18 additions and 8 deletions

View file

@ -60,13 +60,9 @@ namespace BirdsiteLive.Domain
// Replace RT by a link
var content = extractedTags.content;
if (content.Contains("{RT}") && tweet.IsRetweet)
if (tweet.IsRetweet)
{
if (!string.IsNullOrWhiteSpace(tweet.RetweetUrl))
content = content.Replace("{RT}",
$@"<a href=""{tweet.RetweetUrl}"" rel=""nofollow noopener noreferrer"" target=""_blank"">RT</a>");
else
content = content.Replace("{RT}", "RT");
content = "RT: " + content;
}
string inReplyTo = null;

View file

@ -13,7 +13,15 @@ namespace BirdsiteLive.Twitter.Extractors
}
public class TweetExtractor : ITweetExtractor
{
{
private readonly ITwitterTweetsService _twitterTweetsService;
public TweetExtractor(ITwitterTweetsService twitterTweetsService)
{
_twitterTweetsService = twitterTweetsService;
}
public ExtractedTweet Extract(JsonElement tweet)
{
bool IsRetweet = false;
@ -33,6 +41,11 @@ namespace BirdsiteLive.Twitter.Extractors
if (first.GetProperty("type").GetString() == "retweeted")
{
IsRetweet = true;
var statusId = Int64.Parse(first.GetProperty("id").GetString());
var extracted = _twitterTweetsService.GetTweet(statusId);
extracted.IsRetweet = true;
return extracted;
}
if (first.GetProperty("type").GetString() == "replied_to")
{

View file

@ -15,5 +15,6 @@ namespace BirdsiteLive.Twitter.Models
public bool IsThread { get; set; }
public bool IsRetweet { get; set; }
public string RetweetUrl { get; set; }
public string OriginalAuthor { get; set; }
}
}

View file

@ -50,7 +50,7 @@ namespace BirdsiteLive.Twitter
{
await _twitterAuthenticationInitializer.EnsureAuthenticationIsInitialized();
JsonDocument tweet;
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.twitter.com/2/tweets?ids=" + statusId))
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.twitter.com/2/tweets?ids=" + statusId + "&tweet.fields=id,created_at,text,author_id,in_reply_to_user_id,referenced_tweets,attachments,withheld,geo,entities,public_metrics,possibly_sensitive,source,lang,context_annotations,conversation_id,reply_settings&user.fields=name,username"))
{
request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + _twitterAuthenticationInitializer.Token);