NotificationOptions.cs 4.1 KB

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