using IM.DomainCommons; using MessageService.Domain.Enums; namespace MessageService.Domain.KeyObjects { public class QuoteInfo { /// /// 被引用消息的唯一标识 /// public Guid MessageId { get; init; } = Guid.Empty; /// /// 被引用消息的发送者 ID /// public Guid SenderId { get; init; } = Guid.Empty; /// /// 快照:发送者当时的昵称 (非常关键) /// 避免客户端为了显示 "回复 @张三" 而去额外查询一次用户信息 /// public string SenderName { get; init; } = string.Empty; /// /// 被引用消息的类型 (例如:1=文本, 2=图片, 3=文件) /// 帮助客户端决定如何渲染左侧的 Icon (比如是一段文字,还是一个小图片占位符) /// public MessageType MessageType { get; init; } = MessageType.Text; /// /// 被引用消息的内容预览 /// 如果原消息是文本,则截取前50个字符;如果是图片,可以是 "[图片]" /// public string Preview { get; init; } = string.Empty; /// /// 构造函数与自校验 /// 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; } } }