mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using Govor.API.Hubs;
|
|
using Govor.API.Hubs.Infrastructure;
|
|
using Govor.Application.Interfaces;
|
|
using Govor.Core.Models;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace Govor.API.Hubs.Infrastructure;
|
|
|
|
public class PrivateChatGroupManager : IPrivateChatGroupManager
|
|
{
|
|
private readonly IConnectionStore _connectionStore;
|
|
private readonly IHubContext<ChatsHub> _hubContext;
|
|
|
|
public PrivateChatGroupManager(IConnectionStore connectionStore, IHubContext<ChatsHub> hubContext)
|
|
{
|
|
_connectionStore = connectionStore;
|
|
_hubContext = hubContext;
|
|
}
|
|
|
|
public async Task AddUsersToPrivateChatGroupAsync(PrivateChat privateChat)
|
|
{
|
|
var connectionsA = _connectionStore.GetConnections(privateChat.UserAId);
|
|
var connectionsB = _connectionStore.GetConnections(privateChat.UserBId);
|
|
|
|
foreach (var conn in connectionsA.Concat(connectionsB))
|
|
{
|
|
await _hubContext.Groups.AddToGroupAsync(conn, ChatHubConstants.GetPrivateChat(privateChat.Id));
|
|
}
|
|
}
|
|
|
|
public async Task RemoveUsersFromPrivateChatGroupAsync(PrivateChat privateChat)
|
|
{
|
|
var connectionsA = _connectionStore.GetConnections(privateChat.UserAId);
|
|
var connectionsB = _connectionStore.GetConnections(privateChat.UserBId);
|
|
|
|
foreach (var conn in connectionsA.Concat(connectionsB))
|
|
{
|
|
await _hubContext.Groups.RemoveFromGroupAsync(conn, ChatHubConstants.GetPrivateChat(privateChat.Id));
|
|
}
|
|
}
|
|
} |