Skip to content

Commit

Permalink
[Core] parse markdown entity (LagrangeDev#658)
Browse files Browse the repository at this point in the history
* add: parse markdown entity

* fix: exception throw when preview markdown string
  • Loading branch information
dogdie233 authored Oct 24, 2024
1 parent 946891c commit b5857eb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Lagrange.Core/Message/Entity/MarkdownEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Lagrange.Core.Message.Entity;

[MessageElement(typeof(CommonElem))]
public class MarkdownEntity : IMessageEntity
{
public MarkdownData Data { get; set; }
Expand All @@ -30,9 +31,18 @@ public class MarkdownEntity : IMessageEntity
}
};

IMessageEntity? IMessageEntity.UnpackElement(Elem elem) => null;
IMessageEntity? IMessageEntity.UnpackElement(Elem elem)
{
if (elem.CommonElem?.ServiceType != 45 || elem.CommonElem?.BusinessType != 1)
return null;

return new MarkdownEntity(Serializer.Deserialize<MarkdownData>(elem.CommonElem.PbElem.AsSpan()));
}

public string ToPreviewString() => throw new NotImplementedException();
public string ToPreviewString()
{
return $"[Markdown] {Data.Content}";
}
}

[ProtoContract]
Expand Down

0 comments on commit b5857eb

Please sign in to comment.