1、优化消息排序逻辑 2、新增加载历史消息 3、修复已知问题 后端: 1、优化消息排序逻辑 2、增加用户信息缓存机制 3、修改日期类型为DateTimeOffset改善时区信息丢失问题 3、修复了已知问题 数据库: 1、新增SequenceId字段用于消息排序 2、新增ClientMsgId字段用于客户端消息回执
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using IM_API.Application.Interfaces;
|
|
using IM_API.Domain.Events;
|
|
using IM_API.Dtos;
|
|
using IM_API.Dtos.Message;
|
|
using IM_API.Interface.Services;
|
|
using IM_API.VOs.Message;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Security.Claims;
|
|
|
|
namespace IM_API.Controllers
|
|
{
|
|
[Authorize]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MessageController : ControllerBase
|
|
{
|
|
private readonly IMessageSevice _messageService;
|
|
private readonly ILogger<MessageController> _logger;
|
|
private readonly IEventBus _eventBus;
|
|
public MessageController(IMessageSevice messageService, ILogger<MessageController> logger, IEventBus eventBus)
|
|
{
|
|
_messageService = messageService;
|
|
_logger = logger;
|
|
_eventBus = eventBus;
|
|
}
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(BaseResponse<MessageBaseVo>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> SendMessage(MessageBaseDto dto)
|
|
{
|
|
var userIdstr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
MessageBaseVo messageBaseVo = new MessageBaseVo();
|
|
if(dto.ChatType == Models.ChatType.PRIVATE)
|
|
{
|
|
messageBaseVo = await _messageService.SendPrivateMessageAsync(int.Parse(userIdstr), dto.ReceiverId, dto);
|
|
}
|
|
else
|
|
{
|
|
messageBaseVo = await _messageService.SendGroupMessageAsync(int.Parse(userIdstr), dto.ReceiverId, dto);
|
|
}
|
|
return Ok(new BaseResponse<MessageBaseVo>(messageBaseVo));
|
|
}
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(BaseResponse<List<MessageBaseVo>>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetMessageList([FromQuery]MessageQueryDto dto)
|
|
{
|
|
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var msgList = await _messageService.GetMessagesAsync(int.Parse(userIdStr),dto);
|
|
var res = new BaseResponse<List<MessageBaseVo>>(msgList);
|
|
return Ok(res);
|
|
}
|
|
}
|
|
}
|