PlotDirector/PlotLine/Services/StoryIntelligenceProgressNotifier.cs

27 lines
914 B
C#

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<StoryIntelligenceHub> 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);
}
}