diff options
Diffstat (limited to 'MediaBrowser.Api/NotificationsService.cs')
| -rw-r--r-- | MediaBrowser.Api/NotificationsService.cs | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/MediaBrowser.Api/NotificationsService.cs b/MediaBrowser.Api/NotificationsService.cs index 796fcdab1..d17b3c368 100644 --- a/MediaBrowser.Api/NotificationsService.cs +++ b/MediaBrowser.Api/NotificationsService.cs @@ -1,8 +1,10 @@ -using MediaBrowser.Controller.Notifications; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Notifications; using MediaBrowser.Model.Notifications; using ServiceStack; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -31,12 +33,38 @@ namespace MediaBrowser.Api public string UserId { get; set; } } - [Route("/Notifications/{UserId}", "POST", Summary = "Adds a notifications")] - public class AddUserNotification : IReturnVoid + [Route("/Notifications/Types", "GET", Summary = "Gets notification types")] + public class GetNotificationTypes : IReturn<List<NotificationTypeInfo>> + { + } + + [Route("/Notifications/Services", "GET", Summary = "Gets notification types")] + public class GetNotificationServices : IReturn<List<NotificationServiceInfo>> + { + } + + [Route("/Notifications", "POST", Summary = "Sends a notification to all admin users")] + public class AddAdminNotification : IReturnVoid { - [ApiMember(Name = "Id", Description = "The Id of the new notification. If unspecified one will be provided.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string Id { get; set; } + [ApiMember(Name = "Name", Description = "The notification's name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public string Name { get; set; } + + [ApiMember(Name = "Description", Description = "The notification's description", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public string Description { get; set; } + + [ApiMember(Name = "ImageUrl", Description = "The notification's image url", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public string ImageUrl { get; set; } + [ApiMember(Name = "Url", Description = "The notification's info url", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public string Url { get; set; } + + [ApiMember(Name = "Level", Description = "The notification level", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public NotificationLevel Level { get; set; } + } + + [Route("/Notifications/{UserId}", "POST", Summary = "Sends a notification to a user")] + public class AddUserNotification : IReturnVoid + { [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public string UserId { get; set; } @@ -77,11 +105,13 @@ namespace MediaBrowser.Api { private readonly INotificationsRepository _notificationsRepo; private readonly INotificationManager _notificationManager; + private readonly IUserManager _userManager; - public NotificationsService(INotificationsRepository notificationsRepo, INotificationManager notificationManager) + public NotificationsService(INotificationsRepository notificationsRepo, INotificationManager notificationManager, IUserManager userManager) { _notificationsRepo = notificationsRepo; _notificationManager = notificationManager; + _userManager = userManager; } public void Post(AddUserNotification request) @@ -91,11 +121,25 @@ namespace MediaBrowser.Api Task.WaitAll(task); } + public object Get(GetNotificationTypes request) + { + var result = _notificationManager.GetNotificationTypes().ToList(); + + return ToOptimizedResult(result); + } + + public object Get(GetNotificationServices request) + { + var result = _notificationManager.GetNotificationServices().ToList(); + + return ToOptimizedResult(result); + } + public object Get(GetNotificationsSummary request) { var result = _notificationsRepo.GetNotificationsSummary(request.UserId); - return result; + return ToOptimizedResult(result); } private async Task AddNotification(AddUserNotification request) @@ -113,6 +157,29 @@ namespace MediaBrowser.Api await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false); } + public void Post(AddAdminNotification request) + { + // This endpoint really just exists as post of a real with sickbeard + var task = AddNotification(request); + + Task.WaitAll(task); + } + + private async Task AddNotification(AddAdminNotification request) + { + var notification = new NotificationRequest + { + Date = DateTime.UtcNow, + Description = request.Description, + Level = request.Level, + Name = request.Name, + Url = request.Url, + UserIds = _userManager.Users.Where(i => i.Configuration.IsAdministrator).Select(i => i.Id.ToString("N")).ToList() + }; + + await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false); + } + public void Post(MarkRead request) { var task = MarkRead(request.Ids, request.UserId, true); |
