mirror of
https://github.com/g3rv4/GetMoarFediverse.git
synced 2024-11-21 23:23:09 +01:00
Columns of PinnedTags can have Include additional tags for this column enabled
This adds not only filter capabilities, which are not relevent to this project like `not` and `all` but also has the `any` field, which is an array where you may add more tags. Unfortunatly, I was unable to create a precise select query for this, as the database field `data` is not jsonb. I think parsing json is really the most optimal way under these circumstances.
This commit is contained in:
parent
1b1a8d5d0b
commit
04af58dde1
@ -1,4 +1,5 @@
|
|||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace GetMoarFediverse;
|
namespace GetMoarFediverse;
|
||||||
|
|
||||||
@ -36,11 +37,33 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user