diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-04-27 13:54:43 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-04-27 13:54:43 -0400 |
| commit | 9a27cbab8c025b5c106e2ecb9dd85060cd90cc87 (patch) | |
| tree | 73964c9502ca988353429524743715e4ae3e9b20 /MediaBrowser.Server.Implementations/Notifications | |
| parent | bfe76e2077db3ce07363407a73f4d5f99e7625b7 (diff) | |
added send to user mode
Diffstat (limited to 'MediaBrowser.Server.Implementations/Notifications')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs | 22 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/Notifications/NotificationManager.cs | 52 |
2 files changed, 60 insertions, 14 deletions
diff --git a/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs b/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs index bf5228dd9..cfda23a65 100644 --- a/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs +++ b/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Notifications; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Notifications; @@ -11,10 +12,12 @@ namespace MediaBrowser.Server.Implementations.Notifications public class CoreNotificationTypes : INotificationTypeFactory { private readonly ILocalizationManager _localization; + private readonly IServerApplicationHost _appHost; - public CoreNotificationTypes(ILocalizationManager localization) + public CoreNotificationTypes(ILocalizationManager localization, IServerApplicationHost appHost) { _localization = localization; + _appHost = appHost; } public IEnumerable<NotificationTypeInfo> GetNotificationTypes() @@ -23,12 +26,6 @@ namespace MediaBrowser.Server.Implementations.Notifications { new NotificationTypeInfo { - Type = NotificationType.ApplicationUpdateAvailable.ToString(), - DefaultTitle = "A new version of Media Browser Server is available for download." - }, - - new NotificationTypeInfo - { Type = NotificationType.ApplicationUpdateInstalled.ToString(), DefaultTitle = "A new version of Media Browser Server has been installed.", Variables = new List<string>{"Version"} @@ -104,6 +101,15 @@ namespace MediaBrowser.Server.Implementations.Notifications } }; + if (!_appHost.CanSelfUpdate) + { + knownTypes.Add(new NotificationTypeInfo + { + Type = NotificationType.ApplicationUpdateAvailable.ToString(), + DefaultTitle = "A new version of Media Browser Server is available for download." + }); + } + foreach (var type in knownTypes) { Update(type); diff --git a/MediaBrowser.Server.Implementations/Notifications/NotificationManager.cs b/MediaBrowser.Server.Implementations/Notifications/NotificationManager.cs index ff8d35e28..300d2c351 100644 --- a/MediaBrowser.Server.Implementations/Notifications/NotificationManager.cs +++ b/MediaBrowser.Server.Implementations/Notifications/NotificationManager.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Notifications; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Notifications; using System; @@ -31,11 +32,15 @@ namespace MediaBrowser.Server.Implementations.Notifications public Task SendNotification(NotificationRequest request, CancellationToken cancellationToken) { - var users = request.UserIds.Select(i => _userManager.GetUserById(new Guid(i))); - var notificationType = request.NotificationType; - var title = GetTitle(request); + var options = string.IsNullOrWhiteSpace(notificationType) ? + null : + _config.Configuration.NotificationOptions.GetOptions(notificationType); + + var users = GetUserIds(request, options).Select(i => _userManager.GetUserById(new Guid(i))); + + var title = GetTitle(request, options); var tasks = _services.Where(i => IsEnabled(i, notificationType)) .Select(i => SendNotification(request, i, users, title, cancellationToken)); @@ -58,6 +63,43 @@ namespace MediaBrowser.Server.Implementations.Notifications } + private IEnumerable<string> GetUserIds(NotificationRequest request, NotificationOption options) + { + if (request.SendToUserMode.HasValue) + { + switch (request.SendToUserMode.Value) + { + case SendToUserType.Admins: + return _userManager.Users.Where(i => i.Configuration.IsAdministrator) + .Select(i => i.Id.ToString("N")); + case SendToUserType.All: + return _userManager.Users.Select(i => i.Id.ToString("N")); + case SendToUserType.Custom: + return request.UserIds; + default: + throw new ArgumentException("Unrecognized SendToUserMode: " + request.SendToUserMode.Value); + } + } + + if (options != null) + { + switch (options.SendToUserMode) + { + case SendToUserType.Admins: + return _userManager.Users.Where(i => i.Configuration.IsAdministrator) + .Select(i => i.Id.ToString("N")); + case SendToUserType.All: + return _userManager.Users.Select(i => i.Id.ToString("N")); + case SendToUserType.Custom: + return options.SendToUsers; + default: + throw new ArgumentException("Unrecognized SendToUserMode: " + options.SendToUserMode); + } + } + + return new List<string>(); + } + private async Task SendNotification(NotificationRequest request, INotificationService service, string title, @@ -86,7 +128,7 @@ namespace MediaBrowser.Server.Implementations.Notifications } } - private string GetTitle(NotificationRequest request) + private string GetTitle(NotificationRequest request, NotificationOption options) { var title = request.Name; @@ -95,8 +137,6 @@ namespace MediaBrowser.Server.Implementations.Notifications { if (!string.IsNullOrEmpty(request.NotificationType)) { - var options = _config.Configuration.NotificationOptions.GetOptions(request.NotificationType); - if (options != null) { title = options.Title; |
