diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 9bb17cfb..e4471cba 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -245,7 +245,7 @@ namespace PluralKit.Bot throw new PKError("You do not have permission to access this information."); } - var groups = (await conn.QueryGroupsInSystem(system.Id)) + var groups = (await conn.QueryGroupList(system.Id)) .Where(g => g.Visibility.CanAccess(pctx)) .ToList(); @@ -262,14 +262,14 @@ namespace PluralKit.Bot var title = system.Name != null ? $"Groups of {system.Name} (`{system.Hid}`)" : $"Groups of `{system.Hid}`"; await ctx.Paginate(groups.ToAsyncEnumerable(), groups.Count, 25, title, Renderer); - Task Renderer(DiscordEmbedBuilder eb, IEnumerable page) + Task Renderer(DiscordEmbedBuilder eb, IEnumerable page) { eb.WithSimpleLineContent(page.Select(g => { if (g.DisplayName != null) - return $"[`{g.Hid}`] **{g.Name}** ({g.DisplayName})"; + return $"[`{g.Hid}`] **{g.Name}** ({g.DisplayName}) ({"member".ToQuantity(g.MemberCount)})"; else - return $"[`{g.Hid}`] **{g.Name}**"; + return $"[`{g.Hid}`] **{g.Name}** ({"member".ToQuantity(g.MemberCount)})"; })); eb.WithFooter($"{groups.Count} total."); return Task.CompletedTask; diff --git a/PluralKit.Core/Database/Migrations/9.sql b/PluralKit.Core/Database/Migrations/9.sql index d7fb6ccb..bf409529 100644 --- a/PluralKit.Core/Database/Migrations/9.sql +++ b/PluralKit.Core/Database/Migrations/9.sql @@ -26,6 +26,7 @@ create table group_members ( primary key (group_id, member_id) ); -alter table systems add column group_list_privacy integer check (group_list_privacy in (1, 2)) not null default systems.member_list_privacy; +alter table systems add column group_list_privacy integer check (group_list_privacy in (1, 2)) not null default 1; +update systems set group_list_privacy = member_list_privacy; update info set schema_version = 9; diff --git a/PluralKit.Core/Database/Views/DatabaseViewsExt.cs b/PluralKit.Core/Database/Views/DatabaseViewsExt.cs index c399a28d..0171900b 100644 --- a/PluralKit.Core/Database/Views/DatabaseViewsExt.cs +++ b/PluralKit.Core/Database/Views/DatabaseViewsExt.cs @@ -11,6 +11,9 @@ namespace PluralKit.Core { public static Task> QueryCurrentFronters(this IPKConnection conn, SystemId system) => conn.QueryAsync("select * from system_fronters where system = @system", new {system}); + + public static Task> QueryGroupList(this IPKConnection conn, SystemId system) => + conn.QueryAsync("select * from group_list where system = @System", new {System = system}); public static Task> QueryMemberList(this IPKConnection conn, SystemId system, MemberListQueryOptions opts) { diff --git a/PluralKit.Core/Database/Views/ListedGroup.cs b/PluralKit.Core/Database/Views/ListedGroup.cs new file mode 100644 index 00000000..fcfbc184 --- /dev/null +++ b/PluralKit.Core/Database/Views/ListedGroup.cs @@ -0,0 +1,7 @@ +namespace PluralKit.Core +{ + public class ListedGroup : PKGroup + { + public int MemberCount { get; } + } +} \ No newline at end of file diff --git a/PluralKit.Core/Database/Views/views.sql b/PluralKit.Core/Database/Views/views.sql index 344c05b1..20f5ac1a 100644 --- a/PluralKit.Core/Database/Views/views.sql +++ b/PluralKit.Core/Database/Views/views.sql @@ -54,4 +54,10 @@ select members.*, when members.description_privacy = 1 then members.description -- Any other privacy (rn just '2'), return null description (missing case = null in SQL) end as public_description -from members; \ No newline at end of file +from members; + +create view group_list as +select groups.*, + -- Find group member count + (select count(*) from group_members where group_id = groups.id) as member_count +from groups; \ No newline at end of file diff --git a/PluralKit.Core/Database/clean.sql b/PluralKit.Core/Database/clean.sql index f950c6ec..3338f4bf 100644 --- a/PluralKit.Core/Database/clean.sql +++ b/PluralKit.Core/Database/clean.sql @@ -5,6 +5,7 @@ drop view if exists system_last_switch; drop view if exists system_fronters; drop view if exists member_list; +drop view if exists group_list; drop function if exists message_context; drop function if exists proxy_members; diff --git a/PluralKit.Core/Models/ModelQueryExt.cs b/PluralKit.Core/Models/ModelQueryExt.cs index 228992eb..45ee566f 100644 --- a/PluralKit.Core/Models/ModelQueryExt.cs +++ b/PluralKit.Core/Models/ModelQueryExt.cs @@ -34,10 +34,7 @@ namespace PluralKit.Core public static Task QueryGroupByHid(this IPKConnection conn, string hid) => conn.QueryFirstOrDefaultAsync("select * from groups where hid = @hid", new {hid = hid.ToLowerInvariant()}); - - public static Task> QueryGroupsInSystem(this IPKConnection conn, SystemId system) => - conn.QueryAsync("select * from groups where system = @System", new {System = system}); - + public static Task QueryGroupMemberCount(this IPKConnection conn, GroupId id, PrivacyLevel? privacyFilter = null) { diff --git a/PluralKit.Core/Models/PKGroup.cs b/PluralKit.Core/Models/PKGroup.cs index b5bf26f6..d373c614 100644 --- a/PluralKit.Core/Models/PKGroup.cs +++ b/PluralKit.Core/Models/PKGroup.cs @@ -5,20 +5,20 @@ namespace PluralKit.Core { public class PKGroup { - public GroupId Id { get; } - public string Hid { get; } = null!; - public SystemId System { get; } + public GroupId Id { get; private set; } + public string Hid { get; private set; } = null!; + public SystemId System { get; private set; } - public string Name { get; } = null!; - public string? DisplayName { get; } - public string? Description { get; } - public string? Icon { get; } + public string Name { get; private set; } = null!; + public string? DisplayName { get; private set; } + public string? Description { get; private set; } + public string? Icon { get; private set; } - public PrivacyLevel DescriptionPrivacy { get; } - public PrivacyLevel IconPrivacy { get; } - public PrivacyLevel ListPrivacy { get; } - public PrivacyLevel Visibility { get; } + public PrivacyLevel DescriptionPrivacy { get; private set; } + public PrivacyLevel IconPrivacy { get; private set; } + public PrivacyLevel ListPrivacy { get; private set; } + public PrivacyLevel Visibility { get; private set; } - public Instant Created { get; } + public Instant Created { get; private set; } } } \ No newline at end of file