From 875b2fe26e59648f4d765409213396cb6b8a2cf4 Mon Sep 17 00:00:00 2001 From: Gervasio Marchand Date: Tue, 20 Dec 2022 12:03:06 -0800 Subject: [PATCH] Deprecate Sites in favor of Instances (#7) --- README.md | 12 +----------- src/Config.cs | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3e8a361..87c9cf3 100644 --- a/README.md +++ b/README.md @@ -18,17 +18,7 @@ You can download an executable for your environment [on the releases page](https "dotnet", "csharp" ], - "Sites": [ - { - "Host": "hachyderm.io", - "SiteSpecificTags": [ - "hachyderm" - ] - }, - { - "Host": "mastodon.social" - } - ] + "Instances": [ "hachyderm.io", "mastodon.social" ] } ``` diff --git a/src/Config.cs b/src/Config.cs index c499880..0b23d65 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -44,9 +44,14 @@ public class Config { throw new Exception("The api key is missing"); } + + if (data.Sites is { Length: > 0 }) + { + Console.WriteLine("Warning: Sites is deprecated, please use Instances instead"); + } Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.MastodonPostgresConnectionString, - data.Tags.ToImmutableArray(), data.ImmutableSites); + data.Tags.ToImmutableArray(), data.GetImmutableSites()); } public class ConfigData @@ -54,14 +59,26 @@ public class Config public string FakeRelayUrl { get; set; } public string? FakeRelayApiKey { get; set; } public string? MastodonPostgresConnectionString { get; set; } + public string[]? Instances { get; set; } public string[] Tags { get; set; } public InternalSiteData[]? Sites { get; set; } - public ImmutableArray ImmutableSites => - Sites == null + public ImmutableArray GetImmutableSites() + { + // the plan is to stop supporting Sites in favor of Instances. SiteSpecificTags add complexity and + // don't make sense when pulling tags from Mastodon. Also, pulling is fast and multithreaded! + if (Instances != null) + { + return Instances + .Select(i => new SiteData { Host = i, SiteSpecificTags = ImmutableArray.Empty }) + .ToImmutableArray(); + } + + return Sites == null ? ImmutableArray.Empty : Sites.Select(s => s.ToSiteData()) - .ToImmutableArray(); + .ToImmutableArray(); + } public class InternalSiteData {