From 1a7eae9471c724a33f27d6cad657028fadbd747a Mon Sep 17 00:00:00 2001 From: Gervasio Marchand Date: Tue, 20 Dec 2022 09:46:15 -0300 Subject: [PATCH] Avoid sending Announce to instances about their own statuses --- src/FakeRelay.Core/Extensions.cs | 7 +++++++ src/FakeRelay.Core/Helpers/MastodonHelper.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/FakeRelay.Core/Extensions.cs 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) {