Merge branch 'master' of https://gitea.nxsir.cn/nanxun/IM_NEW
This commit is contained in:
@@ -39,5 +39,17 @@ namespace MessageService.WebApi.Application.Conversation
|
||||
var list = await reposity.FindAllStreamKeyAsync(userId);
|
||||
return Result.Success(list.ToList());
|
||||
}
|
||||
|
||||
public async Task<Result<object>> MarkAsReadAsync(Guid conversationId, Guid userId)
|
||||
{
|
||||
var conversation = await reposity.FindByIdAsync(conversationId);
|
||||
if (conversation is null || conversation.UserId != userId)
|
||||
{
|
||||
return Result.Fail<object>(ResultCode.CONVERSATION_NOT_FOUND);
|
||||
}
|
||||
|
||||
conversation.MarkAsRead(lastReadSequenceId: null);
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace MessageService.WebApi.Application.EventHandlers
|
||||
reposity.Create(new Domain.Entities.Conversation(
|
||||
userId: @event.UserId,
|
||||
targetId: @event.GroupId,
|
||||
targetAvatar: @event.Avatar,
|
||||
targetName: @event.GroupNickName,
|
||||
targetAvatar: @event.GroupAvatar ?? @event.Avatar,
|
||||
targetName: @event.GroupName,
|
||||
lastReadSequenceId: null,
|
||||
unreadCount:0,
|
||||
chatType: Domain.Enums.ChatType.GROUP,
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
|
||||
using System.Net.Http.Json;
|
||||
using IM.Commons;
|
||||
|
||||
namespace MessageService.WebApi.Application.IntegrationServices
|
||||
@@ -6,6 +6,12 @@ namespace MessageService.WebApi.Application.IntegrationServices
|
||||
public class GroupMemberIntegrationService : IGroupMemberIntegrationService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
|
||||
public GroupMemberIntegrationService(HttpClient http)
|
||||
{
|
||||
this.http = http;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckGroupMemberAsync(Guid userId, Guid groupId)
|
||||
{
|
||||
var result = await http.GetFromJsonAsync<Result<bool>>(
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace MessageService.WebApi.Application.Message
|
||||
}
|
||||
message.WithQuote(quote);
|
||||
}
|
||||
message.Send();
|
||||
reposity.Create(message);
|
||||
|
||||
return Result.Success(mapper.Map<MessageResponse>(message));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using MessageService.WebApi.Application.Conversation;
|
||||
using IM.ASPNETCore;
|
||||
using MessageService.Infrastructure;
|
||||
using MessageService.WebApi.Application.Conversation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
@@ -30,5 +32,13 @@ namespace MessageService.WebApi.Controllers.Conversation
|
||||
return Ok(await service.GetByIdAsync(id, Guid.Parse(userId)));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(MessageDbContext))]
|
||||
public async Task<IActionResult> MarkRead([FromQuery] Guid conversationId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.MarkAsReadAsync(conversationId, Guid.Parse(userId)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,19 @@ namespace MessageService.WebApi.Controllers.Message
|
||||
RuleFor(r => r.TargetId)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
|
||||
// 文本消息:text 必填
|
||||
When(r => r.MsgType == MessageType.Text, () =>
|
||||
{
|
||||
RuleFor(r => r.Text).NotEmpty().WithMessage("文本消息的 text 字段不能为空");
|
||||
});
|
||||
|
||||
// 图片/视频/语音消息:url 必填
|
||||
When(r => r.MsgType == MessageType.Image || r.MsgType == MessageType.Video
|
||||
|| r.MsgType == MessageType.Voice || r.MsgType == MessageType.File, () =>
|
||||
{
|
||||
RuleFor(r => r.Url).NotEmpty().WithMessage("媒体消息的 url 字段不能为空");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,13 @@
|
||||
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY IM_API_NEW.sln ./
|
||||
|
||||
COPY MessageService.WebApi/MessageService.WebApi.csproj MessageService.WebApi/
|
||||
COPY MessageService.Domain/MessageService.Domain.csproj MessageService.Domain/
|
||||
COPY MessageService.Infrastructure/MessageService.Infrastructure.csproj MessageService.Infrastructure/
|
||||
COPY DomainCommons/IM.DomainCommons.csproj DomainCommons/
|
||||
COPY Infrastructure/IM.Infrastructure.csproj Infrastructure/
|
||||
COPY IM.ASPNETCore/IM.ASPNETCore.csproj IM.ASPNETCore/
|
||||
COPY IM.Commons/IM.Commons.csproj IM.Commons/
|
||||
COPY IM.InitCommon/IM.InitCommon.csproj IM.InitCommon/
|
||||
COPY IM.Jwt/IM.Jwt.csproj IM.Jwt/
|
||||
COPY IM.Protocols/IM.Protocols.csproj IM.Protocols/
|
||||
|
||||
RUN dotnet restore MessageService.WebApi/MessageService.WebApi.csproj
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN find . -type d \( -name obj -o -name bin \) -prune -exec rm -rf {} + 2>/dev/null || true
|
||||
|
||||
RUN dotnet publish MessageService.WebApi/MessageService.WebApi.csproj \
|
||||
-c Release \
|
||||
-o /app/publish \
|
||||
--no-restore
|
||||
-o /app/publish
|
||||
|
||||
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using IM.Commons;
|
||||
using IM.Application.Abstractions;
|
||||
using IM.Commons;
|
||||
using IM.Infrastructure.Efcore;
|
||||
using IM.Protocols.Grpc.Contact;
|
||||
using IM.Protocols.Grpc.User;
|
||||
using MessageService.Infrastructure;
|
||||
using MessageService.WebApi.Application;
|
||||
using MessageService.WebApi.Application.Conversation;
|
||||
using MessageService.WebApi.Application.IntegrationServices;
|
||||
@@ -13,10 +16,14 @@ namespace MessageService.WebApi
|
||||
public void Initialize(IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<Application.Message.MessageService>();
|
||||
services.AddScoped<IUnitOfWork, EfUnitOfWork<MessageDbContext>>();
|
||||
services.AddScoped<ConversationService>();
|
||||
services.AddScoped<SquenceService>();
|
||||
services.AddScoped<IContactIntegrationService, ContactIntegrationService>();
|
||||
services.AddScoped<IGroupMemberIntegrationService, GroupMemberIntegrationService>();
|
||||
services.AddHttpClient<IGroupMemberIntegrationService, GroupMemberIntegrationService>(c =>
|
||||
{
|
||||
c.BaseAddress = new Uri("http://im-group-service:8080/");
|
||||
});
|
||||
services.AddGrpcClient<ContactInternal.ContactInternalClient>((sp, o) =>
|
||||
{
|
||||
var options = sp.GetRequiredService<IOptionsMonitor<GrpcOptions>>();
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace MessageService.WebApi
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.ConfigExtraServices();
|
||||
builder.Services.AddAllGrpcServer();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -30,6 +31,7 @@ namespace MessageService.WebApi
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
app.MapAllGrpcServer();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user