Починка реакций

This commit is contained in:
Халимов Рустам
2026-03-13 12:46:01 +03:00
parent 9a32442b5c
commit ca1d88191c
438 changed files with 374 additions and 20961 deletions

View File

@@ -1,11 +1,12 @@
using Microsoft.AspNetCore.SignalR;
using System.Collections.Concurrent;
using System.Security.Claims;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Vortex.Modules.Chats.Application.Messages.Send;
using Vortex.Modules.Chats.Domain;
using Vortex.Shared.Kernel;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Concurrent;
using System.Security.Claims;
namespace Vortex.Modules.Chats.Infrastructure.SignalR;
@@ -23,12 +24,14 @@ public sealed class ChatHub : Hub
private readonly ISender _sender;
private readonly IUserContext _userContext;
private readonly IChatRepository _chatRepository;
private readonly ILogger<ChatHub> _logger;
public ChatHub(ISender sender, IUserContext userContext, IChatRepository chatRepository)
public ChatHub(ISender sender, IUserContext userContext, IChatRepository chatRepository, ILogger<ChatHub> logger)
{
_sender = sender;
_userContext = userContext;
_chatRepository = chatRepository;
_logger = logger;
}
public override async Task OnConnectedAsync()
@@ -48,6 +51,10 @@ public sealed class ChatHub : Hub
await Groups.AddToGroupAsync(Context.ConnectionId, chat.Id.ToString());
}
_logger.LogInformation("User {UserId} connected with {ConnectionId}, added to {ChatCount} chats",
userId, Context.ConnectionId, userChats.Count);
await Clients.Others.SendAsync("user_online", new { userId });
}
await base.OnConnectedAsync();
@@ -67,6 +74,7 @@ public sealed class ChatHub : Hub
await Clients.Others.SendAsync("user_offline", new { userId, lastSeen = DateTime.UtcNow });
}
}
_logger.LogInformation("User {UserId} disconnected", userId);
}
await base.OnDisconnectedAsync(exception);
}
@@ -78,7 +86,8 @@ public sealed class ChatHub : Hub
[HubMethodName("send_message")]
public async Task SendMessage(SendMessageHubRequest request)
{
var attachments = request.Attachments?.Select(a =>
var attachments = request.Attachments?.Select(a =>
new AttachmentRequest(a.Type, a.Url, a.FileName, a.FileSize)).ToList();
var command = new SendMessageCommand(
@@ -165,25 +174,43 @@ public sealed class ChatHub : Hub
[HubMethodName("add_reaction")]
public async Task AddReaction(AddReactionRequest request)
{
_logger.LogInformation("AddReaction called: MessageId={MessageId}, ChatId={ChatId}, Emoji={Emoji}, UserId={UserId}",
request.MessageId, request.ChatId, request.Emoji, _userContext.UserId);
var command = new Vortex.Modules.Chats.Application.Messages.React.AddReactionCommand(
request.MessageId, _userContext.UserId, request.Emoji, request.ChatId);
var result = await _sender.Send(command);
if (result.IsFailure)
{
_logger.LogWarning("AddReaction failed: {Error}", result.Error.Description);
throw new HubException(result.Error.Description);
}
_logger.LogInformation("AddReaction completed successfully");
}
[HubMethodName("remove_reaction")]
public async Task RemoveReaction(RemoveReactionRequest request)
{
_logger.LogInformation("RemoveReaction called: MessageId={MessageId}, ChatId={ChatId}, Emoji={Emoji}, UserId={UserId}",
request.MessageId, request.ChatId, request.Emoji, _userContext.UserId);
var command = new Vortex.Modules.Chats.Application.Messages.React.RemoveReactionCommand(
request.MessageId, _userContext.UserId, request.Emoji, request.ChatId);
var result = await _sender.Send(command);
if (result.IsFailure)
{
_logger.LogWarning("RemoveReaction failed: {Error}", result.Error.Description);
throw new HubException(result.Error.Description);
}
_logger.LogInformation("RemoveReaction completed successfully");
}
// ────────────────────────────────────────────────────────────────
@@ -239,8 +266,9 @@ public sealed class ChatHub : Hub
offer = request.Offer,
callType = request.CallType,
chatId = request.ChatId,
callerInfo = new
{
callerInfo = new
{
id = _userContext.UserId.ToString(),
displayName = displayName,
avatar = avatar,
@@ -326,7 +354,8 @@ public sealed class ChatHub : Hub
{
var chatId = request.ChatId;
var userId = _userContext.UserId.ToString();
var displayName = Context.User?.FindFirstValue("name") ?? Context.User?.FindFirstValue(ClaimTypes.Name) ?? "User";
var avatar = Context.User?.FindFirstValue("avatar");
var username = Context.User?.FindFirstValue("unique_name") ?? Context.User?.Identity?.Name ?? "user";
@@ -337,7 +366,8 @@ public sealed class ChatHub : Hub
participants.TryAdd(userId, userInfo);
// Notify others
await Clients.Group(chatId).SendAsync("group_call_user_joined", new {
await Clients.Group(chatId).SendAsync("group_call_user_joined", new
{
chatId = chatId,
userId = userId,
userInfo = userInfo
@@ -345,7 +375,8 @@ public sealed class ChatHub : Hub
// Send current participants to joiner (excluding self)
var others = participants.Values.Where(p => p.Id != userId).ToList();
await Clients.Caller.SendAsync("group_call_participants", new {
await Clients.Caller.SendAsync("group_call_participants", new
{
chatId = chatId,
participants = others
});
@@ -364,7 +395,8 @@ public sealed class ChatHub : Hub
}
}
await Clients.Group(chatId).SendAsync("group_call_user_left", new {
await Clients.Group(chatId).SendAsync("group_call_user_left", new
{
chatId = chatId,
userId = userId
});
@@ -437,7 +469,8 @@ public sealed class ChatHub : Hub
}
}
await Clients.Group(chatId).SendAsync("screen_share_started", new {
await Clients.Group(chatId).SendAsync("screen_share_started", new
{
chatId = chatId,
userId = userId
});
@@ -455,7 +488,8 @@ public sealed class ChatHub : Hub
}
}
await Clients.Group(chatId).SendAsync("screen_share_stopped", new {
await Clients.Group(chatId).SendAsync("screen_share_stopped", new
{
chatId = chatId,
userId = userId
});
@@ -467,9 +501,12 @@ public sealed class ChatHub : Hub
public record AttachmentHubRequest(string Type, string Url, string? FileName, long? FileSize);
public record SendMessageHubRequest(
Guid ChatId,
string? Content,
string Type,
Guid ChatId,
string? Content,
string Type,
List<AttachmentHubRequest>? Attachments = null,
Guid? ReplyToId = null,
string? Quote = null,