[backend/api] Change RelationData object into a [Flags] enum (ISH-368)
This maintains the efficiency of JsonIgnoreCondition.WhenWritingDefault while generating a valid OpenAPI schema.
This commit is contained in:
parent
24bde5ad29
commit
663903c992
2 changed files with 36 additions and 26 deletions
|
@ -89,6 +89,31 @@ public class UserProfileRenderer(DatabaseContext db)
|
|||
return await userList.Select(p => RenderOne(p, localUser, data)).AwaitAllAsync();
|
||||
}
|
||||
|
||||
public class RelationData
|
||||
{
|
||||
public required string UserId;
|
||||
public required bool IsSelf;
|
||||
public required bool IsFollowing;
|
||||
public required bool IsFollowedBy;
|
||||
public required bool IsRequested;
|
||||
public required bool IsRequestedBy;
|
||||
public required bool IsBlocking;
|
||||
public required bool IsMuting;
|
||||
|
||||
public static implicit operator Relations(RelationData data)
|
||||
{
|
||||
var res = Relations.None;
|
||||
if (data.IsSelf) res |= Relations.Self;
|
||||
if (data.IsFollowing) res |= Relations.Following;
|
||||
if (data.IsFollowedBy) res |= Relations.FollowedBy;
|
||||
if (data.IsRequested) res |= Relations.Requested;
|
||||
if (data.IsRequestedBy) res |= Relations.RequestedBy;
|
||||
if (data.IsBlocking) res |= Relations.Blocking;
|
||||
if (data.IsMuting) res |= Relations.Muting;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserRendererDto
|
||||
{
|
||||
public Dictionary<string, RelationData>? Relations;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Iceshrimp.Shared.Schemas;
|
||||
|
||||
public class UserProfileResponse
|
||||
|
@ -11,33 +9,20 @@ public class UserProfileResponse
|
|||
public required string? Bio { get; set; }
|
||||
public required int? Followers { get; set; }
|
||||
public required int? Following { get; set; }
|
||||
public required RelationData Relations { get; set; }
|
||||
public required Relations Relations { get; set; }
|
||||
}
|
||||
|
||||
public class RelationData
|
||||
[Flags]
|
||||
public enum Relations
|
||||
{
|
||||
[JsonIgnore] public required string UserId;
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsSelf { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsFollowing { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsFollowedBy { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsRequested { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsRequestedBy { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsBlocking { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public required bool IsMuting { get; set; }
|
||||
None = 0,
|
||||
Self = 1,
|
||||
Following = 2,
|
||||
FollowedBy = 4,
|
||||
Requested = 8,
|
||||
RequestedBy = 16,
|
||||
Blocking = 32,
|
||||
Muting = 64
|
||||
}
|
||||
|
||||
public class UserProfileField
|
||||
|
|
Loading…
Add table
Reference in a new issue