LANCommander/LANCommander.Server.Services/ChatThreadService.cs
Pat Hartl 191827ed6d Remove manual tracking of user connections, populate participants in database
Removes the manual tracking of user connections by connection ID in the RPC hub. SignalR automatically links connections to connected users and provides Client.User[s] methods.

Also fixes message sending to participants and tracking of participants per thread.
2025-10-28 22:19:48 -05:00

35 lines
1.2 KiB
C#

using AutoMapper;
using LANCommander.Server.Data;
using LANCommander.Server.Data.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ZiggyCreatures.Caching.Fusion;
namespace LANCommander.Server.Services
{
public sealed class ChatThreadService(
ILogger<ChatThreadService> logger,
IFusionCache cache,
IMapper mapper,
IHttpContextAccessor httpContextAccessor,
IDbContextFactory<DatabaseContext> context) : BaseDatabaseService<ChatThread>(logger, cache, mapper, httpContextAccessor, context)
{
public override async Task<ChatThread> AddAsync(ChatThread entity)
{
return await base.AddAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(ct => ct.Messages);
});
}
public override async Task<ChatThread> UpdateAsync(ChatThread entity)
{
return await base.UpdateAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(ct => ct.Participants);
await context.UpdateRelationshipAsync(ct => ct.Messages);
});
}
}
}