aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/EntryPoints
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/EntryPoints')
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs172
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs32
-rw-r--r--MediaBrowser.Server.Implementations/EntryPoints/Notifications/WebSocketNotifier.cs4
3 files changed, 101 insertions, 107 deletions
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs
index fcb4406ab..2a3668dfa 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs
@@ -20,20 +20,20 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
/// </summary>
public class Notifications : IServerEntryPoint
{
- private readonly INotificationsRepository _notificationsRepo;
private readonly IInstallationManager _installationManager;
private readonly IUserManager _userManager;
private readonly ILogger _logger;
private readonly ITaskManager _taskManager;
+ private readonly INotificationManager _notificationManager;
- public Notifications(IInstallationManager installationManager, INotificationsRepository notificationsRepo, IUserManager userManager, ILogger logger, ITaskManager taskManager)
+ public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager)
{
_installationManager = installationManager;
- _notificationsRepo = notificationsRepo;
_userManager = userManager;
_logger = logger;
_taskManager = taskManager;
+ _notificationManager = notificationManager;
}
public void Run()
@@ -49,21 +49,25 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
async void _userManager_UserCreated(object sender, GenericEventArgs<User> e)
{
- var notification = new Notification
+ var userIds = _userManager
+ .Users
+ .Select(i => i.Id.ToString("N"))
+ .ToList();
+
+ var notification = new NotificationRequest
{
- UserId = e.Argument.Id,
- Category = "UserCreated",
+ UserIds = userIds,
Name = "Welcome to Media Browser!",
Description = "Check back here for more notifications."
};
try
{
- await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
+ await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
- _logger.ErrorException("Error adding notification", ex);
+ _logger.ErrorException("Error sending notification", ex);
}
}
@@ -73,29 +77,27 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
if (result.Status == TaskCompletionStatus.Failed)
{
- foreach (var user in _userManager
- .Users
- .Where(i => i.Configuration.IsAdministrator)
- .ToList())
+ var userIds = _userManager
+ .Users
+ .Where(i => i.Configuration.IsAdministrator)
+ .Select(i => i.Id.ToString("N"))
+ .ToList();
+
+ var notification = new NotificationRequest
+ {
+ UserIds = userIds,
+ Name = result.Name + " failed",
+ Description = result.ErrorMessage,
+ Level = NotificationLevel.Error
+ };
+
+ try
{
- var notification = new Notification
- {
- UserId = user.Id,
- Category = "ScheduledTaskFailed",
- Name = result.Name + " failed",
- RelatedId = result.Name,
- Description = result.ErrorMessage,
- Level = NotificationLevel.Error
- };
-
- try
- {
- await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error adding notification", ex);
- }
+ await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error sending notification", ex);
}
}
}
@@ -104,27 +106,25 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
{
var plugin = e.Argument;
- foreach (var user in _userManager
- .Users
- .Where(i => i.Configuration.IsAdministrator)
- .ToList())
+ var userIds = _userManager
+ .Users
+ .Where(i => i.Configuration.IsAdministrator)
+ .Select(i => i.Id.ToString("N"))
+ .ToList();
+
+ var notification = new NotificationRequest
{
- var notification = new Notification
- {
- UserId = user.Id,
- Category = "PluginUninstalled",
- Name = plugin.Name + " has been uninstalled",
- RelatedId = plugin.Id.ToString()
- };
+ UserIds = userIds,
+ Name = plugin.Name + " has been uninstalled"
+ };
- try
- {
- await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error adding notification", ex);
- }
+ try
+ {
+ await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error sending notification", ex);
}
}
@@ -132,28 +132,26 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
{
var installationInfo = e.InstallationInfo;
- foreach (var user in _userManager
- .Users
- .Where(i => i.Configuration.IsAdministrator)
- .ToList())
+ var userIds = _userManager
+ .Users
+ .Where(i => i.Configuration.IsAdministrator)
+ .Select(i => i.Id.ToString("N"))
+ .ToList();
+
+ var notification = new NotificationRequest
{
- var notification = new Notification
- {
- UserId = user.Id,
- Category = "PackageInstallationCompleted",
- Name = installationInfo.Name + " " + installationInfo.Version + " was installed",
- RelatedId = installationInfo.Name,
- Description = e.PackageVersionInfo.description
- };
+ UserIds = userIds,
+ Name = installationInfo.Name + " " + installationInfo.Version + " was installed",
+ Description = e.PackageVersionInfo.description
+ };
- try
- {
- await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error adding notification", ex);
- }
+ try
+ {
+ await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error sending notification", ex);
}
}
@@ -161,29 +159,27 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
{
var installationInfo = e.InstallationInfo;
- foreach (var user in _userManager
+ var userIds = _userManager
.Users
.Where(i => i.Configuration.IsAdministrator)
- .ToList())
+ .Select(i => i.Id.ToString("N"))
+ .ToList();
+
+ var notification = new NotificationRequest
{
- var notification = new Notification
- {
- UserId = user.Id,
- Category = "PackageInstallationFailed",
- Level = NotificationLevel.Error,
- Name = installationInfo.Name + " " + installationInfo.Version + " installation failed",
- RelatedId = installationInfo.Name,
- Description = e.Exception.Message
- };
+ UserIds = userIds,
+ Level = NotificationLevel.Error,
+ Name = installationInfo.Name + " " + installationInfo.Version + " installation failed",
+ Description = e.Exception.Message
+ };
- try
- {
- await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error adding notification", ex);
- }
+ try
+ {
+ await _notificationManager.SendNotification(notification, CancellationToken.None).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error sending notification", ex);
}
}
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs
index 723e4fdd3..d5b7f5b36 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/RemoteNotifications.cs
@@ -1,7 +1,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Controller.Plugins;
@@ -26,22 +25,23 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
private readonly IApplicationPaths _appPaths;
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
- private readonly INotificationsRepository _notificationsRepo;
private readonly IUserManager _userManager;
private readonly IFileSystem _fileSystem;
private readonly TimeSpan _frequency = TimeSpan.FromHours(6);
private readonly TimeSpan _maxAge = TimeSpan.FromDays(31);
- public RemoteNotifications(IApplicationPaths appPaths, ILogger logger, IHttpClient httpClient, IJsonSerializer json, INotificationsRepository notificationsRepo, IUserManager userManager, IFileSystem fileSystem)
+ private readonly INotificationManager _notificationManager;
+
+ public RemoteNotifications(IApplicationPaths appPaths, ILogger logger, IHttpClient httpClient, IJsonSerializer json, IUserManager userManager, IFileSystem fileSystem, INotificationManager notificationManager)
{
_appPaths = appPaths;
_logger = logger;
_httpClient = httpClient;
_json = json;
- _notificationsRepo = notificationsRepo;
_userManager = userManager;
_fileSystem = fileSystem;
+ _notificationManager = notificationManager;
}
/// <summary>
@@ -107,21 +107,19 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
.Where(i => string.Equals(i.active, "1") && i.date.ToUniversalTime() > lastRunTime && (DateTime.UtcNow - i.date.ToUniversalTime()) <= _maxAge)
.ToList();
- foreach (var user in _userManager.Users.ToList())
+ var userIds = _userManager.Users.Select(i => i.Id.ToString("N")).ToList();
+
+ foreach (var notification in notificationList)
{
- foreach (var notification in notificationList)
+ await _notificationManager.SendNotification(new NotificationRequest
{
- await _notificationsRepo.AddNotification(new Notification
- {
- Category = notification.category,
- Date = notification.date,
- Name = notification.name,
- Description = notification.description,
- Url = notification.url,
- UserId = user.Id
-
- }, CancellationToken.None).ConfigureAwait(false);
- }
+ Date = notification.date,
+ Name = notification.name,
+ Description = notification.description,
+ Url = notification.url,
+ UserIds = userIds
+
+ }, CancellationToken.None).ConfigureAwait(false);
}
}
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/WebSocketNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/WebSocketNotifier.cs
index c5a93720c..42aadf62e 100644
--- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/WebSocketNotifier.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/WebSocketNotifier.cs
@@ -30,9 +30,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
void _notificationsRepo_NotificationsMarkedRead(object sender, NotificationReadEventArgs e)
{
- var list = e.IdList.Select(i => i.ToString("N")).ToList();
+ var list = e.IdList.ToList();
- list.Add(e.UserId.ToString("N"));
+ list.Add(e.UserId);
list.Add(e.IsRead.ToString().ToLower());
var msg = string.Join("|", list.ToArray());