using AutoMapper; using IM.Commons; using MessageService.Domain.IReposities; using MessageService.WebApi.Application.Dtos; namespace MessageService.WebApi.Application.Conversation { public class ConversationService { private readonly IConversationReposity reposity; private readonly IMapper mapper; public ConversationService(IConversationReposity reposity, IMapper mapper) { this.reposity = reposity; this.mapper = mapper; } public async Task>> GetByOwnerIdAsync(Guid userId) { var list = await reposity.FindByUserIdAsync(userId); return Result.Success(mapper.Map>(list.ToList())); } public async Task> GetByIdAsync(Guid id, Guid userId) { var conversation = await reposity.FindByIdAsync(id); if (conversation is null || conversation.UserId != userId) { return Result.Fail(ResultCode.CONVERSATION_NOT_FOUND); } return Result.Success(mapper.Map(conversation)); } public async Task>> GetStreamkeysAsync(Guid userId) { var list = await reposity.FindAllStreamKeyAsync(userId); return Result.Success(list.ToList()); } public async Task> MarkAsReadAsync(Guid conversationId, Guid userId) { var conversation = await reposity.FindByIdAsync(conversationId); if (conversation is null || conversation.UserId != userId) { return Result.Fail(ResultCode.CONVERSATION_NOT_FOUND); } conversation.MarkAsRead(lastReadSequenceId: null); return Result.Success(); } } }