mirror of
https://github.com/g3rv4/GetMoarFediverse.git
synced 2024-11-21 15:13:08 +01:00
Get PinnedTags from database, use them if "PinnedTags": true
This need `GRANT SELECT ON web_settings TO mastodon_read;` Fixes #25
This commit is contained in:
parent
db4023797a
commit
1b1a8d5d0b
@ -11,17 +11,19 @@ public class Config
|
||||
public string FakeRelayUrl { get; }
|
||||
public string FakeRelayApiKey { get; }
|
||||
public string? MastodonPostgresConnectionString { get; }
|
||||
public bool PinnedTags { get; }
|
||||
public ImmutableArray<string> Tags { get; }
|
||||
public ImmutableArray<SiteData> Sites { get; }
|
||||
|
||||
|
||||
private Config(string importedPath, string fakeRelayUrl, string fakeRelayApiKey, string? mastodonPostgresConnectionString,
|
||||
ImmutableArray<string> tags, ImmutableArray<SiteData> sites)
|
||||
bool pinnedTags, ImmutableArray<string> tags, ImmutableArray<SiteData> sites)
|
||||
{
|
||||
ImportedPath = importedPath;
|
||||
FakeRelayUrl = fakeRelayUrl;
|
||||
FakeRelayApiKey = fakeRelayApiKey;
|
||||
MastodonPostgresConnectionString = mastodonPostgresConnectionString;
|
||||
PinnedTags = pinnedTags;
|
||||
Tags = tags;
|
||||
Sites = sites;
|
||||
}
|
||||
@ -68,7 +70,7 @@ public class Config
|
||||
}
|
||||
|
||||
Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.MastodonPostgresConnectionString,
|
||||
data.Tags.ToImmutableArray(), data.GetImmutableSites());
|
||||
data.PinnedTags, data.Tags.ToImmutableArray(), data.GetImmutableSites());
|
||||
}
|
||||
|
||||
public class ConfigData
|
||||
@ -76,6 +78,7 @@ public class Config
|
||||
public string? FakeRelayUrl { get; set; }
|
||||
public string? FakeRelayApiKey { get; set; }
|
||||
public string? MastodonPostgresConnectionString { get; set; }
|
||||
public bool PinnedTags { get; set; }
|
||||
public string[]? Instances { get; set; }
|
||||
public string[]? Tags { get; set; }
|
||||
public InternalSiteData[]? Sites { get; set; }
|
||||
|
@ -23,4 +23,25 @@ public static class MastodonConnectionHelper
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<List<string>> GetPinnedTagsAsync()
|
||||
{
|
||||
if (Config.Instance == null) throw new Exception("Config object is not initialized");
|
||||
if (Config.Instance.MastodonPostgresConnectionString.IsNullOrEmpty())
|
||||
{
|
||||
throw new Exception("Missing mastodon postgres connection string");
|
||||
}
|
||||
|
||||
await using var conn = new NpgsqlConnection(Config.Instance.MastodonPostgresConnectionString);
|
||||
await conn.OpenAsync();
|
||||
|
||||
var res = new List<string>();
|
||||
await using var cmd = new NpgsqlCommand("SELECT DISTINCT col->'params'->>'id' FROM web_settings, json_array_elements(data->'columns') col WHERE col->>'id' = 'HASHTAG' AND col->'params'->>'id' IS NOT NULL ORDER BY col->'params'->>'id' ASC", conn);
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
while (await reader.ReadAsync())
|
||||
res.Add(reader.GetString(0));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ int numberOfTags;
|
||||
if (Config.Instance.MastodonPostgresConnectionString.HasValue())
|
||||
{
|
||||
var tags = await MastodonConnectionHelper.GetFollowedTagsAsync();
|
||||
if (Config.Instance.PinnedTags)
|
||||
{
|
||||
tags = tags.Concat(await MastodonConnectionHelper.GetPinnedTagsAsync()).Distinct().ToList();
|
||||
}
|
||||
numberOfTags = tags.Count;
|
||||
sitesTags = Config.Instance.Sites
|
||||
.SelectMany(s => tags.Select(t => (s.Host, t)))
|
||||
|
Loading…
Reference in New Issue
Block a user