fix: align backend APIs and upload flow
This commit is contained in:
@@ -40,6 +40,11 @@ namespace MessageService.Domain.Entities
|
||||
/// 最后一条最新消息
|
||||
/// </summary>
|
||||
public string LastMessage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一条消息产生的时间。已读状态等会话元数据更新不得改变该值。
|
||||
/// </summary>
|
||||
public DateTimeOffset? LastMessageTime { get; private set; }
|
||||
private Conversation() { }
|
||||
|
||||
public Conversation(Guid userId, Guid targetId, string targetAvatar, string targetName, long? lastReadSequenceId, int unreadCount, ChatType chatType, string lastMessage)
|
||||
@@ -52,29 +57,29 @@ namespace MessageService.Domain.Entities
|
||||
UnreadCount = unreadCount;
|
||||
ChatType = chatType;
|
||||
LastMessage = lastMessage;
|
||||
LastMessageTime = DateTimeOffset.Now;
|
||||
ModificationTime = DateTime.Now;
|
||||
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)
|
||||
public void SetLastReadSequence(long sequenceId)
|
||||
{
|
||||
if (LastReadSequenceId != null)
|
||||
{
|
||||
LastReadSequenceId = LastReadSequenceId.Value;
|
||||
this.NotifyModified();
|
||||
}
|
||||
if (unreadCount != null)
|
||||
{
|
||||
UnreadCount += unreadCount.Value;
|
||||
NotifyModified();
|
||||
}
|
||||
LastReadSequenceId = sequenceId;
|
||||
NotifyModified();
|
||||
}
|
||||
|
||||
if (lastMsg != null)
|
||||
{
|
||||
LastMessage = lastMsg;
|
||||
NotifyModified();
|
||||
}
|
||||
public void IncrementUnread()
|
||||
{
|
||||
UnreadCount += 1;
|
||||
NotifyModified();
|
||||
}
|
||||
|
||||
public void UpdateLastMessage(string lastMessage, DateTimeOffset messageTime)
|
||||
{
|
||||
LastMessage = lastMessage;
|
||||
LastMessageTime = messageTime;
|
||||
NotifyModified();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +91,7 @@ namespace MessageService.Domain.Entities
|
||||
UnreadCount = 0;
|
||||
if (lastReadSequenceId.HasValue)
|
||||
LastReadSequenceId = lastReadSequenceId.Value;
|
||||
NotifyModified();
|
||||
}
|
||||
|
||||
public void UpdateProfile(string name, string avatar)
|
||||
|
||||
@@ -91,10 +91,10 @@ namespace MessageService.Domain.Entities
|
||||
/// <param name="thumb">预览图</param>
|
||||
/// <param name="sequenceId"></param>
|
||||
/// <returns></returns>
|
||||
public static Message BuildImg(MessageCreateContext ctx, string url,
|
||||
int width, int height, string thumb, long sequenceId)
|
||||
public static Message BuildImg(MessageCreateContext ctx, string? url,
|
||||
int width, int height, string thumb, long sequenceId, Guid? fileId = null)
|
||||
{
|
||||
var content = new MessageContent("[图片]", new ImageBody(url, width, height, thumb));
|
||||
var content = new MessageContent("[图片]", new ImageBody(url, width, height, thumb, fileId));
|
||||
return new Message(ctx, sequenceId, MessageType.Image, content);
|
||||
}
|
||||
/// <summary>
|
||||
@@ -107,10 +107,10 @@ namespace MessageService.Domain.Entities
|
||||
/// <param name="thumb"></param>
|
||||
/// <param name="sequenceId"></param>
|
||||
/// <returns></returns>
|
||||
public static Message BuildVideo(MessageCreateContext ctx, string url,
|
||||
int width, int height, string thumb, long sequenceId)
|
||||
public static Message BuildVideo(MessageCreateContext ctx, string? url,
|
||||
int width, int height, string thumb, long sequenceId, Guid? fileId = null)
|
||||
{
|
||||
var content = new MessageContent("[视频]", new VideoBody(url, width, height, thumb));
|
||||
var content = new MessageContent("[视频]", new VideoBody(url, width, height, thumb, fileId));
|
||||
return new Message(ctx, sequenceId, MessageType.Video, content);
|
||||
}
|
||||
/// <summary>
|
||||
@@ -121,10 +121,10 @@ namespace MessageService.Domain.Entities
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="sequenceId"></param>
|
||||
/// <returns></returns>
|
||||
public static Message BuildVoice(MessageCreateContext ctx, string url,
|
||||
int duration, long sequenceId)
|
||||
public static Message BuildVoice(MessageCreateContext ctx, string? url,
|
||||
int duration, long sequenceId, Guid? fileId = null)
|
||||
{
|
||||
var content = new MessageContent("[音频]", new VoiceBody(url, duration));
|
||||
var content = new MessageContent("[音频]", new VoiceBody(url, duration, fileId));
|
||||
return new Message(ctx, sequenceId, MessageType.Voice, content);
|
||||
}
|
||||
/// <summary>
|
||||
@@ -137,11 +137,11 @@ namespace MessageService.Domain.Entities
|
||||
/// <param name="format">文件格式</param>
|
||||
/// <param name="sequenceId"></param>
|
||||
/// <returns></returns>
|
||||
public static Message BuildFile(MessageCreateContext ctx, string url,
|
||||
public static Message BuildFile(MessageCreateContext ctx, Guid fileId, string? url,
|
||||
string name, long size,
|
||||
string format, long sequenceId)
|
||||
{
|
||||
var content = new MessageContent("[文件]", new FileBody(url, name, size, format));
|
||||
var content = new MessageContent("[文件]", new FileBody(fileId, url, name, size, format));
|
||||
return new Message(ctx, sequenceId, MessageType.File, content);
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
using MessageService.Domain.Entities;
|
||||
|
||||
using MessageService.Domain.Models;
|
||||
|
||||
namespace MessageService.Domain.IReposities
|
||||
{
|
||||
public interface IConversationReposity
|
||||
{
|
||||
Task<Conversation?> FindByIdAsync(Guid id);
|
||||
Task<IEnumerable<Conversation>> FindByUserIdAsync(Guid userId);
|
||||
Task<IEnumerable<Conversation>> FindByTargetIdAsync(Guid targetId);
|
||||
Task<IEnumerable<Conversation>> FindByStreamKeyAsync(string streamKey);
|
||||
Task<Conversation?> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
|
||||
Task<IReadOnlyList<ConversationSummary>> ListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
Task<IEnumerable<Conversation>> FindByTargetIdAsync(Guid targetId, CancellationToken cancellationToken = default);
|
||||
Task<IEnumerable<Conversation>> FindByStreamKeyAsync(string streamKey, CancellationToken cancellationToken = default);
|
||||
Task<Conversation?> FindActiveAsync(Guid userId, Guid targetId, Enums.ChatType chatType, CancellationToken cancellationToken = default);
|
||||
void Create(Conversation conversation);
|
||||
Task<IEnumerable<string>> FindAllStreamKeyAsync(Guid userId);
|
||||
Task<IEnumerable<string>> FindAllStreamKeyAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ namespace MessageService.Domain.IReposities
|
||||
{
|
||||
public interface IMessageReposity
|
||||
{
|
||||
Task<Message?> FindByIdAsync(Guid id);
|
||||
Task<(IEnumerable<Message> messages, bool hasMore)> GetAsync(string streamKey, long? cusor, int direction, int limit);
|
||||
Task<Message?> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
|
||||
Task<(IEnumerable<Message> messages, bool hasMore)> GetAsync(string streamKey, long? cusor, int direction, int limit, CancellationToken cancellationToken = default);
|
||||
Task<(IEnumerable<Message> messages, bool hasMore)> SearchAsync(string streamKey, string keyword, long? cursor, int limit, CancellationToken cancellationToken = default);
|
||||
void Create(Message message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +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);
|
||||
public record ImageBody(string? Url, int Width, int Height, string Thumb, Guid? FileId = null);
|
||||
public record VideoBody(string? Url, int Width, int Height, string Thumb, Guid? FileId = null);
|
||||
public record VoiceBody(string? Url, int Duration, Guid? FileId = null);
|
||||
public record FileBody(Guid FileId, string? Url, string FileName, long Size, string Format);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using MessageService.Domain.Enums;
|
||||
|
||||
namespace MessageService.Domain.Models
|
||||
{
|
||||
public sealed record ConversationSummary(
|
||||
Guid Id,
|
||||
Guid UserId,
|
||||
Guid TargetId,
|
||||
string TargetAvatar,
|
||||
string TargetName,
|
||||
long? LastReadSequenceId,
|
||||
int UnreadCount,
|
||||
ChatType ChatType,
|
||||
string LastMessage,
|
||||
DateTimeOffset DateTime);
|
||||
}
|
||||
Reference in New Issue
Block a user