#nullable enable
#pragma warning disable CA1801
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.Http;
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 user's ID.
/// 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}")]
[ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
public IActionResult GetNotifications(
[FromRoute] string userId,
[FromQuery] bool? isRead,
[FromQuery] int? startIndex,
[FromQuery] int? limit)
{
return Ok(new NotificationResultDto());
}
///
/// Endpoint for getting a user's notification summary.
///
/// The user's ID.
/// Notifications summary for the user.
[HttpGet("{UserID}/Summary")]
[ProducesResponseType(typeof(NotificationsSummaryDto), StatusCodes.Status200OK)]
public IActionResult GetNotificationsSummary(
[FromRoute] string userId)
{
return Ok(new NotificationsSummaryDto());
}
///
/// Endpoint for getting notification types.
///
/// All notification types.
[HttpGet("Types")]
[ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
public IActionResult GetNotificationTypes()
{
return Ok(_notificationManager.GetNotificationTypes());
}
///
/// Endpoint for getting notification services.
///
/// All notification services.
[HttpGet("Services")]
[ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
public IActionResult GetNotificationServices()
{
return Ok(_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.
/// Status.
[HttpPost("Admin")]
[ProducesResponseType(StatusCodes.Status200OK)]
public void CreateAdminNotification(
[FromQuery] string name,
[FromQuery] string description,
[FromQuery] string? url,
[FromQuery] NotificationLevel? level)
{
var notification = new NotificationRequest
{
Name = name,
Description = description,
Url = url,
Level = level ?? NotificationLevel.Normal,
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.
/// A comma-separated list of the IDs of notifications which should be set as read.
[HttpPost("{UserID}/Read")]
[ProducesResponseType(StatusCodes.Status200OK)]
public void SetRead(
[FromRoute] string userId,
[FromQuery] string ids)
{
}
///
/// Endpoint to set notifications as unread.
///
/// The userID.
/// A comma-separated list of the IDs of notifications which should be set as unread.
[HttpPost("{UserID}/Unread")]
[ProducesResponseType(StatusCodes.Status200OK)]
public void SetUnread(
[FromRoute] string userId,
[FromQuery] string ids)
{
}
}
}