diff --git a/Iceshrimp.Backend/Controllers/Renderers/UserProfileRenderer.cs b/Iceshrimp.Backend/Controllers/Renderers/UserProfileRenderer.cs index 57c2ba56..43aea633 100644 --- a/Iceshrimp.Backend/Controllers/Renderers/UserProfileRenderer.cs +++ b/Iceshrimp.Backend/Controllers/Renderers/UserProfileRenderer.cs @@ -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? Relations; diff --git a/Iceshrimp.Shared/Schemas/UserProfileResponse.cs b/Iceshrimp.Shared/Schemas/UserProfileResponse.cs index 88a105e4..e1b56e1c 100644 --- a/Iceshrimp.Shared/Schemas/UserProfileResponse.cs +++ b/Iceshrimp.Shared/Schemas/UserProfileResponse.cs @@ -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