2021-09-27 03:18:17 +00:00
|
|
|
using System;
|
|
|
|
|
2021-08-27 15:03:47 +00:00
|
|
|
using NodaTime;
|
2020-06-29 21:51:12 +00:00
|
|
|
|
2021-09-22 01:42:41 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
2021-08-07 20:39:32 +00:00
|
|
|
|
2020-06-29 21:51:12 +00:00
|
|
|
namespace PluralKit.Core
|
|
|
|
{
|
2021-08-07 20:39:32 +00:00
|
|
|
public readonly struct GroupId: INumericId<GroupId, int>
|
|
|
|
{
|
|
|
|
public int Value { get; }
|
|
|
|
|
|
|
|
public GroupId(int value)
|
|
|
|
{
|
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Equals(GroupId other) => Value == other.Value;
|
|
|
|
|
|
|
|
public override bool Equals(object obj) => obj is GroupId other && Equals(other);
|
|
|
|
|
|
|
|
public override int GetHashCode() => Value;
|
|
|
|
|
|
|
|
public static bool operator ==(GroupId left, GroupId right) => left.Equals(right);
|
|
|
|
|
|
|
|
public static bool operator !=(GroupId left, GroupId right) => !left.Equals(right);
|
|
|
|
|
|
|
|
public int CompareTo(GroupId other) => Value.CompareTo(other.Value);
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-07 20:39:32 +00:00
|
|
|
public override string ToString() => $"Group #{Value}";
|
|
|
|
}
|
|
|
|
|
|
|
|
#nullable enable
|
2020-06-29 21:51:12 +00:00
|
|
|
public class PKGroup
|
|
|
|
{
|
2020-08-21 15:08:49 +00:00
|
|
|
public GroupId Id { get; private set; }
|
|
|
|
public string Hid { get; private set; } = null!;
|
2021-09-27 03:18:17 +00:00
|
|
|
public Guid Uuid { get; private set; }
|
2020-08-21 15:08:49 +00:00
|
|
|
public SystemId System { get; private set; }
|
2020-06-29 21:51:12 +00:00
|
|
|
|
2020-08-21 15:08:49 +00:00
|
|
|
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; }
|
2021-08-02 17:46:12 +00:00
|
|
|
public string? BannerImage { get; private set; }
|
2021-03-28 10:02:41 +00:00
|
|
|
public string? Color { get; private set; }
|
2020-07-07 17:45:26 +00:00
|
|
|
|
2020-08-21 15:08:49 +00:00
|
|
|
public PrivacyLevel DescriptionPrivacy { get; private set; }
|
|
|
|
public PrivacyLevel IconPrivacy { get; private set; }
|
|
|
|
public PrivacyLevel ListPrivacy { get; private set; }
|
|
|
|
public PrivacyLevel Visibility { get; private set; }
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2020-08-21 15:08:49 +00:00
|
|
|
public Instant Created { get; private set; }
|
2020-06-29 21:51:12 +00:00
|
|
|
}
|
2020-08-21 16:31:22 +00:00
|
|
|
|
|
|
|
public static class PKGroupExt
|
|
|
|
{
|
|
|
|
public static string? DescriptionFor(this PKGroup group, LookupContext ctx) =>
|
|
|
|
group.DescriptionPrivacy.Get(ctx, group.Description);
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2020-08-21 16:31:22 +00:00
|
|
|
public static string? IconFor(this PKGroup group, LookupContext ctx) =>
|
2021-08-01 16:51:54 +00:00
|
|
|
group.IconPrivacy.Get(ctx, group.Icon?.TryGetCleanCdnUrl());
|
2021-09-22 01:42:41 +00:00
|
|
|
|
2021-10-12 06:19:42 +00:00
|
|
|
public static JObject ToJson(this PKGroup group, LookupContext ctx, string? systemStr = null, bool isExport = false)
|
2021-09-22 01:42:41 +00:00
|
|
|
{
|
|
|
|
var o = new JObject();
|
|
|
|
|
|
|
|
o.Add("id", group.Hid);
|
2021-10-12 08:25:06 +00:00
|
|
|
o.Add("uuid", group.Uuid.ToString());
|
2021-09-22 01:42:41 +00:00
|
|
|
o.Add("name", group.Name);
|
2021-10-12 06:19:42 +00:00
|
|
|
|
|
|
|
if (systemStr != null)
|
|
|
|
o.Add("system", systemStr);
|
|
|
|
|
2021-09-22 01:42:41 +00:00
|
|
|
o.Add("display_name", group.DisplayName);
|
|
|
|
o.Add("description", group.DescriptionPrivacy.Get(ctx, group.Description));
|
|
|
|
o.Add("icon", group.Icon);
|
|
|
|
o.Add("banner", group.DescriptionPrivacy.Get(ctx, group.BannerImage));
|
|
|
|
o.Add("color", group.Color);
|
|
|
|
|
|
|
|
o.Add("created", group.Created.FormatExport());
|
|
|
|
|
|
|
|
if (isExport)
|
|
|
|
o.Add("members", new JArray());
|
|
|
|
|
|
|
|
if (ctx == LookupContext.ByOwner)
|
|
|
|
{
|
|
|
|
var p = new JObject();
|
|
|
|
|
|
|
|
p.Add("description_privacy", group.DescriptionPrivacy.ToJsonString());
|
|
|
|
p.Add("icon_privacy", group.IconPrivacy.ToJsonString());
|
|
|
|
p.Add("list_privacy", group.ListPrivacy.ToJsonString());
|
|
|
|
p.Add("visibility", group.Visibility.ToJsonString());
|
|
|
|
|
|
|
|
o.Add("privacy", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
o.Add("privacy", null);
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
2020-08-21 16:31:22 +00:00
|
|
|
}
|
2020-06-29 21:51:12 +00:00
|
|
|
}
|