mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 04:04:19 -04:00
* Code cleanup. When copying files, if the target file already exists, append (1), (2), etc onto the file (this is enhancing existing implementation to allow multiple numbers) * Added a ton of null checks to UpdateSeriesMetadata and made the code work on the rare case (not really possible) that SeriesMetadata doesn't exist. * Updated Genre code to use strings to ensure a better, more fault tolerant update experience. * More cleanup on the codebase * Fixed a bug where Series SortName was getting emptied on file scan * Fixed a bad copy * Fixed unit tests
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.SignalR.Presence;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace API.SignalR;
|
|
|
|
/// <summary>
|
|
/// Responsible for ushering events to the UI and allowing simple DI hook to send data
|
|
/// </summary>
|
|
public interface IEventHub
|
|
{
|
|
Task SendMessageAsync(string method, SignalRMessage message, bool onlyAdmins = true);
|
|
}
|
|
|
|
public class EventHub : IEventHub
|
|
{
|
|
private readonly IHubContext<MessageHub> _messageHub;
|
|
private readonly IPresenceTracker _presenceTracker;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
public EventHub(IHubContext<MessageHub> messageHub, IPresenceTracker presenceTracker, IUnitOfWork unitOfWork)
|
|
{
|
|
_messageHub = messageHub;
|
|
_presenceTracker = presenceTracker;
|
|
_unitOfWork = unitOfWork;
|
|
|
|
// TODO: When sending a message, queue the message up and on re-connect, reply the queued messages. Queue messages expire on a rolling basis (rolling array)
|
|
}
|
|
|
|
public async Task SendMessageAsync(string method, SignalRMessage message, bool onlyAdmins = true)
|
|
{
|
|
// TODO: If libraryId and NOT onlyAdmins, then perform RBS check before sending the event
|
|
|
|
var users = _messageHub.Clients.All;
|
|
if (onlyAdmins)
|
|
{
|
|
var admins = await _presenceTracker.GetOnlineAdmins();
|
|
users = _messageHub.Clients.Users(admins);
|
|
}
|
|
|
|
|
|
await users.SendAsync(method, message);
|
|
}
|
|
}
|