feat: system pronouns (#429)

This commit is contained in:
Jake Fulmine
2022-03-23 19:20:16 +01:00
committed by GitHub
parent 062835e0c5
commit 7efe6f1f97
11 changed files with 99 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ public class PKSystem
public string Name { get; }
public string Description { get; }
public string Tag { get; }
public string Pronouns { get; }
public string AvatarUrl { get; }
public string BannerImage { get; }
public string Color { get; }
@@ -51,6 +52,7 @@ public class PKSystem
public PrivacyLevel FrontPrivacy { get; }
public PrivacyLevel FrontHistoryPrivacy { get; }
public PrivacyLevel GroupListPrivacy { get; }
public PrivacyLevel PronounPrivacy { get; }
}
public static class PKSystemExt
@@ -68,6 +70,9 @@ public static class PKSystemExt
o.Add("name", system.Name);
o.Add("description", system.DescriptionFor(ctx));
o.Add("tag", system.Tag);
if (v == APIVersion.V2)
o.Add("pronouns", system.PronounPrivacy.Get(ctx, system.Pronouns));
o.Add("avatar_url", system.AvatarUrl.TryGetCleanCdnUrl());
o.Add("banner", system.DescriptionPrivacy.Get(ctx, system.BannerImage).TryGetCleanCdnUrl());
o.Add("color", system.Color);
@@ -103,6 +108,7 @@ public static class PKSystemExt
var p = new JObject();
p.Add("description_privacy", system.DescriptionPrivacy.ToJsonString());
p.Add("pronoun_privacy", system.PronounPrivacy.ToJsonString());
p.Add("member_list_privacy", system.MemberListPrivacy.ToJsonString());
p.Add("group_list_privacy", system.GroupListPrivacy.ToJsonString());
p.Add("front_privacy", system.FrontPrivacy.ToJsonString());

View File

@@ -13,6 +13,7 @@ public class SystemPatch: PatchObject
public Partial<string?> Hid { get; set; }
public Partial<string?> Description { get; set; }
public Partial<string?> Tag { get; set; }
public Partial<string?> Pronouns { get; set; }
public Partial<string?> AvatarUrl { get; set; }
public Partial<string?> BannerImage { get; set; }
public Partial<string?> Color { get; set; }
@@ -24,12 +25,14 @@ public class SystemPatch: PatchObject
public Partial<PrivacyLevel> GroupListPrivacy { get; set; }
public Partial<PrivacyLevel> FrontPrivacy { get; set; }
public Partial<PrivacyLevel> FrontHistoryPrivacy { get; set; }
public Partial<PrivacyLevel> PronounPrivacy { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("name", Name)
.With("hid", Hid)
.With("description", Description)
.With("tag", Tag)
.With("pronouns", Pronouns)
.With("avatar_url", AvatarUrl)
.With("banner_image", BannerImage)
.With("color", Color)
@@ -41,6 +44,7 @@ public class SystemPatch: PatchObject
.With("group_list_privacy", GroupListPrivacy)
.With("front_privacy", FrontPrivacy)
.With("front_history_privacy", FrontHistoryPrivacy)
.With("pronoun_privacy", PronounPrivacy)
);
public new void AssertIsValid()
@@ -51,6 +55,8 @@ public class SystemPatch: PatchObject
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
if (Tag.Value != null)
AssertValid(Tag.Value, "tag", Limits.MaxSystemTagLength);
if (Pronouns.Value != null)
AssertValid(Pronouns.Value, "pronouns", Limits.MaxPronounsLength);
if (AvatarUrl.Value != null)
AssertValid(AvatarUrl.Value, "avatar_url", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var avatarUri));
@@ -69,6 +75,7 @@ public class SystemPatch: PatchObject
if (o.ContainsKey("name")) patch.Name = o.Value<string>("name").NullIfEmpty();
if (o.ContainsKey("description")) patch.Description = o.Value<string>("description").NullIfEmpty();
if (o.ContainsKey("tag")) patch.Tag = o.Value<string>("tag").NullIfEmpty();
if (o.ContainsKey("pronouns")) patch.Pronouns = o.Value<string>("pronouns").NullIfEmpty();
if (o.ContainsKey("avatar_url")) patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty();
@@ -96,6 +103,9 @@ public class SystemPatch: PatchObject
if (privacy.ContainsKey("description_privacy"))
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
if (privacy.ContainsKey("pronoun_privacy"))
patch.PronounPrivacy = patch.ParsePrivacy(privacy, "pronoun_privacy");
if (privacy.ContainsKey("member_list_privacy"))
patch.MemberListPrivacy = patch.ParsePrivacy(privacy, "member_list_privacy");
@@ -128,6 +138,8 @@ public class SystemPatch: PatchObject
o.Add("description", Description.Value);
if (Tag.IsPresent)
o.Add("tag", Tag.Value);
if (Pronouns.IsPresent)
o.Add("pronouns", Pronouns.Value);
if (AvatarUrl.IsPresent)
o.Add("avatar_url", AvatarUrl.Value);
if (BannerImage.IsPresent)
@@ -137,6 +149,7 @@ public class SystemPatch: PatchObject
if (
DescriptionPrivacy.IsPresent
|| PronounPrivacy.IsPresent
|| MemberListPrivacy.IsPresent
|| GroupListPrivacy.IsPresent
|| FrontPrivacy.IsPresent
@@ -148,6 +161,9 @@ public class SystemPatch: PatchObject
if (DescriptionPrivacy.IsPresent)
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
if (PronounPrivacy.IsPresent)
p.Add("pronoun_privacy", PronounPrivacy.Value.ToJsonString());
if (MemberListPrivacy.IsPresent)
p.Add("member_list_privacy", MemberListPrivacy.Value.ToJsonString());

View File

@@ -3,6 +3,7 @@ namespace PluralKit.Core;
public enum SystemPrivacySubject
{
Description,
Pronouns,
MemberList,
GroupList,
Front,
@@ -17,6 +18,7 @@ public static class SystemPrivacyUtils
_ = subject switch
{
SystemPrivacySubject.Description => system.DescriptionPrivacy = level,
SystemPrivacySubject.Pronouns => system.PronounPrivacy = level,
SystemPrivacySubject.Front => system.FrontPrivacy = level,
SystemPrivacySubject.FrontHistory => system.FrontHistoryPrivacy = level,
SystemPrivacySubject.MemberList => system.MemberListPrivacy = level,
@@ -44,6 +46,10 @@ public static class SystemPrivacyUtils
case "info":
subject = SystemPrivacySubject.Description;
break;
case "pronouns":
case "prns":
subject = SystemPrivacySubject.Pronouns;
break;
case "members":
case "memberlist":
case "list":