feat: rework group list into member list
This commit is contained in:
@@ -43,9 +43,11 @@ public class PKGroup
|
||||
public string? BannerImage { get; private set; }
|
||||
public string? Color { get; private set; }
|
||||
|
||||
public PrivacyLevel NamePrivacy { get; private set; }
|
||||
public PrivacyLevel DescriptionPrivacy { get; private set; }
|
||||
public PrivacyLevel IconPrivacy { get; private set; }
|
||||
public PrivacyLevel ListPrivacy { get; private set; }
|
||||
public PrivacyLevel MetadataPrivacy { get; private set; }
|
||||
public PrivacyLevel Visibility { get; private set; }
|
||||
|
||||
public Instant Created { get; private set; }
|
||||
@@ -53,12 +55,18 @@ public class PKGroup
|
||||
|
||||
public static class PKGroupExt
|
||||
{
|
||||
public static string? NameFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.NamePrivacy.Get(ctx, group.Name, group.DisplayName ?? group.Name);
|
||||
|
||||
public static string? DescriptionFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.DescriptionPrivacy.Get(ctx, group.Description);
|
||||
|
||||
public static string? IconFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.IconPrivacy.Get(ctx, group.Icon?.TryGetCleanCdnUrl());
|
||||
|
||||
public static Instant? CreatedFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.MetadataPrivacy.Get(ctx, (Instant?)group.Created);
|
||||
|
||||
public static JObject ToJson(this PKGroup group, LookupContext ctx, string? systemStr = null,
|
||||
bool needsMembersArray = false)
|
||||
{
|
||||
@@ -66,18 +74,18 @@ public static class PKGroupExt
|
||||
|
||||
o.Add("id", group.Hid);
|
||||
o.Add("uuid", group.Uuid.ToString());
|
||||
o.Add("name", group.Name);
|
||||
o.Add("name", group.NameFor(ctx));
|
||||
|
||||
if (systemStr != null)
|
||||
o.Add("system", systemStr);
|
||||
|
||||
o.Add("display_name", group.DisplayName);
|
||||
o.Add("display_name", group.NamePrivacy.CanAccess(ctx) ? group.DisplayName : null);
|
||||
o.Add("description", group.DescriptionPrivacy.Get(ctx, group.Description));
|
||||
o.Add("icon", group.IconFor(ctx));
|
||||
o.Add("banner", group.DescriptionPrivacy.Get(ctx, group.BannerImage));
|
||||
o.Add("color", group.Color);
|
||||
|
||||
o.Add("created", group.Created.FormatExport());
|
||||
o.Add("created", group.CreatedFor(ctx)?.FormatExport());
|
||||
|
||||
if (needsMembersArray)
|
||||
o.Add("members", new JArray());
|
||||
@@ -86,9 +94,11 @@ public static class PKGroupExt
|
||||
{
|
||||
var p = new JObject();
|
||||
|
||||
p.Add("name_privacy", group.NamePrivacy.ToJsonString());
|
||||
p.Add("description_privacy", group.DescriptionPrivacy.ToJsonString());
|
||||
p.Add("icon_privacy", group.IconPrivacy.ToJsonString());
|
||||
p.Add("list_privacy", group.ListPrivacy.ToJsonString());
|
||||
p.Add("metadata_privacy", group.MetadataPrivacy.ToJsonString());
|
||||
p.Add("visibility", group.Visibility.ToJsonString());
|
||||
|
||||
o.Add("privacy", p);
|
||||
|
@@ -15,9 +15,11 @@ public class GroupPatch: PatchObject
|
||||
public Partial<string?> BannerImage { get; set; }
|
||||
public Partial<string?> Color { get; set; }
|
||||
|
||||
public Partial<PrivacyLevel> NamePrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> IconPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> ListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MetadataPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> Visibility { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
@@ -28,9 +30,11 @@ public class GroupPatch: PatchObject
|
||||
.With("icon", Icon)
|
||||
.With("banner_image", BannerImage)
|
||||
.With("color", Color)
|
||||
.With("name_privacy", NamePrivacy)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("icon_privacy", IconPrivacy)
|
||||
.With("list_privacy", ListPrivacy)
|
||||
.With("metadata_privacy", MetadataPrivacy)
|
||||
.With("visibility", Visibility)
|
||||
);
|
||||
|
||||
@@ -74,6 +78,9 @@ public class GroupPatch: PatchObject
|
||||
{
|
||||
var privacy = o.Value<JObject>("privacy");
|
||||
|
||||
if (privacy.ContainsKey("name_privacy"))
|
||||
patch.NamePrivacy = patch.ParsePrivacy(privacy, "name_privacy");
|
||||
|
||||
if (privacy.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(privacy, "description_privacy");
|
||||
|
||||
@@ -83,6 +90,9 @@ public class GroupPatch: PatchObject
|
||||
if (privacy.ContainsKey("list_privacy"))
|
||||
patch.ListPrivacy = patch.ParsePrivacy(privacy, "list_privacy");
|
||||
|
||||
if (privacy.ContainsKey("metadata_privacy"))
|
||||
patch.MetadataPrivacy = patch.ParsePrivacy(privacy, "metadata_privacy");
|
||||
|
||||
if (privacy.ContainsKey("visibility"))
|
||||
patch.Visibility = patch.ParsePrivacy(privacy, "visibility");
|
||||
}
|
||||
@@ -110,14 +120,19 @@ public class GroupPatch: PatchObject
|
||||
o.Add("color", Color.Value);
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
NamePrivacy.IsPresent
|
||||
|| DescriptionPrivacy.IsPresent
|
||||
|| IconPrivacy.IsPresent
|
||||
|| ListPrivacy.IsPresent
|
||||
|| MetadataPrivacy.IsPresent
|
||||
|| Visibility.IsPresent
|
||||
)
|
||||
{
|
||||
var p = new JObject();
|
||||
|
||||
if (NamePrivacy.IsPresent)
|
||||
p.Add("name_privacy", NamePrivacy.Value.ToJsonString());
|
||||
|
||||
if (DescriptionPrivacy.IsPresent)
|
||||
p.Add("description_privacy", DescriptionPrivacy.Value.ToJsonString());
|
||||
|
||||
@@ -127,6 +142,9 @@ public class GroupPatch: PatchObject
|
||||
if (ListPrivacy.IsPresent)
|
||||
p.Add("list_privacy", ListPrivacy.Value.ToJsonString());
|
||||
|
||||
if (MetadataPrivacy.IsPresent)
|
||||
p.Add("metadata_privacy", MetadataPrivacy.Value.ToJsonString());
|
||||
|
||||
if (Visibility.IsPresent)
|
||||
p.Add("visibility", Visibility.Value.ToJsonString());
|
||||
|
||||
|
@@ -2,9 +2,11 @@ namespace PluralKit.Core;
|
||||
|
||||
public enum GroupPrivacySubject
|
||||
{
|
||||
Name,
|
||||
Description,
|
||||
Icon,
|
||||
List,
|
||||
Metadata,
|
||||
Visibility
|
||||
}
|
||||
|
||||
@@ -15,9 +17,11 @@ public static class GroupPrivacyUtils
|
||||
// what do you mean switch expressions can't be statements >.>
|
||||
_ = subject switch
|
||||
{
|
||||
GroupPrivacySubject.Name => group.NamePrivacy = level,
|
||||
GroupPrivacySubject.Description => group.DescriptionPrivacy = level,
|
||||
GroupPrivacySubject.Icon => group.IconPrivacy = level,
|
||||
GroupPrivacySubject.List => group.ListPrivacy = level,
|
||||
GroupPrivacySubject.Metadata => group.MetadataPrivacy = level,
|
||||
GroupPrivacySubject.Visibility => group.Visibility = level,
|
||||
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
||||
};
|
||||
@@ -36,6 +40,9 @@ public static class GroupPrivacyUtils
|
||||
{
|
||||
switch (input.ToLowerInvariant())
|
||||
{
|
||||
case "name":
|
||||
subject = GroupPrivacySubject.Name;
|
||||
break;
|
||||
case "description":
|
||||
case "desc":
|
||||
case "text":
|
||||
@@ -54,6 +61,11 @@ public static class GroupPrivacyUtils
|
||||
case "visible":
|
||||
subject = GroupPrivacySubject.Visibility;
|
||||
break;
|
||||
case "meta":
|
||||
case "metadata":
|
||||
case "created":
|
||||
subject = GroupPrivacySubject.Metadata;
|
||||
break;
|
||||
case "list":
|
||||
case "listing":
|
||||
case "members":
|
||||
|
Reference in New Issue
Block a user