Add online pinging and friendship verification features

Introduces OnlinePingingController and related integration/unit tests for user online status updates. Adds PingHandlerService with memory cache throttling, IPingHandlerService interface, and service registration. Implements VerifyFriendship service and interface for friendship validation, with exception handling. Refactors CurrentUserService for improved user ID extraction and testability. Updates ChatsHub to verify friendship before messaging. Cleans up MediaController and optimizes UsersRepository queries by removing unnecessary includes.
This commit is contained in:
Artemy
2025-07-02 19:16:49 +07:00
parent 0669614a5e
commit 565d3249e5
14 changed files with 483 additions and 32 deletions
+8 -5
View File
@@ -1,4 +1,5 @@
using System.Security.Claims;
using Govor.Application.Interfaces;
using Govor.Contracts.Requests.SignalR;
using Govor.Core.Models;
using Govor.Core.Repositories.Users;
@@ -13,6 +14,7 @@ namespace Govor.API.Hubs;
public class ChatsHub : Hub
{
private readonly IUsersRepository _usersRepository;
private readonly IVerifyFriendship _verifyFriendship;
private readonly ILogger<ChatsHub> _logger;
public ChatsHub(IUsersRepository usersRepository, ILogger<ChatsHub> logger)
@@ -60,21 +62,22 @@ public class ChatsHub : Hub
var senderId = GetUserId();
// Проверка существования получателя
/*try
// Проверка существования получателя и установленной дружбы
try
{
await _usersRepository.FindByIdAsync(toUserId);
await _usersRepository.FindByIdAsync(request.RecipientId);
await _verifyFriendship.VerifyAsync(senderId, request.RecipientId);
}
catch (NotFoundByKeyException<User> ex)
{
_logger.LogWarning("Recipient user {ToUserId} not found", toUserId);
_logger.LogWarning("Recipient user {ToUserId} not found", request.RecipientId);
throw;
}
catch (ArgumentException ex)
{
_logger.LogWarning("Invalid recipient userId received from user {UserId}", GetUserId());
throw;
}*/
}
try
{