Skip to content

Commit

Permalink
Update PostContent.cs
Browse files Browse the repository at this point in the history
修复 富文本 消息  content 字段错误。
  • Loading branch information
fengb3 committed Jul 25, 2024
1 parent 57457f4 commit 12b02bf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Im/Dtos/PostContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
// </copyright>
// <summary>富文本消息</summary>
// ************************************************************************

using System.Text.Json;

namespace FeishuNetSdk.Im.Dtos
{
/// <summary>
/// 富文本消息
/// </summary>
/// <param name="Post">富文本消息。post content格式请参见发送消息Content</param>
[JsonConverter(typeof(PostContentJsonConverter))]
public record PostContent([property: JsonPropertyName("post")] I18nLanguage<PostContent.PostLanguage> Post = default!)
: MessageContent("post")
{
Expand Down Expand Up @@ -57,4 +61,18 @@ public record PostLanguage
public object[][] Content { get; set; } = Array.Empty<object[]>();
}
}

internal class PostContentJsonConverter : JsonConverter<PostContent>
{
public override PostContent Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var postLanguage = JsonSerializer.Deserialize<I18nLanguage<PostContent.PostLanguage>>(ref reader, options);
return new PostContent(postLanguage);

Check warning on line 70 in src/Im/Dtos/PostContent.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'Post' in 'PostContent.PostContent(I18nLanguage<PostLanguage> Post = null)'.

Check warning on line 70 in src/Im/Dtos/PostContent.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'Post' in 'PostContent.PostContent(I18nLanguage<PostLanguage> Post = null)'.
}

public override void Write(Utf8JsonWriter writer, PostContent value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value.Post, options);
}
}
}

0 comments on commit 12b02bf

Please sign in to comment.