17 lines
953 B
C#
17 lines
953 B
C#
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<NativeCompanionPresenceHub> hub, ILogger<ContextWorkspaceNotifications> logger)
|
|
{
|
|
public Task Position(int user) => Send(user, "ContextPositionChanged", new { });
|
|
public Task Invalidate(int user, int? bookId = null, int? chapterId = null, int? sceneId = null, int? projectId = null)
|
|
=> Send(user, "ContextInvalidated", new { bookId, chapterId, sceneId, projectId });
|
|
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); }
|
|
}
|
|
}
|