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
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 class MastodonHelper
{ {
public static Task<string> EnqueueStatusToFetchAsync(string targetHost, string statusUrl) => public static async Task<string> EnqueueStatusToFetchAsync(string targetHost, string statusUrl)
SendMessageToInboxAsync(targetHost, $@"{{ {
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"", ""@context"": ""https://www.w3.org/ns/activitystreams"",
""actor"": ""https://{Config.Instance.Host}/actor"", ""actor"": ""https://{Config.Instance.Host}/actor"",
""id"": ""https://{Config.Instance.Host}/activities/{Guid.NewGuid()}"", ""id"": ""https://{Config.Instance.Host}/activities/{Guid.NewGuid()}"",
@ -15,6 +21,7 @@ public static class MastodonHelper
], ],
""type"": ""Announce"" ""type"": ""Announce""
}}"); }}");
}
public static async Task<string> SendMessageToInboxAsync(string targetHost, string content) public static async Task<string> SendMessageToInboxAsync(string targetHost, string content)
{ {