添加项目文件。
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MessageService.Domain.KeyObjects
|
||||
{
|
||||
public class MessageContent
|
||||
{
|
||||
// 兜底文本
|
||||
[JsonPropertyName("fallback")]
|
||||
public string Fallback { get; init; }
|
||||
|
||||
// 核心 Payload,反序列化时根据外层 MessageType 转换为具体子类
|
||||
public string RawBody { get; init; }
|
||||
public string RawExt { get; set; } = string.Empty;
|
||||
[JsonPropertyName("body")]
|
||||
// 业务代码使用的对象
|
||||
[NotMapped]
|
||||
public object Body => string.IsNullOrEmpty(RawBody) ? null : JsonSerializer.Deserialize<object>(RawBody);
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<string, string> Ext => string.IsNullOrEmpty(RawExt)
|
||||
? new()
|
||||
: JsonSerializer.Deserialize<Dictionary<string, string>>(RawExt);
|
||||
|
||||
// 引用信息
|
||||
[JsonPropertyName("quote")]
|
||||
public QuoteInfo Quote { get; set; } = new();
|
||||
|
||||
private MessageContent() { }
|
||||
public MessageContent(string fallback, object body)
|
||||
{
|
||||
Fallback = fallback;
|
||||
RawBody = body == null ? null : JsonSerializer.Serialize(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using MessageService.Domain.Enums;
|
||||
|
||||
namespace MessageService.Domain.KeyObjects
|
||||
{
|
||||
public record MessageCreateContext(
|
||||
ChatType ChatType,
|
||||
Guid ClientMsgId,
|
||||
Guid SenderId,
|
||||
Guid TargetId
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MessageService.Domain.KeyObjects
|
||||
{
|
||||
public record TextBody(string Text);
|
||||
public record ImageBody(string Url, int Width, int Height, string Thumb);
|
||||
public record VideoBody(string Url, int Width, int Height, string Thumb);
|
||||
public record VoiceBody(string Url, int Duration);
|
||||
public record FileBody(string Url, string FileName, long Size, string Format);
|
||||
}
|
||||
@@ -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