feat: upgrade to .NET 6, refactor everything

This commit is contained in:
spiral
2021-11-26 21:10:56 -05:00
parent d28e99ba43
commit 1918c56937
314 changed files with 27954 additions and 27966 deletions

View File

@@ -1,57 +1,60 @@
#nullable enable
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace PluralKit.Core
namespace PluralKit.Core;
public static class DatabaseViewsExt
{
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<ListedMember>> QueryMemberList(this IPKConnection conn, SystemId system,
MemberListQueryOptions opts)
{
public static Task<IEnumerable<SystemFronter>> QueryCurrentFronters(this IPKConnection conn, SystemId system) =>
conn.QueryAsync<SystemFronter>("select * from system_fronters where system = @system", new { system });
StringBuilder query;
if (opts.GroupFilter == null)
query = new StringBuilder("select * from member_list where system = @system");
else
query = new StringBuilder(
"select member_list.* from group_members inner join member_list on member_list.id = group_members.member_id where group_id = @groupFilter");
public static Task<IEnumerable<ListedGroup>> QueryGroupList(this IPKConnection conn, SystemId system) =>
conn.QueryAsync<ListedGroup>("select * from group_list where system = @System", new { System = system });
if (opts.PrivacyFilter != null)
query.Append($" and member_visibility = {(int)opts.PrivacyFilter}");
public static Task<IEnumerable<ListedMember>> QueryMemberList(this IPKConnection conn, SystemId system, MemberListQueryOptions opts)
if (opts.Search != null)
{
StringBuilder query;
if (opts.GroupFilter == null)
query = new StringBuilder("select * from member_list where system = @system");
else
query = new StringBuilder("select member_list.* from group_members inner join member_list on member_list.id = group_members.member_id where group_id = @groupFilter");
static string Filter(string column) =>
$"(position(lower(@filter) in lower(coalesce({column}, ''))) > 0)";
if (opts.PrivacyFilter != null)
query.Append($" and member_visibility = {(int)opts.PrivacyFilter}");
if (opts.Search != null)
query.Append($" and ({Filter("name")} or {Filter("display_name")}");
if (opts.SearchDescription)
{
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(")");
// 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)}");
}
return conn.QueryAsync<ListedMember>(query.ToString(), new { system, filter = opts.Search, groupFilter = opts.GroupFilter });
query.Append(")");
}
public struct MemberListQueryOptions
{
public PrivacyLevel? PrivacyFilter;
public string? Search;
public bool SearchDescription;
public LookupContext Context;
public GroupId? GroupFilter;
}
return conn.QueryAsync<ListedMember>(query.ToString(),
new { system, filter = opts.Search, groupFilter = opts.GroupFilter });
}
public struct MemberListQueryOptions
{
public PrivacyLevel? PrivacyFilter;
public string? Search;
public bool SearchDescription;
public LookupContext Context;
public GroupId? GroupFilter;
}
}

View File

@@ -1,7 +1,6 @@
namespace PluralKit.Core
namespace PluralKit.Core;
public class ListedGroup: PKGroup
{
public class ListedGroup: PKGroup
{
public int MemberCount { get; }
}
public int MemberCount { get; }
}

View File

@@ -1,17 +1,16 @@
#nullable enable
using NodaTime;
namespace PluralKit.Core
{
// TODO: is inheritance here correct?
public class ListedMember: PKMember
{
// public ulong? LastMessage { get; }
public Instant? LastSwitchTime { get; }
namespace PluralKit.Core;
public AnnualDate? AnnualBirthday =>
Birthday != null
? new AnnualDate(Birthday.Value.Month, Birthday.Value.Day)
: (AnnualDate?)null;
}
// TODO: is inheritance here correct?
public class ListedMember: PKMember
{
// public ulong? LastMessage { get; }
public Instant? LastSwitchTime { get; }
public AnnualDate? AnnualBirthday =>
Birthday != null
? new AnnualDate(Birthday.Value.Month, Birthday.Value.Day)
: null;
}

View File

@@ -1,14 +1,13 @@
using NodaTime;
namespace PluralKit.Core
namespace PluralKit.Core;
public class SystemFronter
{
public class SystemFronter
{
public SystemId SystemId { get; }
public SwitchId SwitchId { get; }
public Instant SwitchTimestamp { get; }
public MemberId MemberId { get; }
public string MemberHid { get; }
public string MemberName { get; }
}
public SystemId SystemId { get; }
public SwitchId SwitchId { get; }
public Instant SwitchTimestamp { get; }
public MemberId MemberId { get; }
public string MemberHid { get; }
public string MemberName { get; }
}