#nullable enable #pragma warning disable CA1801 #pragma warning disable SA1313 using System; using System.Collections.Generic; using System.Linq; using System.Threading; using Jellyfin.Api.Models.NotificationDtos; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Notifications; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Notifications; using Microsoft.AspNetCore.Mvc; namespace Jellyfin.Api.Controllers { /// /// The notification controller. /// public class NotificationsController : BaseJellyfinApiController { private readonly INotificationManager _notificationManager; private readonly IUserManager _userManager; /// /// Initializes a new instance of the class. /// /// The notification manager. /// The user manager. public NotificationsController(INotificationManager notificationManager, IUserManager userManager) { _notificationManager = notificationManager; _userManager = userManager; } /// /// Endpoint for getting a user's notifications. /// /// The UserID. /// An optional filter by IsRead. /// The optional index to start at. All notifications with a lower index will be dropped from the results. /// An optional limit on the number of notifications returned. /// A read-only list of all of the user's notifications. [HttpGet("{UserID}")] public IReadOnlyList GetNotifications( [FromRoute] string UserID, [FromQuery] bool? IsRead, [FromQuery] int? StartIndex, [FromQuery] int? Limit) { return new List(); } /// /// Endpoint for getting a user's notification summary. /// /// The UserID. /// Notifications summary for the user. [HttpGet("{UserId}/Summary")] public NotificationsSummaryDto GetNotificationsSummary( [FromRoute] string UserID) { return new NotificationsSummaryDto(); } /// /// Endpoint for getting notification types. /// /// All notification types. [HttpGet("Types")] public IEnumerable GetNotificationTypes() { return _notificationManager.GetNotificationTypes(); } /// /// Endpoint for getting notification services. /// /// All notification services. [HttpGet("Services")] public IEnumerable GetNotificationServices() { return _notificationManager.GetNotificationServices(); } /// /// Endpoint to send a notification to all admins. /// /// The name of the notification. /// The description of the notification. /// The URL of the notification. /// The level of the notification. [HttpPost("Admin")] public void CreateAdminNotification( [FromForm] string Name, [FromForm] string Description, [FromForm] string? URL, [FromForm] NotificationLevel Level) { var notification = new NotificationRequest { Name = Name, Description = Description, Url = URL, Level = Level, UserIds = _userManager.Users.Where(i => i.Policy.IsAdministrator).Select(i => i.Id).ToArray(), Date = DateTime.UtcNow, }; _notificationManager.SendNotification(notification, CancellationToken.None); } /// /// Endpoint to set notifications as read. /// /// The UserID. /// The IDs of notifications which should be set as read. [HttpPost("{UserID}/Read")] public void SetRead( [FromRoute] string UserID, [FromForm] List IDs) { } /// /// Endpoint to set notifications as unread. /// /// The UserID. /// The IDs of notifications which should be set as unread. [HttpPost("{UserID}/Unread")] public void SetUnread( [FromRoute] string UserID, [FromForm] List IDs) { } } }