From aa7ca60b5c0109f4f2a1c7d21e0e4dbbf291fe00 Mon Sep 17 00:00:00 2001 From: sweetymajo <115923988+sweetymajo@users.noreply.github.com> Date: Mon, 26 Aug 2024 20:58:30 +0800 Subject: [PATCH] MultiMsg supports custom detail text. (#508) --- .../Message/Entity/MultiMsgEntity.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Lagrange.Core/Message/Entity/MultiMsgEntity.cs b/Lagrange.Core/Message/Entity/MultiMsgEntity.cs index 7a8354ddf..fdbbbd70d 100644 --- a/Lagrange.Core/Message/Entity/MultiMsgEntity.cs +++ b/Lagrange.Core/Message/Entity/MultiMsgEntity.cs @@ -20,6 +20,8 @@ public class MultiMsgEntity : IMessageEntity public List Chains { get; } + public string? DetailStr { get; set; } + internal MultiMsgEntity() => Chains = new List(); public MultiMsgEntity(string resId) @@ -28,10 +30,11 @@ public MultiMsgEntity(string resId) Chains = new List(); } - public MultiMsgEntity(uint? groupUin, List chains) + public MultiMsgEntity(uint? groupUin, List chains, string? detail = null) { GroupUin = groupUin; Chains = chains; + DetailStr = detail; } IEnumerable IMessageEntity.PackElement() @@ -73,19 +76,26 @@ IEnumerable IMessageEntity.PackElement() View = "contact" }; - if (!Chains.Select(x => x.GetEntity()).Any()) + if (!string.IsNullOrEmpty(DetailStr)) { - json.Meta.Detail.News.Add(new News { Text = "[This message is send from Lagrange.Core]" }); + json.Meta.Detail.News.Add(new News { Text = DetailStr }); } else { - for (int i = 0; i < count; i++) + if (!Chains.Select(x => x.GetEntity()).Any()) + { + json.Meta.Detail.News.Add(new News { Text = "[This message is send from Lagrange.Core]" }); + } + else { - var chain = Chains[i]; - var member = chain.GroupMemberInfo; - var friend = chain.FriendInfo; - string text = $"{member?.MemberCard ?? member?.MemberName ?? friend?.Nickname}: {chain.ToPreviewText()}"; - json.Meta.Detail.News.Add(new News { Text = text }); + for (int i = 0; i < count; i++) + { + var chain = Chains[i]; + var member = chain.GroupMemberInfo; + var friend = chain.FriendInfo; + string text = $"{member?.MemberCard ?? member?.MemberName ?? friend?.Nickname}: {chain.ToPreviewText()}"; + json.Meta.Detail.News.Add(new News { Text = text }); + } } }