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>
|
|
|
|
/// Endpoint for getting a user's notifications.
|
|
|
|
/// </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-15 06:34:50 +00:00
|
|
|
/// <param name="startIndex">The optional index to start at. All notifications with a lower index will be dropped from the results.</param>
|
|
|
|
/// <param name="limit">An optional limit on the number of notifications returned.</param>
|
2020-04-15 06:01:31 +00:00
|
|
|
/// <returns>A read-only list of all of the user's notifications.</returns>
|
|
|
|
[HttpGet("{UserID}")]
|
2020-04-21 05:53:09 +00:00
|
|
|
[ProducesResponseType(typeof(NotificationResultDto), StatusCodes.Status200OK)]
|
|
|
|
public 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>
|
|
|
|
/// Endpoint for getting a user's notification summary.
|
|
|
|
/// </summary>
|
2020-04-15 15:29:29 +00:00
|
|
|
/// <param name="userId">The user's ID.</param>
|
2020-04-15 06:01:31 +00:00
|
|
|
/// <returns>Notifications summary for the user.</returns>
|
2020-04-15 06:34:50 +00:00
|
|
|
[HttpGet("{UserID}/Summary")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(typeof(NotificationsSummaryDto), StatusCodes.Status200OK)]
|
2020-04-21 05:53:09 +00:00
|
|
|
public 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>
|
|
|
|
/// Endpoint for getting notification types.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>All notification types.</returns>
|
|
|
|
[HttpGet("Types")]
|
2020-04-21 05:53:09 +00:00
|
|
|
[ProducesResponseType(typeof(IEnumerable<NotificationTypeInfo>), StatusCodes.Status200OK)]
|
|
|
|
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>
|
|
|
|
/// Endpoint for getting notification services.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>All notification services.</returns>
|
|
|
|
[HttpGet("Services")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(typeof(IEnumerable<NameIdPair>), StatusCodes.Status200OK)]
|
2020-04-21 05:53:09 +00:00
|
|
|
public IEnumerable<NameIdPair> GetNotificationServices()
|
2020-04-15 06:01:31 +00:00
|
|
|
{
|
2020-04-21 05:53:09 +00:00
|
|
|
return _notificationManager.GetNotificationServices();
|
2020-04-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Endpoint to send a notification to all admins.
|
|
|
|
/// </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-15 06:01:31 +00:00
|
|
|
[HttpPost("Admin")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-21 02:16:58 +00:00
|
|
|
public void 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-15 06:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Endpoint to set notifications as read.
|
|
|
|
/// </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-15 06:01:31 +00:00
|
|
|
[HttpPost("{UserID}/Read")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-20 06:00:00 +00:00
|
|
|
public void 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Endpoint to set notifications as unread.
|
|
|
|
/// </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-15 06:01:31 +00:00
|
|
|
[HttpPost("{UserID}/Unread")]
|
2020-04-20 03:06:28 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-04-20 06:00:00 +00:00
|
|
|
public void 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
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|