Files
Govor/Govor.API/Hubs/Infrastructure/ConnectionManager.cs
T
Artemy 6d1c53beeb Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
2026-07-16 19:27:45 +07:00

58 lines
2.2 KiB
C#

using System.Collections.Concurrent;
using Govor.Application.Groups;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Interfaces;
using Govor.Application.PrivateUserChats;
using Microsoft.AspNetCore.SignalR;
namespace Govor.API.Hubs.Infrastructure;
public class ConnectionManager : IConnectionManager
{
private readonly IUserGroupsGetterService _userGroupsGetterService;
private readonly IUserPrivateChatsGetterService _userPrivateChatsGetterService;
private readonly IConnectionStore _connectionStore;
private readonly IHubContext<ChatsHub> _hubContext;
public ConnectionManager(
IUserGroupsGetterService userGroupsGetterService,
IConnectionStore connectionStore,
IUserPrivateChatsGetterService userPrivateChatsGetterService,
IHubContext<ChatsHub> hubContext)
{
_userGroupsGetterService = userGroupsGetterService;
_connectionStore = connectionStore;
_userPrivateChatsGetterService = userPrivateChatsGetterService;
_hubContext = hubContext;
}
public async Task OnConnectedAsync(string connectionId, Guid userId)
{
// user
await _hubContext.Groups.AddToGroupAsync(connectionId, ChatHubConstants.GetUserGroup(userId));
_connectionStore.AddConnection(userId, connectionId);
// groups
var userGroups = await _userGroupsGetterService.GetUserGroupsAsync(userId);
foreach (var group in userGroups)
{
await _hubContext.Groups.AddToGroupAsync(connectionId, ChatHubConstants.GetChatGroup(group.Id));
}
// private chats
var chats = await _userPrivateChatsGetterService.GetUserChatsAsync(userId);
foreach (var group in chats)
{
await _hubContext.Groups.AddToGroupAsync(connectionId, ChatHubConstants.GetPrivateChat(group.Id));
}
}
public async Task OnDisconnectedAsync(string connectionId, Guid userId)
{
if (userId != Guid.Empty)
{
await _hubContext.Groups.RemoveFromGroupAsync(connectionId, ChatHubConstants.GetUserGroup(userId));
_connectionStore.RemoveConnection(userId, connectionId);
}
}
}