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.
///
/// The user's ID.
/// An optional filter by notification read state.
/// The optional index to start at. All notifications with a lower index will be omitted from the results.
/// An optional limit on the number of notifications returned.
/// Notifications returned.
/// An containing a list of notifications.
[HttpGet("{userId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "userId", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isRead", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "startIndex", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "limit", Justification = "Imported from ServiceStack")]
public ActionResult GetNotifications(
[FromRoute] string userId,
[FromQuery] bool? isRead,
[FromQuery] int? startIndex,
[FromQuery] int? limit)
{
return new NotificationResultDto();
}
///
/// Gets a user's notification summary.
///
/// The user's ID.
/// Summary of user's notifications returned.
/// An containing a summary of the users notifications.
[HttpGet("{userId}/Summary")]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "userId", Justification = "Imported from ServiceStack")]
public ActionResult GetNotificationsSummary(
[FromRoute] string userId)
{
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.
///
/// The userID.
/// A comma-separated list of the IDs of notifications which should be set as read.
/// Notifications set as read.
/// A .
[HttpPost("{userId}/Read")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "userId", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "ids", Justification = "Imported from ServiceStack")]
public ActionResult SetRead(
[FromRoute] string userId,
[FromQuery] string ids)
{
return NoContent();
}
///
/// Sets notifications as unread.
///
/// The userID.
/// A comma-separated list of the IDs of notifications which should be set as unread.
/// Notifications set as unread.
/// A .
[HttpPost("{userId}/Unread")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "userId", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "ids", Justification = "Imported from ServiceStack")]
public ActionResult SetUnread(
[FromRoute] string userId,
[FromQuery] string ids)
{
return NoContent();
}
}
}