添加项目文件。
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using IM.DomainCommons;
|
||||
using MessageService.Domain.Enums;
|
||||
|
||||
namespace MessageService.Domain.KeyObjects
|
||||
{
|
||||
public class QuoteInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 被引用消息的唯一标识
|
||||
/// </summary>
|
||||
public Guid MessageId { get; init; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 被引用消息的发送者 ID
|
||||
/// </summary>
|
||||
public Guid SenderId { get; init; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 快照:发送者当时的昵称 (非常关键)
|
||||
/// 避免客户端为了显示 "回复 @张三" 而去额外查询一次用户信息
|
||||
/// </summary>
|
||||
public string SenderName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 被引用消息的类型 (例如:1=文本, 2=图片, 3=文件)
|
||||
/// 帮助客户端决定如何渲染左侧的 Icon (比如是一段文字,还是一个小图片占位符)
|
||||
/// </summary>
|
||||
public MessageType MessageType { get; init; } = MessageType.Text;
|
||||
|
||||
/// <summary>
|
||||
/// 被引用消息的内容预览
|
||||
/// 如果原消息是文本,则截取前50个字符;如果是图片,可以是 "[图片]"
|
||||
/// </summary>
|
||||
public string Preview { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数与自校验
|
||||
/// </summary>
|
||||
public QuoteInfo() { }
|
||||
public QuoteInfo(Guid messageId, Guid senderId, string senderName, MessageType messageType, string preview)
|
||||
{
|
||||
if (messageId == Guid.Empty)
|
||||
throw new DomainException("回复消息ID不可为空");
|
||||
|
||||
if (senderId == Guid.Empty)
|
||||
throw new DomainException("回复发送者ID不可为空");
|
||||
|
||||
MessageId = messageId;
|
||||
SenderId = senderId;
|
||||
SenderName = string.IsNullOrWhiteSpace(senderName) ? "Unknown" : senderName;
|
||||
MessageType = messageType;
|
||||
|
||||
// 限制预览文本的长度,防止 Payload 过大(截断处理)
|
||||
Preview = string.IsNullOrWhiteSpace(preview)
|
||||
? string.Empty
|
||||
: preview.Length > 50 ? preview[..47] + "..." : preview;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user