This commit is contained in:
Vincent Cloutier 2022-05-17 17:51:21 -04:00
parent e53beb1f9d
commit a2cd844394
5 changed files with 24 additions and 6 deletions

View file

@ -10,6 +10,7 @@ namespace BirdsiteLive.ActivityPub.Models
public string[] context { get; set; } = new[] { "https://www.w3.org/ns/activitystreams" };
public string id { get; set; }
public string announceId { get; set; }
public string type { get; } = "Note";
public string summary { get; set; }
public string inReplyTo { get; set; }

View file

@ -62,7 +62,14 @@ namespace BirdsiteLive.Domain
try
{
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
var noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId);
String noteUri;
if (activityType == "Create")
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId);
} else
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, note.announceId);
}
var now = DateTime.UtcNow;
var nowString = now.ToString("s") + "Z";

View file

@ -42,10 +42,12 @@ namespace BirdsiteLive.Domain
{
var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
var noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());
String announceId = null;
if (tweet.IsRetweet)
{
actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, tweet.OriginalAuthor.Acct);
noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, tweet.OriginalAuthor.Acct, tweet.Id.ToString());
announceId = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.RetweetId.ToString());
}
var to = $"{actorUrl}/followers";
@ -79,6 +81,7 @@ namespace BirdsiteLive.Domain
var note = new Note
{
id = noteUrl,
announceId = announceId,
published = tweet.CreatedAt.ToString("s") + "Z",
url = noteUrl,

View file

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

View file

@ -83,6 +83,11 @@ namespace BirdsiteLive.Twitter
}
public async Task<ExtractedTweet[]> GetTimelineAsync(string username, int nberTweets, long fromTweetId = -1)
{
if (nberTweets < 5)
nberTweets = 5;
if (nberTweets > 100)
nberTweets = 100;
await _twitterAuthenticationInitializer.EnsureAuthenticationIsInitialized();
@ -91,9 +96,10 @@ namespace BirdsiteLive.Twitter
var reqURL = "https://api.twitter.com/2/users/"
+ user.Id +
"/tweets?expansions=in_reply_to_user_id,attachments.media_keys,entities.mentions.username,referenced_tweets.id.author_id&tweet.fields=id"
"/tweets?expansions=in_reply_to_user_id,attachments.media_keys,entities.mentions.username,referenced_tweets.id.author_id"
+ "&tweet.fields=id,created_at"
+ "&media.fields=media_key,duration_ms,height,preview_image_url,type,url,width,public_metrics,alt_text,variants"
+ "&max_results=5"
+ "&max_results=" + nberTweets
+ "" ; // ?since_id=2324234234
JsonDocument tweets;
try
@ -147,7 +153,7 @@ namespace BirdsiteLive.Twitter
var originalAuthor = _twitterUserService.GetUser(match.Groups[1].Value);
var statusId = Int64.Parse(first.GetProperty("id").GetString());
var extracted = GetTweet(statusId);
extracted.Id = Int64.Parse(tweet.GetProperty("id").GetString());
extracted.RetweetId = Int64.Parse(tweet.GetProperty("id").GetString());
extracted.IsRetweet = true;
extracted.OriginalAuthor = originalAuthor;
return extracted;
@ -194,7 +200,7 @@ namespace BirdsiteLive.Twitter
}
catch (Exception e)
{
_logger.LogError("Tried getting media from tweet, but got error:", e);
_logger.LogError("Tried getting media from tweet, but got error: \n", e.StackTrace);
}
@ -205,7 +211,7 @@ namespace BirdsiteLive.Twitter
InReplyToStatusId = replyId,
InReplyToAccount = replyAccountString,
MessageContent = tweet.GetProperty("text").GetString(),
CreatedAt = DateTime.Now, // tweet.GetProperty("data").GetProperty("in_reply_to_status_id").GetDateTime(),
CreatedAt = tweet.GetProperty("created_at").GetDateTime(),
IsReply = IsReply,
IsThread = false,
IsRetweet = IsRetweet,