NotificationOptions.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Linq;
  3. namespace MediaBrowser.Model.Configuration
  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. },
  17. new NotificationOption
  18. {
  19. Type = NotificationType.ServerRestartRequired.ToString(),
  20. Enabled = true
  21. },
  22. new NotificationOption
  23. {
  24. Type = NotificationType.ApplicationUpdateAvailable.ToString(),
  25. Enabled = true
  26. },
  27. new NotificationOption
  28. {
  29. Type = NotificationType.ApplicationUpdateInstalled.ToString(),
  30. Enabled = true
  31. },
  32. new NotificationOption
  33. {
  34. Type = NotificationType.PluginUpdateInstalled.ToString(),
  35. Enabled = true
  36. },
  37. new NotificationOption
  38. {
  39. Type = NotificationType.PluginUninstalled.ToString(),
  40. Enabled = true
  41. },
  42. new NotificationOption
  43. {
  44. Type = NotificationType.InstallationFailed.ToString(),
  45. Enabled = true
  46. },
  47. new NotificationOption
  48. {
  49. Type = NotificationType.PluginInstalled.ToString(),
  50. Enabled = true
  51. }
  52. };
  53. }
  54. public NotificationOption GetOptions(string type)
  55. {
  56. return Options.FirstOrDefault(i => string.Equals(type, i.Type, StringComparison.OrdinalIgnoreCase));
  57. }
  58. public bool IsEnabled(string type)
  59. {
  60. var opt = GetOptions(type);
  61. return opt != null && opt.Enabled;
  62. }
  63. public bool IsServiceEnabled(string service, string notificationType)
  64. {
  65. var opt = GetOptions(notificationType);
  66. return opt == null ||
  67. !opt.DisabledServices.Contains(service, StringComparer.OrdinalIgnoreCase);
  68. }
  69. public bool IsEnabledToMonitorUser(string type, string userId)
  70. {
  71. var opt = GetOptions(type);
  72. return opt != null && opt.Enabled &&
  73. !opt.DisabledMonitorUsers.Contains(userId, StringComparer.OrdinalIgnoreCase);
  74. }
  75. public bool IsEnabledToSendToUser(string type, string userId)
  76. {
  77. var opt = GetOptions(type);
  78. return opt != null && opt.Enabled &&
  79. !opt.DisabledSendToUsers.Contains(userId, StringComparer.OrdinalIgnoreCase);
  80. }
  81. }
  82. public class NotificationOption
  83. {
  84. public string Type { get; set; }
  85. /// <summary>
  86. /// User Ids to not monitor (it's opt out)
  87. /// </summary>
  88. public string[] DisabledMonitorUsers { get; set; }
  89. /// <summary>
  90. /// User Ids to not send to (it's opt out)
  91. /// </summary>
  92. public string[] DisabledSendToUsers { get; set; }
  93. /// <summary>
  94. /// Gets or sets a value indicating whether this <see cref="NotificationOption"/> is enabled.
  95. /// </summary>
  96. /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
  97. public bool Enabled { get; set; }
  98. /// <summary>
  99. /// Gets or sets the title format string.
  100. /// </summary>
  101. /// <value>The title format string.</value>
  102. public string Title { get; set; }
  103. /// <summary>
  104. /// Gets or sets the disabled services.
  105. /// </summary>
  106. /// <value>The disabled services.</value>
  107. public string[] DisabledServices { get; set; }
  108. public NotificationOption()
  109. {
  110. DisabledServices = new string[] { };
  111. DisabledMonitorUsers = new string[] { };
  112. DisabledSendToUsers = new string[] { };
  113. }
  114. }
  115. public enum NotificationType
  116. {
  117. TaskFailed,
  118. InstallationFailed,
  119. NewLibraryContent,
  120. ServerRestartRequired,
  121. ApplicationUpdateAvailable,
  122. ApplicationUpdateInstalled,
  123. PluginInstalled,
  124. PluginUpdateInstalled,
  125. PluginUninstalled,
  126. AudioPlayback,
  127. GamePlayback,
  128. VideoPlayback
  129. }
  130. }