Skip to content

Commit

Permalink
MultiMsg supports custom detail text. (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetymajo authored Aug 26, 2024
1 parent 6c930b7 commit aa7ca60
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Lagrange.Core/Message/Entity/MultiMsgEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class MultiMsgEntity : IMessageEntity

public List<MessageChain> Chains { get; }

public string? DetailStr { get; set; }

internal MultiMsgEntity() => Chains = new List<MessageChain>();

public MultiMsgEntity(string resId)
Expand All @@ -28,10 +30,11 @@ public MultiMsgEntity(string resId)
Chains = new List<MessageChain>();
}

public MultiMsgEntity(uint? groupUin, List<MessageChain> chains)
public MultiMsgEntity(uint? groupUin, List<MessageChain> chains, string? detail = null)
{
GroupUin = groupUin;
Chains = chains;
DetailStr = detail;
}

IEnumerable<Elem> IMessageEntity.PackElement()
Expand Down Expand Up @@ -73,19 +76,26 @@ IEnumerable<Elem> IMessageEntity.PackElement()
View = "contact"
};

if (!Chains.Select(x => x.GetEntity<TextEntity>()).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<TextEntity>()).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 });
}
}
}

Expand Down

0 comments on commit aa7ca60

Please sign in to comment.