添加项目文件。
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using IM.DomainCommons;
|
||||
using MessageService.Domain.Enums;
|
||||
using MessageService.Domain.Events;
|
||||
using MessageService.Domain.Tools;
|
||||
|
||||
namespace MessageService.Domain.Entities
|
||||
{
|
||||
public class Conversation : AggregateRootEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
public Guid UserId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对方ID(群聊为群聊ID,单聊为单聊ID)
|
||||
/// </summary>
|
||||
public Guid TargetId { get; private set; }
|
||||
public string TargetAvatar { get; private set; }
|
||||
public string TargetName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一条未读消息ID
|
||||
/// </summary>
|
||||
public long? LastReadSequenceId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 未读消息数
|
||||
/// </summary>
|
||||
public int UnreadCount { get; private set; }
|
||||
|
||||
public ChatType ChatType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息推送唯一标识符
|
||||
/// </summary>
|
||||
public string StreamKey { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一条最新消息
|
||||
/// </summary>
|
||||
public string LastMessage { get; private set; }
|
||||
private Conversation() { }
|
||||
|
||||
public Conversation(Guid userId, Guid targetId, string targetAvatar, string targetName, long? lastReadSequenceId, int unreadCount, ChatType chatType, string lastMessage)
|
||||
{
|
||||
UserId = userId;
|
||||
TargetId = targetId;
|
||||
TargetAvatar = targetAvatar;
|
||||
TargetName = targetName;
|
||||
LastReadSequenceId = lastReadSequenceId;
|
||||
UnreadCount = unreadCount;
|
||||
ChatType = chatType;
|
||||
LastMessage = lastMessage;
|
||||
StreamKey = ChatType == ChatType.GROUP ? StreamKeyBuilder.Group(targetId) : StreamKeyBuilder.Private(userId, targetId);
|
||||
AddDomainEvent(new ConversationCreatedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Update(long? LastReadSequenceId = default, int? unreadCount = default, string? lastMsg = default)
|
||||
{
|
||||
if (LastReadSequenceId != null)
|
||||
{
|
||||
LastReadSequenceId = LastReadSequenceId.Value;
|
||||
}
|
||||
if (unreadCount != null)
|
||||
{
|
||||
UnreadCount += unreadCount.Value;
|
||||
}
|
||||
|
||||
if (lastMsg != null)
|
||||
{
|
||||
LastMessage = lastMsg;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateProfile(string name, string avatar)
|
||||
{
|
||||
TargetAvatar = avatar;
|
||||
TargetName = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user