Browse Source

Soapbox-style quote RTs

master
Pasture Pastureson 8 months ago
parent
commit
22c4d84682
6 changed files with 32 additions and 7 deletions
  1. +1
    -0
      src/BirdsiteLive.ActivityPub/Models/Activity.cs
  2. +2
    -0
      src/BirdsiteLive.ActivityPub/Models/Note.cs
  3. +2
    -0
      src/BirdsiteLive.Common/Settings/InstanceSettings.cs
  4. +5
    -0
      src/BirdsiteLive.Domain/StatusService.cs
  5. +21
    -7
      src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs
  6. +1
    -0
      src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs

+ 1
- 0
src/BirdsiteLive.ActivityPub/Models/Activity.cs 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#" }


+ 2
- 0
src/BirdsiteLive.ActivityPub/Models/Note.cs 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; }
}
}

+ 2
- 0
src/BirdsiteLive.Common/Settings/InstanceSettings.cs View File

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

+ 5
- 0
src/BirdsiteLive.Domain/StatusService.cs 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;


+ 21
- 7
src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs 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)
{
url.ExpandedURL = "";
} else
{
linkUri.Host = _instanceSettings.TwitterDomain;
url.ExpandedURL = linkUri.Uri.ToString();
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;
}


+ 1
- 0
src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs 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; }
}
}

Loading…
Cancel
Save