2020-04-15 06:01:31 +00:00
|
|
|
#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;
|
2020-04-20 03:06:28 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-04-15 06:01:31 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The notification controller.
|
|
|
|
/// </summary>
|
|
|
|
public class NotificationsController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly INotificationManager _notificationManager;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="NotificationsController" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="notificationManager">The notification manager.</param>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
public NotificationsController(INotificationManager notificationManager, IUserManager userManager)
|
|
|
|
{
|
|
|
|
_notificationManager = notificationManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Gets a user's notifications.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-15 15:29:29 +00:00
|
|
|
/// <param name="userId">The user's ID.</param>
|
2020-04-21 18:10:34 +00:00
|
|
|
/// <param name="isRead">An optional filter by notification read state.</param>
|
2020-04-22 06:21:37 +00:00
|
|
|
/// <param name="startIndex">The optional index to start at. All notifications with a lower index will be omitted from the results.</param>
|
2020-04-15 06:34:50 +00:00
|
|
|
/// <param name="limit">An optional limit on the number of notifications returned.</param>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">Notifications returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing a list of notifications.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpGet("{UserID}")]
|
2020-04-22 16:00:10 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<NotificationResultDto> GetNotifications(
|
2020-04-15 15:29:29 +00:00
|
|
|
[FromRoute] string userId,
|
2020-04-15 06:34:50 +00:00
|
|
|
[FromQuery] bool? isRead,
|
|
|
|
[FromQuery] int? startIndex,
|
|
|
|
[FromQuery] int? limit)
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 05:53:09 +00:00
|
|
|
return new NotificationResultDto();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Gets a user's notification summary.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-15 15:29:29 +00:00
|
|
|
/// <param name="userId">The user's ID.</param>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">Summary of user's notifications returned.</response>
|
|
|
|
/// <returns>An <cref see="OkResult"/> containing a summary of the users notifications.</returns>
|
2020-04-15 06:34:50 +00:00
|
|
|
[HttpGet("{UserID}/Summary")]
|
2020-04-22 16:00:10 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<NotificationsSummaryDto> GetNotificationsSummary(
|
2020-04-15 15:29:29 +00:00
|
|
|
[FromRoute] string userId)
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 05:53:09 +00:00
|
|
|
return new NotificationsSummaryDto();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Gets notification types.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">All notification types returned.</response>
|
|
|
|
/// <returns>An <cref see="OkResult"/> containing a list of all notification types.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpGet("Types")]
|
2020-04-22 16:00:10 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-29 21:53:29 +00:00
|
|
|
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 05:53:09 +00:00
|
|
|
return _notificationManager.GetNotificationTypes();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Gets notification services.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-05-03 20:02:15 +00:00
|
|
|
/// <response code="200">All notification services returned.</response>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <returns>An <cref see="OkResult"/> containing a list of all notification services.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpGet("Services")]
|
2020-04-22 16:00:10 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-29 21:53:29 +00:00
|
|
|
public IEnumerable<NameIdPair> GetNotificationServices()
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-29 21:53:29 +00:00
|
|
|
return _notificationManager.GetNotificationServices();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Sends a notification to all admins.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-15 06:34:50 +00:00
|
|
|
/// <param name="name">The name of the notification.</param>
|
|
|
|
/// <param name="description">The description of the notification.</param>
|
|
|
|
/// <param name="url">The URL of the notification.</param>
|
|
|
|
/// <param name="level">The level of the notification.</param>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">Notification sent.</response>
|
|
|
|
/// <returns>An <cref see="OkResult"/>.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpPost("Admin")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-22 16:00:10 +00:00
|
|
|
public ActionResult CreateAdminNotification(
|
2020-04-19 19:19:15 +00:00
|
|
|
[FromQuery] string name,
|
|
|
|
[FromQuery] string description,
|
|
|
|
[FromQuery] string? url,
|
|
|
|
[FromQuery] NotificationLevel? level)
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 02:16:58 +00:00
|
|
|
var notification = new NotificationRequest
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 02:16:58 +00:00
|
|
|
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,
|
|
|
|
};
|
2020-04-15 06:01:31 +00:00
|
|
|
|
2020-04-21 02:16:58 +00:00
|
|
|
_notificationManager.SendNotification(notification, CancellationToken.None);
|
2020-04-22 16:00:10 +00:00
|
|
|
|
|
|
|
return Ok();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Sets notifications as read.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-15 15:29:29 +00:00
|
|
|
/// <param name="userId">The userID.</param>
|
2020-04-19 19:19:15 +00:00
|
|
|
/// <param name="ids">A comma-separated list of the IDs of notifications which should be set as read.</param>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">Notifications set as read.</response>
|
|
|
|
/// <returns>An <cref see="OkResult"/>.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpPost("{UserID}/Read")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-22 16:00:10 +00:00
|
|
|
public ActionResult SetRead(
|
2020-04-15 15:29:29 +00:00
|
|
|
[FromRoute] string userId,
|
2020-04-19 19:19:15 +00:00
|
|
|
[FromQuery] string ids)
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-22 16:00:10 +00:00
|
|
|
return Ok();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// Sets notifications as unread.
|
2020-04-15 06:01:31 +00:00
|
|
|
/// </summary>
|
2020-04-15 15:29:29 +00:00
|
|
|
/// <param name="userId">The userID.</param>
|
2020-04-19 19:19:15 +00:00
|
|
|
/// <param name="ids">A comma-separated list of the IDs of notifications which should be set as unread.</param>
|
2020-04-28 15:30:59 +00:00
|
|
|
/// <response code="200">Notifications set as unread.</response>
|
|
|
|
/// <returns>An <cref see="OkResult"/>.</returns>
|
2020-04-15 06:01:31 +00:00
|
|
|
[HttpPost("{UserID}/Unread")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-22 16:00:10 +00:00
|
|
|
public ActionResult SetUnread(
|
2020-04-15 15:29:29 +00:00
|
|
|
[FromRoute] string userId,
|
2020-04-19 19:19:15 +00:00
|
|
|
[FromQuery] string ids)
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-22 16:00:10 +00:00
|
|
|
return Ok();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|