NotificationOptions.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using MediaBrowser.Model.Configuration;
  2. using MediaBrowser.Model.Extensions;
  3. namespace MediaBrowser.Model.Notifications
  4. {
  5. public class NotificationOptions
  6. {
  7. public NotificationOption[] Options { get; set; }
  8. public NotificationOptions()
  9. {
  10. Options = new[]
  11. {
  12. new NotificationOption
  13. {
  14. Type = NotificationType.TaskFailed.ToString(),
  15. Enabled = true,
  16. SendToUserMode = SendToUserType.Admins
  17. },
  18. new NotificationOption
  19. {
  20. Type = NotificationType.ServerRestartRequired.ToString(),
  21. Enabled = true,
  22. SendToUserMode = SendToUserType.Admins
  23. },
  24. new NotificationOption
  25. {
  26. Type = NotificationType.ApplicationUpdateAvailable.ToString(),
  27. Enabled = true,
  28. SendToUserMode = SendToUserType.Admins
  29. },
  30. new NotificationOption
  31. {
  32. Type = NotificationType.ApplicationUpdateInstalled.ToString(),
  33. Enabled = true,
  34. SendToUserMode = SendToUserType.Admins
  35. },
  36. new NotificationOption
  37. {
  38. Type = NotificationType.PluginUpdateInstalled.ToString(),
  39. Enabled = true,
  40. SendToUserMode = SendToUserType.Admins
  41. },
  42. new NotificationOption
  43. {
  44. Type = NotificationType.PluginUninstalled.ToString(),
  45. Enabled = true,
  46. SendToUserMode = SendToUserType.Admins
  47. },
  48. new NotificationOption
  49. {
  50. Type = NotificationType.InstallationFailed.ToString(),
  51. Enabled = true,
  52. SendToUserMode = SendToUserType.Admins
  53. },
  54. new NotificationOption
  55. {
  56. Type = NotificationType.PluginInstalled.ToString(),
  57. Enabled = true,
  58. SendToUserMode = SendToUserType.Admins
  59. },
  60. new NotificationOption
  61. {
  62. Type = NotificationType.PluginError.ToString(),
  63. Enabled = true,
  64. SendToUserMode = SendToUserType.Admins
  65. }
  66. };
  67. }
  68. public NotificationOption GetOptions(string type)
  69. {
  70. foreach (NotificationOption i in Options)
  71. {
  72. if (StringHelper.EqualsIgnoreCase(type, i.Type)) return i;
  73. }
  74. return null;
  75. }
  76. public bool IsEnabled(string type)
  77. {
  78. NotificationOption opt = GetOptions(type);
  79. return opt != null && opt.Enabled;
  80. }
  81. public bool IsServiceEnabled(string service, string notificationType)
  82. {
  83. NotificationOption opt = GetOptions(notificationType);
  84. return opt == null ||
  85. !ListHelper.ContainsIgnoreCase(opt.DisabledServices, service);
  86. }
  87. public bool IsEnabledToMonitorUser(string type, string userId)
  88. {
  89. NotificationOption opt = GetOptions(type);
  90. return opt != null && opt.Enabled &&
  91. !ListHelper.ContainsIgnoreCase(opt.DisabledMonitorUsers, userId);
  92. }
  93. public bool IsEnabledToSendToUser(string type, string userId, UserConfiguration userConfig)
  94. {
  95. NotificationOption opt = GetOptions(type);
  96. if (opt != null && opt.Enabled)
  97. {
  98. if (opt.SendToUserMode == SendToUserType.All)
  99. {
  100. return true;
  101. }
  102. if (opt.SendToUserMode == SendToUserType.Admins && userConfig.IsAdministrator)
  103. {
  104. return true;
  105. }
  106. return ListHelper.ContainsIgnoreCase(opt.SendToUsers, userId);
  107. }
  108. return false;
  109. }
  110. }
  111. }