Soapbox-style quote RTs

This commit is contained in:
Miss Pasture 2022-01-25 19:42:19 -05:00
parent f774cade0e
commit 22c4d84682
6 changed files with 32 additions and 7 deletions

View file

@ -17,6 +17,7 @@ namespace BirdsiteLive.ActivityPub
{ "PropertyValue", "schema:PropertyValue" },
{ "value", "schema:value" },
{ "sensitive", "as:sensitive" },
{ "quoteUrl", "as:quoteUrl" },
{ "schema", "http://schema.org#" },
{ "toot", "https://joinmastodon.org/ns#" }

View file

@ -26,5 +26,7 @@ namespace BirdsiteLive.ActivityPub.Models
public Attachment[] attachment { get; set; }
public Tag[] tag { get; set; }
//public Dictionary<string, string> replies;
public string quoteUrl { get; set; }
}
}

View file

@ -28,5 +28,7 @@
public int FailingTwitterUserCleanUpThreshold { get; set; }
public int MaxStatusFetchAge { get; set; }
public bool EnableQuoteRT { get; set; }
}
}

View file

@ -73,6 +73,9 @@ namespace BirdsiteLive.Domain
if (tweet.InReplyToStatusId != default)
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount.ToLowerInvariant()}/statuses/{tweet.InReplyToStatusId}";
if( tweet.QuoteTweetUrl != null )
content += $@"<span class=""quote-inline""><br><br>RT: <a href=""{tweet.QuoteTweetUrl}"">{tweet.QuoteTweetUrl}</a></span>";
var note = new Note
{
id = noteUrl,
@ -91,6 +94,8 @@ namespace BirdsiteLive.Domain
content = $"<p>{content}</p>",
attachment = Convert(tweet.Media),
tag = extractedTags.tags,
quoteUrl = tweet.QuoteTweetUrl
};
return note;

View file

@ -39,7 +39,8 @@ namespace BirdsiteLive.Twitter.Extractors
IsThread = tweet.InReplyToUserId != null && tweet.InReplyToUserId == tweet.CreatedBy.Id,
IsRetweet = tweet.IsRetweet || tweet.QuotedStatusId != null,
RetweetUrl = ExtractRetweetUrl(tweet),
IsSensitive = tweet.PossiblySensitive
IsSensitive = tweet.PossiblySensitive,
QuoteTweetUrl = tweet.QuotedStatusId != null ? "https://" + _instanceSettings.Domain + "/users/" + tweet.QuotedTweet.CreatedBy.ScreenName + "/statuses/" + tweet.QuotedStatusId : null
};
return extractedTweet;
@ -85,7 +86,11 @@ namespace BirdsiteLive.Twitter.Extractors
message = message.Replace(tweetUrl, string.Empty).Trim();
}
if (tweet.QuotedTweet != null) message = $"[Quote {{RT}}]{Environment.NewLine}{message}";
if (tweet.QuotedTweet != null && ! _instanceSettings.EnableQuoteRT)
{
message = $"[Quote {{RT}}]{Environment.NewLine}{message}";
}
if (tweet.IsRetweet)
{
if (tweet.RetweetedTweet != null && !message.StartsWith("RT"))
@ -99,17 +104,26 @@ namespace BirdsiteLive.Twitter.Extractors
// Expand URLs
foreach (var url in tweet.Urls.OrderByDescending(x => x.URL.Length))
{
var linkUri = new UriBuilder(url.ExpandedURL);
if (linkUri.Host == "twitter.com")
// A bit of a hack
if (url.ExpandedURL == tweet.QuotedTweet?.Url && _instanceSettings.EnableQuoteRT)
{
linkUri.Host = _instanceSettings.TwitterDomain;
url.ExpandedURL = linkUri.Uri.ToString();
url.ExpandedURL = "";
} else
{
var linkUri = new UriBuilder(url.ExpandedURL);
if (linkUri.Host == "twitter.com")
{
linkUri.Host = _instanceSettings.TwitterDomain;
url.ExpandedURL = linkUri.Uri.ToString();
}
}
message = message.Replace(url.URL, url.ExpandedURL);
}
// Hack
return message;
}

View file

@ -16,5 +16,6 @@ namespace BirdsiteLive.Twitter.Models
public bool IsRetweet { get; set; }
public string RetweetUrl { get; set; }
public bool IsSensitive { get; set; }
public string QuoteTweetUrl { get; set; }
}
}