InternalNotificationService.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Notifications;
  3. using MediaBrowser.Model.Notifications;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using System;
  7. namespace Emby.Server.Implementations.Notifications
  8. {
  9. public class InternalNotificationService : INotificationService, IConfigurableNotificationService
  10. {
  11. private readonly INotificationsRepository _repo;
  12. public InternalNotificationService(INotificationsRepository repo)
  13. {
  14. _repo = repo;
  15. }
  16. public string Name
  17. {
  18. get { return "Dashboard Notifications"; }
  19. }
  20. public Task SendNotification(UserNotification request, CancellationToken cancellationToken)
  21. {
  22. return _repo.AddNotification(new Notification
  23. {
  24. Date = request.Date,
  25. Description = request.Description,
  26. Level = request.Level,
  27. Name = request.Name,
  28. Url = request.Url,
  29. UserId = request.User.Id.ToString("N")
  30. }, cancellationToken);
  31. }
  32. public bool IsEnabledForUser(User user)
  33. {
  34. return user.Policy.IsAdministrator;
  35. }
  36. public bool IsHidden
  37. {
  38. get { return true; }
  39. }
  40. public bool IsEnabled(string notificationType)
  41. {
  42. if (notificationType.IndexOf("playback", StringComparison.OrdinalIgnoreCase) != -1)
  43. {
  44. return false;
  45. }
  46. if (notificationType.IndexOf("newlibrarycontent", StringComparison.OrdinalIgnoreCase) != -1)
  47. {
  48. return false;
  49. }
  50. return true;
  51. }
  52. }
  53. }