mirror of
https://github.com/g3rv4/GetMoarFediverse.git
synced 2024-11-28 02:23:49 +01:00
Merge pull request #27 from nberlee/PinnedTags
Get PinnedTags from database, use them if "PinnedTags": true
This commit is contained in:
commit
6b3d3cfd28
@ -11,17 +11,19 @@ public class Config
|
|||||||
public string FakeRelayUrl { get; }
|
public string FakeRelayUrl { get; }
|
||||||
public string FakeRelayApiKey { get; }
|
public string FakeRelayApiKey { get; }
|
||||||
public string? MastodonPostgresConnectionString { get; }
|
public string? MastodonPostgresConnectionString { get; }
|
||||||
|
public bool PinnedTags { get; }
|
||||||
public ImmutableArray<string> Tags { get; }
|
public ImmutableArray<string> Tags { get; }
|
||||||
public ImmutableArray<SiteData> Sites { get; }
|
public ImmutableArray<SiteData> Sites { get; }
|
||||||
|
|
||||||
|
|
||||||
private Config(string importedPath, string fakeRelayUrl, string fakeRelayApiKey, string? mastodonPostgresConnectionString,
|
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;
|
ImportedPath = importedPath;
|
||||||
FakeRelayUrl = fakeRelayUrl;
|
FakeRelayUrl = fakeRelayUrl;
|
||||||
FakeRelayApiKey = fakeRelayApiKey;
|
FakeRelayApiKey = fakeRelayApiKey;
|
||||||
MastodonPostgresConnectionString = mastodonPostgresConnectionString;
|
MastodonPostgresConnectionString = mastodonPostgresConnectionString;
|
||||||
|
PinnedTags = pinnedTags;
|
||||||
Tags = tags;
|
Tags = tags;
|
||||||
Sites = sites;
|
Sites = sites;
|
||||||
}
|
}
|
||||||
@ -68,7 +70,7 @@ public class Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.MastodonPostgresConnectionString,
|
Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.MastodonPostgresConnectionString,
|
||||||
data.Tags.ToImmutableArray(), data.GetImmutableSites());
|
data.PinnedTags, data.Tags.ToImmutableArray(), data.GetImmutableSites());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigData
|
public class ConfigData
|
||||||
@ -76,6 +78,7 @@ public class Config
|
|||||||
public string? FakeRelayUrl { get; set; }
|
public string? FakeRelayUrl { get; set; }
|
||||||
public string? FakeRelayApiKey { get; set; }
|
public string? FakeRelayApiKey { get; set; }
|
||||||
public string? MastodonPostgresConnectionString { get; set; }
|
public string? MastodonPostgresConnectionString { get; set; }
|
||||||
|
public bool PinnedTags { get; set; }
|
||||||
public string[]? Instances { get; set; }
|
public string[]? Instances { get; set; }
|
||||||
public string[]? Tags { get; set; }
|
public string[]? Tags { get; set; }
|
||||||
public InternalSiteData[]? Sites { get; set; }
|
public InternalSiteData[]? Sites { get; set; }
|
||||||
|
@ -23,4 +23,25 @@ public static class MastodonConnectionHelper
|
|||||||
|
|
||||||
return res;
|
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())
|
if (Config.Instance.MastodonPostgresConnectionString.HasValue())
|
||||||
{
|
{
|
||||||
var tags = await MastodonConnectionHelper.GetFollowedTagsAsync();
|
var tags = await MastodonConnectionHelper.GetFollowedTagsAsync();
|
||||||
|
if (Config.Instance.PinnedTags)
|
||||||
|
{
|
||||||
|
tags = tags.Concat(await MastodonConnectionHelper.GetPinnedTagsAsync()).Distinct().ToList();
|
||||||
|
}
|
||||||
numberOfTags = tags.Count;
|
numberOfTags = tags.Count;
|
||||||
sitesTags = Config.Instance.Sites
|
sitesTags = Config.Instance.Sites
|
||||||
.SelectMany(s => tags.Select(t => (s.Host, t)))
|
.SelectMany(s => tags.Select(t => (s.Host, t)))
|
||||||
|
Loading…
Reference in New Issue
Block a user