From 9420cb56f87c772c7368a2c8fca8bdd9b3668c34 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 28 Jun 2020 18:07:50 +0200 Subject: [PATCH] Show sorted field on the long list by default --- PluralKit.Bot/Commands/SystemList.cs | 14 +++++++------- PluralKit.Bot/Lists/LongRenderer.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/PluralKit.Bot/Commands/SystemList.cs b/PluralKit.Bot/Commands/SystemList.cs index ba202280..ffa23c2d 100644 --- a/PluralKit.Bot/Commands/SystemList.cs +++ b/PluralKit.Bot/Commands/SystemList.cs @@ -22,10 +22,11 @@ namespace PluralKit.Bot if (target == null) throw Errors.NoSystemError; ctx.CheckSystemPrivacy(target, target.MemberListPrivacy); - // GetRendererFor must be called before GetOptions as it consumes a potential positional full argument that'd otherwise land in the filter - var renderer = GetRendererFor(ctx); + // Must match full before calling the other flag parsers to make sure we consume the token before trying to match search terms, etc + var isFull = ctx.Match("f", "full", "big", "details", "long") || ctx.MatchFlag("f", "full"); var opts = GetOptions(ctx, target); - + var renderer = GetRendererFor(ctx, isFull, opts); + var members = (await _db.Execute(c => opts.Execute(c, target, ctx.LookupContextFor(target)))).ToList(); await ctx.Paginate( members.ToAsyncEnumerable(), @@ -62,11 +63,10 @@ namespace PluralKit.Bot return opts; } - private IListRenderer GetRendererFor(Context ctx) + private IListRenderer GetRendererFor(Context ctx, bool isLongList, SortFilterOptions opts) { - var longList = ctx.Match("f", "full", "big", "details", "long") || ctx.MatchFlag("f", "full"); - if (longList) - return new LongRenderer(LongRenderer.MemberFields.FromFlags(ctx)); + if (isLongList) + return new LongRenderer(LongRenderer.MemberFields.FromFlags(ctx, opts)); return new ShortRenderer(); } } diff --git a/PluralKit.Bot/Lists/LongRenderer.cs b/PluralKit.Bot/Lists/LongRenderer.cs index 52812025..7431999e 100644 --- a/PluralKit.Bot/Lists/LongRenderer.cs +++ b/PluralKit.Bot/Lists/LongRenderer.cs @@ -53,9 +53,16 @@ namespace PluralKit.Bot public bool ShowLastSwitch = false; public bool ShowLastMessage = false; - public static MemberFields FromFlags(Context ctx) + public static MemberFields FromFlags(Context ctx, SortFilterOptions opts) { - var def = new MemberFields(); + var def = new MemberFields + { + // Add some defaults depending on sort order + ShowLastMessage = opts.SortProperty == SortProperty.LastMessage, + ShowLastSwitch = opts.SortProperty == SortProperty.LastSwitch, + ShowMessageCount = opts.SortProperty == SortProperty.MessageCount + }; + if (ctx.MatchFlag("with-last-switch", "with-last-fronted", "with-last-front", "wls", "wlf")) def.ShowLastSwitch = true; if (ctx.MatchFlag("with-message-count", "wmc"))