using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Jellyfin.Api.Models.NotificationDtos;
using Jellyfin.Data.Enums;
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;
}
///
/// Gets a user's notifications.
///
/// Notifications returned.
/// An containing a list of notifications.
[HttpGet("{userId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetNotifications()
{
return new NotificationResultDto();
}
///
/// Gets a user's notification summary.
///
/// Summary of user's notifications returned.
/// An containing a summary of the users notifications.
[HttpGet("{userId}/Summary")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetNotificationsSummary()
{
return new NotificationsSummaryDto();
}
///
/// Gets notification types.
///
/// All notification types returned.
/// An containing a list of all notification types.
[HttpGet("Types")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IEnumerable GetNotificationTypes()
{
return _notificationManager.GetNotificationTypes();
}
///
/// Gets notification services.
///
/// All notification services returned.
/// An containing a list of all notification services.
[HttpGet("Services")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IEnumerable GetNotificationServices()
{
return _notificationManager.GetNotificationServices();
}
///
/// Sends 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.
/// Notification sent.
/// A .
[HttpPost("Admin")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult 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(user => user.HasPermission(PermissionKind.IsAdministrator))
.Select(user => user.Id)
.ToArray(),
Date = DateTime.UtcNow,
};
_notificationManager.SendNotification(notification, CancellationToken.None);
return NoContent();
}
///
/// Sets notifications as read.
///
/// Notifications set as read.
/// A .
[HttpPost("{userId}/Read")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SetRead()
{
return NoContent();
}
///
/// Sets notifications as unread.
///
/// Notifications set as unread.
/// A .
[HttpPost("{userId}/Unread")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SetUnread()
{
return NoContent();
}
}
}