using Microsoft.AspNetCore.SignalR; using PlotLine.Hubs; using PlotLine.Models; namespace PlotLine.Services; public interface IStoryIntelligenceProgressNotifier { Task PublishAsync(StoryIntelligenceRunProgressEvent progress); } public sealed class StoryIntelligenceProgressNotifier( IHubContext hub, IStoryIntelligenceGlobalProgressService globalProgress) : IStoryIntelligenceProgressNotifier { public async Task PublishAsync(StoryIntelligenceRunProgressEvent progress) { var userGroup = StoryIntelligenceHub.UserGroup(progress.UserID); await hub.Clients.Group(userGroup) .SendAsync("StoryIntelligenceRunProgressChanged", progress); var aggregate = await globalProgress.GetForUserAsync(progress.UserID); await hub.Clients.Group(userGroup) .SendAsync("StoryIntelligenceGlobalProgressChanged", aggregate); } }