From a2cd844394944548fd66b0b42e42c34b544368ed Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Tue, 17 May 2022 17:51:21 -0400 Subject: [PATCH] more fix --- src/BirdsiteLive.ActivityPub/Models/Note.cs | 1 + src/BirdsiteLive.Domain/ActivityPubService.cs | 9 ++++++++- src/BirdsiteLive.Domain/StatusService.cs | 3 +++ .../Models/ExtractedTweet.cs | 1 + src/BirdsiteLive.Twitter/TwitterTweetsService.cs | 16 +++++++++++----- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/BirdsiteLive.ActivityPub/Models/Note.cs b/src/BirdsiteLive.ActivityPub/Models/Note.cs index fc6dc5b..d7e158d 100644 --- a/src/BirdsiteLive.ActivityPub/Models/Note.cs +++ b/src/BirdsiteLive.ActivityPub/Models/Note.cs @@ -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; } diff --git a/src/BirdsiteLive.Domain/ActivityPubService.cs b/src/BirdsiteLive.Domain/ActivityPubService.cs index 979be22..83c4185 100644 --- a/src/BirdsiteLive.Domain/ActivityPubService.cs +++ b/src/BirdsiteLive.Domain/ActivityPubService.cs @@ -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"; diff --git a/src/BirdsiteLive.Domain/StatusService.cs b/src/BirdsiteLive.Domain/StatusService.cs index a372a9b..de2040d 100644 --- a/src/BirdsiteLive.Domain/StatusService.cs +++ b/src/BirdsiteLive.Domain/StatusService.cs @@ -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, diff --git a/src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs b/src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs index 268745c..79d4b7c 100644 --- a/src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs +++ b/src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs @@ -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; } } } \ No newline at end of file diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index 0d254fd..5a13c3d 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -83,6 +83,11 @@ namespace BirdsiteLive.Twitter } public async Task 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,