diff --git a/src/FakeRelay.Core/Extensions.cs b/src/FakeRelay.Core/Extensions.cs new file mode 100644 index 0000000..fccf168 --- /dev/null +++ b/src/FakeRelay.Core/Extensions.cs @@ -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); +} diff --git a/src/FakeRelay.Core/Helpers/MastodonHelper.cs b/src/FakeRelay.Core/Helpers/MastodonHelper.cs index b44262d..8618cca 100644 --- a/src/FakeRelay.Core/Helpers/MastodonHelper.cs +++ b/src/FakeRelay.Core/Helpers/MastodonHelper.cs @@ -4,8 +4,14 @@ namespace FakeRelay.Core.Helpers; public static class MastodonHelper { - public static Task EnqueueStatusToFetchAsync(string targetHost, string statusUrl) => - SendMessageToInboxAsync(targetHost, $@"{{ + public static async Task 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 SendMessageToInboxAsync(string targetHost, string content) {