a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/api] Switch to a shared JsonSerializerOptions object instead of explicitly specifying json property names via attributes

+127 -126
+1 -1
Iceshrimp.Backend/Controllers/Renderers/UserProfileRenderer.cs
··· 32 32 { 33 33 Name = p.Name, 34 34 Value = p.Value, 35 - IsVerified = p.IsVerified 35 + Verified = p.IsVerified 36 36 }); 37 37 38 38 return new UserProfileResponse
+16 -1
Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs
··· 10 10 using Iceshrimp.Backend.Core.Middleware; 11 11 using Iceshrimp.Backend.Core.Services; 12 12 using Iceshrimp.Backend.Hubs.Authentication; 13 + using Iceshrimp.Shared.Configuration; 13 14 using Microsoft.AspNetCore.Authentication; 14 15 using Microsoft.AspNetCore.DataProtection; 15 16 using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption; ··· 105 106 .ConfigureWithValidation<Config.StorageSection>(configuration, "Storage") 106 107 .ConfigureWithValidation<Config.LocalStorageSection>(configuration, "Storage:Local") 107 108 .ConfigureWithValidation<Config.ObjectStorageSection>(configuration, "Storage:ObjectStorage"); 109 + 110 + services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => 111 + { 112 + options.SerializerOptions.PropertyNamingPolicy = JsonSerialization.Options.PropertyNamingPolicy; 113 + foreach (var converter in JsonSerialization.Options.Converters) 114 + options.SerializerOptions.Converters.Add(converter); 115 + }); 116 + 117 + services.Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(options => 118 + { 119 + options.JsonSerializerOptions.PropertyNamingPolicy = JsonSerialization.Options.PropertyNamingPolicy; 120 + foreach (var converter in JsonSerialization.Options.Converters) 121 + options.JsonSerializerOptions.Converters.Add(converter); 122 + }); 108 123 } 109 124 110 125 private static IServiceCollection ConfigureWithValidation<T>( ··· 260 275 services.AddAuthentication(options => 261 276 { 262 277 options.AddScheme<HubAuthenticationHandler>("HubAuthenticationScheme", null); 263 - 278 + 264 279 // Add a stub authentication handler to bypass strange ASP.NET Core >=7.0 defaults 265 280 // Ref: https://github.com/dotnet/aspnetcore/issues/44661 266 281 options.AddScheme<IAuthenticationHandler>("StubAuthenticationHandler", null);
+6 -5
Iceshrimp.Frontend/Core/Services/ApiClient.cs
··· 4 4 using System.Text; 5 5 using System.Text.Json; 6 6 using Iceshrimp.Frontend.Core.Miscellaneous; 7 + using Iceshrimp.Shared.Configuration; 7 8 using Iceshrimp.Shared.Schemas; 8 9 using Microsoft.AspNetCore.Components.Forms; 9 10 using Microsoft.AspNetCore.Http; ··· 22 23 if (res.IsSuccessStatusCode) 23 24 return; 24 25 25 - var error = await res.Content.ReadFromJsonAsync<ErrorResponse>(); 26 + var error = await res.Content.ReadFromJsonAsync<ErrorResponse>(JsonSerialization.Options); 26 27 if (error == null) 27 28 throw new Exception("Deserialized API error was null"); 28 29 throw new ApiException(error); ··· 61 62 62 63 if (res.IsSuccessStatusCode) 63 64 { 64 - var deserialized = await res.Content.ReadFromJsonAsync<T>(); 65 + var deserialized = await res.Content.ReadFromJsonAsync<T>(JsonSerialization.Options); 65 66 if (deserialized == null) 66 67 throw new Exception("Deserialized API response was null"); 67 68 return (deserialized, null); 68 69 } 69 70 70 - var error = await res.Content.ReadFromJsonAsync<ErrorResponse>(); 71 + var error = await res.Content.ReadFromJsonAsync<ErrorResponse>(JsonSerialization.Options); 71 72 if (error == null) 72 73 throw new Exception("Deserialized API error was null"); 73 74 return (null, error); ··· 102 103 } 103 104 else if (data is not null) 104 105 { 105 - request.Content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, 106 - MediaTypeNames.Application.Json); 106 + request.Content = new StringContent(JsonSerializer.Serialize(data, JsonSerialization.Options), 107 + Encoding.UTF8, MediaTypeNames.Application.Json); 107 108 } 108 109 109 110 return await client.SendAsync(request);
+13
Iceshrimp.Shared/Configuration/JsonSerialization.cs
··· 1 + using System.Text.Json; 2 + using System.Text.Json.Serialization; 3 + 4 + namespace Iceshrimp.Shared.Configuration; 5 + 6 + public static class JsonSerialization 7 + { 8 + public static readonly JsonSerializerOptions Options = new() 9 + { 10 + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, 11 + Converters = { new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower) } 12 + }; 13 + }
+4
Iceshrimp.Shared/Iceshrimp.Shared.csproj
··· 9 9 <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> 10 10 <DebugType>embedded</DebugType> 11 11 </PropertyGroup> 12 + 13 + <ItemGroup> 14 + <PackageReference Include="System.Text.Json" Version="8.0.3" /> 15 + </ItemGroup> 12 16 13 17 </Project>
+5 -7
Iceshrimp.Shared/Schemas/AuthRequest.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class AuthRequest 6 4 { 7 - [J("username")] public required string Username { get; set; } 8 - [J("password")] public required string Password { get; set; } 5 + public required string Username { get; set; } 6 + public required string Password { get; set; } 9 7 } 10 8 11 9 public class RegistrationRequest : AuthRequest 12 10 { 13 - [J("invite")] public string? Invite { get; set; } 11 + public string? Invite { get; set; } 14 12 } 15 13 16 14 public class ChangePasswordRequest 17 15 { 18 - [J("old_password")] public required string OldPassword { get; set; } 19 - [J("new_password")] public required string NewPassword { get; set; } 16 + public required string OldPassword { get; set; } 17 + public required string NewPassword { get; set; } 20 18 }
+6 -14
Iceshrimp.Shared/Schemas/AuthResponse.cs
··· 1 - using System.Text.Json; 2 - using System.Text.Json.Serialization; 3 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 4 - using JE = System.Runtime.Serialization.EnumMemberAttribute; 5 - 6 1 namespace Iceshrimp.Shared.Schemas; 7 2 8 - public class AuthStatusConverter() : JsonStringEnumConverter<AuthStatusEnum>(JsonNamingPolicy.SnakeCaseLower); 9 - 10 - [JsonConverter(typeof(AuthStatusConverter))] 11 3 public enum AuthStatusEnum 12 4 { 13 - [JE(Value = "guest")] Guest, 14 - [JE(Value = "authenticated")] Authenticated, 15 - [JE(Value = "2fa")] TwoFactor 5 + Guest, 6 + Authenticated, 7 + TwoFactor 16 8 } 17 9 18 10 public class AuthResponse 19 11 { 20 - [J("status")] public required AuthStatusEnum Status { get; set; } 21 - [J("user")] public UserResponse? User { get; set; } 22 - [J("token")] public string? Token { get; set; } 12 + public required AuthStatusEnum Status { get; set; } 13 + public UserResponse? User { get; set; } 14 + public string? Token { get; set; } 23 15 }
+7 -9
Iceshrimp.Shared/Schemas/DriveFileResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class DriveFileResponse 6 4 { 7 - [J("id")] public required string Id { get; set; } 8 - [J("url")] public required string Url { get; set; } 9 - [J("thumbnailUrl")] public required string ThumbnailUrl { get; set; } 10 - [J("filename")] public required string Filename { get; set; } 11 - [J("contentType")] public required string ContentType { get; set; } 12 - [J("sensitive")] public required bool Sensitive { get; set; } 13 - [J("description")] public required string? Description { get; set; } 5 + public required string Id { get; set; } 6 + public required string Url { get; set; } 7 + public required string ThumbnailUrl { get; set; } 8 + public required string Filename { get; set; } 9 + public required string ContentType { get; set; } 10 + public required bool Sensitive { get; set; } 11 + public required string? Description { get; set; } 14 12 }
+3 -7
Iceshrimp.Shared/Schemas/ErrorResponse.cs
··· 1 1 using System.Text.Json.Serialization; 2 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 3 2 using JI = System.Text.Json.Serialization.JsonIgnoreAttribute; 4 3 5 4 namespace Iceshrimp.Shared.Schemas; 6 5 7 6 public class ErrorResponse 8 7 { 9 - [J("statusCode")] public required int StatusCode { get; set; } 10 - [J("error")] public required string Error { get; set; } 8 + public required int StatusCode { get; set; } 9 + public required string Error { get; set; } 11 10 12 - [J("message")] 13 11 [JI(Condition = JsonIgnoreCondition.WhenWritingNull)] 14 12 public string? Message { get; set; } 15 13 16 - [J("details")] 17 14 [JI(Condition = JsonIgnoreCondition.WhenWritingNull)] 18 15 public string? Details { get; set; } 19 16 20 - [J("source")] 21 17 [JI(Condition = JsonIgnoreCondition.WhenWritingNull)] 22 18 public string? Source { get; set; } 23 19 24 - [J("requestId")] public required string RequestId { get; set; } 20 + public required string RequestId { get; set; } 25 21 }
+1 -3
Iceshrimp.Shared/Schemas/InviteResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class InviteResponse 6 4 { 7 - [J("code")] public required string Code { get; set; } 5 + public required string Code { get; set; } 8 6 }
+6 -8
Iceshrimp.Shared/Schemas/NoteCreateRequest.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class NoteCreateRequest 6 4 { 7 - [J("text")] public required string Text { get; set; } 8 - [J("cw")] public string? Cw { get; set; } 9 - [J("replyId")] public string? ReplyId { get; set; } 10 - [J("renoteId")] public string? RenoteId { get; set; } 11 - [J("mediaIds")] public List<string>? MediaIds { get; set; } 12 - [J("visibility")] public required NoteVisibility Visibility { get; set; } 5 + public required string Text { get; set; } 6 + public string? Cw { get; set; } 7 + public string? ReplyId { get; set; } 8 + public string? RenoteId { get; set; } 9 + public List<string>? MediaIds { get; set; } 10 + public required NoteVisibility Visibility { get; set; } 13 11 }
+32 -34
Iceshrimp.Shared/Schemas/NoteResponse.cs
··· 1 1 using System.Text.Json.Serialization; 2 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 3 2 using JI = System.Text.Json.Serialization.JsonIgnoreAttribute; 4 3 5 4 namespace Iceshrimp.Shared.Schemas; 6 5 7 6 public class NoteResponse : NoteWithQuote, ICloneable 8 7 { 9 - [J("reply")] public NoteBase? Reply { get; set; } 10 - [J("replyId")] public string? ReplyId { get; set; } 11 - [J("renote")] public NoteWithQuote? Renote { get; set; } 12 - [J("renoteId")] public string? RenoteId { get; set; } 13 - [J("filtered")] public NoteFilteredSchema? Filtered { get; set; } 8 + public NoteBase? Reply { get; set; } 9 + public string? ReplyId { get; set; } 10 + public NoteWithQuote? Renote { get; set; } 11 + public string? RenoteId { get; set; } 12 + public NoteFilteredSchema? Filtered { get; set; } 14 13 15 14 // The properties below are only necessary for building a descendants tree 16 15 [JI] public NoteResponse? Parent; 17 16 18 17 [JI(Condition = JsonIgnoreCondition.WhenWritingNull)] 19 - [J("descendants")] 20 18 public List<NoteResponse>? Descendants { get; set; } 21 19 22 20 public object Clone() => MemberwiseClone(); ··· 24 22 25 23 public class NoteWithQuote : NoteBase 26 24 { 27 - [J("quote")] public NoteBase? Quote { get; set; } 28 - [J("quoteId")] public string? QuoteId { get; set; } 25 + public NoteBase? Quote { get; set; } 26 + public string? QuoteId { get; set; } 29 27 } 30 28 31 29 public class NoteBase 32 30 { 33 - [J("id")] public required string Id { get; set; } 34 - [J("createdAt")] public required string CreatedAt { get; set; } 35 - [J("text")] public required string? Text { get; set; } 36 - [J("cw")] public required string? Cw { get; set; } 37 - [J("visibility")] public required NoteVisibility Visibility { get; set; } 38 - [J("liked")] public required bool Liked { get; set; } 39 - [J("likes")] public required int Likes { get; set; } 40 - [J("renotes")] public required int Renotes { get; set; } 41 - [J("replies")] public required int Replies { get; set; } 42 - [J("user")] public required UserResponse User { get; set; } 43 - [J("attachments")] public required List<NoteAttachment> Attachments { get; set; } 44 - [J("reactions")] public required List<NoteReactionSchema> Reactions { get; set; } 31 + public required string Id { get; set; } 32 + public required string CreatedAt { get; set; } 33 + public required string? Text { get; set; } 34 + public required string? Cw { get; set; } 35 + public required NoteVisibility Visibility { get; set; } 36 + public required bool Liked { get; set; } 37 + public required int Likes { get; set; } 38 + public required int Renotes { get; set; } 39 + public required int Replies { get; set; } 40 + public required UserResponse User { get; set; } 41 + public required List<NoteAttachment> Attachments { get; set; } 42 + public required List<NoteReactionSchema> Reactions { get; set; } 45 43 } 46 44 47 45 public class NoteAttachment 48 46 { 49 - [JI] public required string Id; 50 - [J("url")] public required string Url { get; set; } 51 - [J("thumbnailUrl")] public required string ThumbnailUrl { get; set; } 52 - [J("blurhash")] public required string? Blurhash { get; set; } 53 - [J("alt")] public required string? AltText { get; set; } 47 + [JI] public required string Id; 48 + public required string Url { get; set; } 49 + public required string ThumbnailUrl { get; set; } 50 + public required string? Blurhash { get; set; } 51 + public required string? AltText { get; set; } 54 52 } 55 53 56 54 public class NoteReactionSchema 57 55 { 58 - [JI] public required string NoteId; 59 - [J("name")] public required string Name { get; set; } 60 - [J("count")] public required int Count { get; set; } 61 - [J("reacted")] public required bool Reacted { get; set; } 62 - [J("url")] public required string? Url { get; set; } 56 + [JI] public required string NoteId; 57 + public required string Name { get; set; } 58 + public required int Count { get; set; } 59 + public required bool Reacted { get; set; } 60 + public required string? Url { get; set; } 63 61 } 64 62 65 63 public class NoteFilteredSchema 66 64 { 67 - [J("filterId")] public required long Id { get; set; } 68 - [J("keyword")] public required string Keyword { get; set; } 69 - [J("drop")] public required bool Hide { get; set; } 65 + public required long Id { get; set; } 66 + public required string Keyword { get; set; } 67 + public required bool Hide { get; set; } 70 68 } 71 69 72 70 public enum NoteVisibility
+6 -8
Iceshrimp.Shared/Schemas/NotificationResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class NotificationResponse 6 4 { 7 - [J("id")] public required string Id { get; set; } 8 - [J("type")] public required string Type { get; set; } 9 - [J("read")] public required bool Read { get; set; } 10 - [J("createdAt")] public required string CreatedAt { get; set; } 11 - [J("note")] public NoteResponse? Note { get; set; } 12 - [J("user")] public UserResponse? User { get; set; } 5 + public required string Id { get; set; } 6 + public required string Type { get; set; } 7 + public required bool Read { get; set; } 8 + public required string CreatedAt { get; set; } 9 + public NoteResponse? Note { get; set; } 10 + public UserResponse? User { get; set; } 13 11 }
+3 -5
Iceshrimp.Shared/Schemas/UpdateDriveFileRequest.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class UpdateDriveFileRequest 6 4 { 7 - [J("filename")] public string? Filename { get; set; } 8 - [J("sensitive")] public bool? Sensitive { get; set; } 9 - [J("description")] public string? Description { get; set; } 5 + public string? Filename { get; set; } 6 + public bool? Sensitive { get; set; } 7 + public string? Description { get; set; } 10 8 }
+10 -12
Iceshrimp.Shared/Schemas/UserProfileResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class UserProfileResponse 6 4 { 7 - [J("id")] public required string Id { get; set; } 8 - [J("birthday")] public required string? Birthday { get; set; } 9 - [J("location")] public required string? Location { get; set; } 10 - [J("fields")] public required List<UserProfileField>? Fields { get; set; } 11 - [J("bio")] public required string? Bio { get; set; } 12 - [J("followers")] public required int? Followers { get; set; } 13 - [J("following")] public required int? Following { get; set; } 5 + public required string Id { get; set; } 6 + public required string? Birthday { get; set; } 7 + public required string? Location { get; set; } 8 + public required List<UserProfileField>? Fields { get; set; } 9 + public required string? Bio { get; set; } 10 + public required int? Followers { get; set; } 11 + public required int? Following { get; set; } 14 12 } 15 13 16 14 public class UserProfileField 17 15 { 18 - [J("name")] public required string Name { get; set; } 19 - [J("value")] public required string Value { get; set; } 20 - [J("verified")] public bool? IsVerified { get; set; } 16 + public required string Name { get; set; } 17 + public required string Value { get; set; } 18 + public bool? Verified { get; set; } 21 19 }
+7 -9
Iceshrimp.Shared/Schemas/UserResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class UserResponse 6 4 { 7 - [J("id")] public required string Id { get; set; } 8 - [J("username")] public required string Username { get; set; } 9 - [J("displayName")] public required string? DisplayName { get; set; } 10 - [J("avatarUrl")] public required string? AvatarUrl { get; set; } 11 - [J("bannerUrl")] public required string? BannerUrl { get; set; } 12 - [J("instanceName")] public required string? InstanceName { get; set; } 13 - [J("instanceIconUrl")] public required string? InstanceIconUrl { get; set; } 5 + public required string Id { get; set; } 6 + public required string Username { get; set; } 7 + public required string? DisplayName { get; set; } 8 + public required string? AvatarUrl { get; set; } 9 + public required string? BannerUrl { get; set; } 10 + public required string? InstanceName { get; set; } 11 + public required string? InstanceIconUrl { get; set; } 14 12 }
+1 -3
Iceshrimp.Shared/Schemas/ValueResponse.cs
··· 1 - using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 2 - 3 1 namespace Iceshrimp.Shared.Schemas; 4 2 5 3 public class ValueResponse(long count) 6 4 { 7 - [J("value")] public long Value { get; set; } = count; 5 + public long Value { get; set; } = count; 8 6 }