feat: rework group list into member list
This commit is contained in:
7
PluralKit.Core/Database/Migrations/25.sql
Normal file
7
PluralKit.Core/Database/Migrations/25.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
-- schema version 25
|
||||
-- group name privacy
|
||||
|
||||
alter table groups add column name_privacy integer check (name_privacy in (1, 2)) not null default 1;
|
||||
alter table groups add column metadata_privacy integer check (metadata_privacy in (1, 2)) not null default 1;
|
||||
|
||||
update info set schema_version = 25;
|
@@ -10,11 +10,39 @@ public static class DatabaseViewsExt
|
||||
public static Task<IEnumerable<SystemFronter>> QueryCurrentFronters(this IPKConnection conn, SystemId system) =>
|
||||
conn.QueryAsync<SystemFronter>("select * from system_fronters where system = @system", new { system });
|
||||
|
||||
public static Task<IEnumerable<ListedGroup>> QueryGroupList(this IPKConnection conn, SystemId system) =>
|
||||
conn.QueryAsync<ListedGroup>("select * from group_list where system = @System", new { System = system });
|
||||
public static Task<IEnumerable<ListedGroup>> QueryGroupList(this IPKConnection conn, SystemId system,
|
||||
ListQueryOptions opts)
|
||||
{
|
||||
StringBuilder query = new StringBuilder("select * from group_list where system = @system");
|
||||
|
||||
if (opts.PrivacyFilter != null)
|
||||
query.Append($" and visibility = {(int)opts.PrivacyFilter}");
|
||||
|
||||
if (opts.Search != null)
|
||||
{
|
||||
static string Filter(string column) =>
|
||||
$"(position(lower(@filter) in lower(coalesce({column}, ''))) > 0)";
|
||||
|
||||
query.Append($" and ({Filter("name")} or {Filter("display_name")}");
|
||||
if (opts.SearchDescription)
|
||||
{
|
||||
// We need to account for the possibility of description privacy when searching
|
||||
// If we're looking up from the outside, only search "public_description" (defined in the view; null if desc is private)
|
||||
// If we're the owner, just search the full description
|
||||
var descriptionColumn =
|
||||
opts.Context == LookupContext.ByOwner ? "description" : "public_description";
|
||||
query.Append($"or {Filter(descriptionColumn)}");
|
||||
}
|
||||
|
||||
query.Append(")");
|
||||
}
|
||||
|
||||
return conn.QueryAsync<ListedGroup>(
|
||||
query.ToString(),
|
||||
new { system, filter = opts.Search });
|
||||
}
|
||||
public static Task<IEnumerable<ListedMember>> QueryMemberList(this IPKConnection conn, SystemId system,
|
||||
MemberListQueryOptions opts)
|
||||
ListQueryOptions opts)
|
||||
{
|
||||
StringBuilder query;
|
||||
if (opts.GroupFilter == null)
|
||||
@@ -49,7 +77,7 @@ public static class DatabaseViewsExt
|
||||
new { system, filter = opts.Search, groupFilter = opts.GroupFilter });
|
||||
}
|
||||
|
||||
public struct MemberListQueryOptions
|
||||
public struct ListQueryOptions
|
||||
{
|
||||
public PrivacyLevel? PrivacyFilter;
|
||||
public string? Search;
|
||||
|
@@ -2,5 +2,6 @@ namespace PluralKit.Core;
|
||||
|
||||
public class ListedGroup: PKGroup
|
||||
{
|
||||
public int MemberCount { get; }
|
||||
public int PublicMemberCount { get; }
|
||||
public int TotalMemberCount { get; }
|
||||
}
|
@@ -64,5 +64,12 @@ select groups.*,
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
group_members.group_id = groups.id and members.member_visibility = 1
|
||||
) as member_count
|
||||
) as public_member_count,
|
||||
-- Find private group member count
|
||||
(
|
||||
select count(*) from group_members
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
group_members.group_id = groups.id
|
||||
) as total_member_count
|
||||
from groups;
|
Reference in New Issue
Block a user