Merge pull request #28 from nberlee/PinnedTags

Columns of PinnedTags can have Include additional tags for this colum…
This commit is contained in:
Gervasio Marchand 2022-12-25 12:46:49 -08:00 committed by GitHub
commit 92e34f7086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
using Npgsql; using Npgsql;
using System.Text.Json;
namespace GetMoarFediverse; namespace GetMoarFediverse;
@ -36,10 +37,32 @@ public static class MastodonConnectionHelper
await conn.OpenAsync(); await conn.OpenAsync();
var res = new List<string>(); 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); // Column 0: the 'original' tag with was pinned
// Column 1: Config of 'Include additional tags for this column' this includes the the tags in 'any' array.
await using var cmd = new NpgsqlCommand(@"
SELECT DISTINCT col->'params'->>'id', col->'params'->>'tags'
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(); await using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync()) while (await reader.ReadAsync())
{
res.Add(reader.GetString(0)); res.Add(reader.GetString(0));
if (reader.IsDBNull(1)) continue;
var doc = JsonDocument.Parse(reader.GetString(1));
var anyArray = doc.RootElement.GetProperty("any");
foreach (var item in anyArray.EnumerateArray())
{
var value = item.GetProperty("value");
if (value.ValueKind != JsonValueKind.Null)
{
var valuestring = value.GetString();
if (valuestring.HasValue())
res.Add(valuestring);
}
}
}
return res; return res;
} }