using Microsoft.AspNetCore.SignalR; using PlotLine.Hubs; namespace PlotLine.Services; // Presentation hints only. A notification failure must never turn a durable save into a failed write. public sealed class ContextWorkspaceNotifications(IHubContext hub, ILogger logger) { public Task Position(int user) => Send(user, "ContextPositionChanged", new { }); public Task Invalidate(int user, int? bookId = null, int? chapterId = null, int? sceneId = null) => Send(user, "ContextInvalidated", new { bookId, chapterId, sceneId }); private async Task Send(int user, string name, object hint) { try { await hub.Clients.Group(NativeCompanionPresenceHub.UserGroup(user)).SendAsync(name, hint); } catch (Exception exception) { logger.LogWarning("Context notification unavailable: {Category}", exception.GetType().Name); } } }