Avoid sending Announce to instances about their own statuses

This commit is contained in:
Gervasio Marchand 2022-12-20 09:46:15 -03:00
parent f3ec35c802
commit 1a7eae9471
No known key found for this signature in database
GPG Key ID: B7736CB188DD0A38
2 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,7 @@
namespace FakeRelay.Core;
public static class Extensions
{
public static bool StartsWithCI(this string s, string prefix) =>
s.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
}

View File

@ -4,8 +4,14 @@ namespace FakeRelay.Core.Helpers;
public static class MastodonHelper
{
public static Task<string> EnqueueStatusToFetchAsync(string targetHost, string statusUrl) =>
SendMessageToInboxAsync(targetHost, $@"{{
public static async Task<string> EnqueueStatusToFetchAsync(string targetHost, string statusUrl)
{
if (statusUrl.StartsWithCI($"https://{targetHost}") || statusUrl.StartsWithCI($"http://{targetHost}"))
{
return "Status ignored, it's local";
}
return await SendMessageToInboxAsync(targetHost, $@"{{
""@context"": ""https://www.w3.org/ns/activitystreams"",
""actor"": ""https://{Config.Instance.Host}/actor"",
""id"": ""https://{Config.Instance.Host}/activities/{Guid.NewGuid()}"",
@ -15,6 +21,7 @@ public static class MastodonHelper
],
""type"": ""Announce""
}}");
}
public static async Task<string> SendMessageToInboxAsync(string targetHost, string content)
{