mirror of
https://github.com/g3rv4/GetMoarFediverse.git
synced 2024-11-21 23:23:09 +01:00
Merge pull request #28 from nberlee/PinnedTags
Columns of PinnedTags can have Include additional tags for this colum…
This commit is contained in:
commit
92e34f7086
@ -1,4 +1,5 @@
|
||||
using Npgsql;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace GetMoarFediverse;
|
||||
|
||||
@ -36,10 +37,32 @@ public static class MastodonConnectionHelper
|
||||
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);
|
||||
// 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();
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user