Migrate ServerEventNotifier.OnUserUpdated to IEventConsumer

This commit is contained in:
Patrick Barron
2020-08-15 18:16:20 -04:00
parent ee5d4b1146
commit a0453a0fe6
5 changed files with 63 additions and 46 deletions

View File

@@ -11,7 +11,7 @@ using MediaBrowser.Model.Notifications;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Implementations.Events.Consumers
namespace Jellyfin.Server.Implementations.Events.Consumers.System
{
/// <summary>
/// Creates an activity log entry whenever a task is completed.

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Events.Users;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Session;
namespace Jellyfin.Server.Implementations.Events.Consumers.Users
{
/// <summary>
/// Notifies a user when their account has been updated.
/// </summary>
public class UserUpdatedNotifier : IEventConsumer<UserUpdatedEventArgs>
{
private readonly IUserManager _userManager;
private readonly ISessionManager _sessionManager;
/// <summary>
/// Initializes a new instance of the <see cref="UserUpdatedNotifier"/> class.
/// </summary>
/// <param name="userManager">The user manager.</param>
/// <param name="sessionManager">The session manager.</param>
public UserUpdatedNotifier(IUserManager userManager, ISessionManager sessionManager)
{
_userManager = userManager;
_sessionManager = sessionManager;
}
/// <inheritdoc />
public async Task OnEvent(UserUpdatedEventArgs e)
{
await _sessionManager.SendMessageToUserSessions(
new List<Guid> { e.Argument.Id },
"UserUpdated",
_userManager.GetUserDto(e.Argument),
CancellationToken.None).ConfigureAwait(false);
}
}
}

View File

@@ -1,9 +1,9 @@
using Jellyfin.Data.Events;
using Jellyfin.Data.Events.Users;
using Jellyfin.Server.Implementations.Events.Consumers;
using Jellyfin.Server.Implementations.Events.Consumers.Library;
using Jellyfin.Server.Implementations.Events.Consumers.Security;
using Jellyfin.Server.Implementations.Events.Consumers.Session;
using Jellyfin.Server.Implementations.Events.Consumers.System;
using Jellyfin.Server.Implementations.Events.Consumers.Updates;
using Jellyfin.Server.Implementations.Events.Consumers.Users;
using MediaBrowser.Common.Updates;
@@ -47,6 +47,8 @@ namespace Jellyfin.Server.Implementations.Events
collection.AddScoped<IEventConsumer<UserCreatedEventArgs>, UserCreatedLogger>();
collection.AddScoped<IEventConsumer<UserDeletedEventArgs>, UserDeletedLogger>();
collection.AddScoped<IEventConsumer<UserDeletedEventArgs>, UserDeletedNotifier>();
collection.AddScoped<IEventConsumer<UserUpdatedEventArgs>, UserUpdatedNotifier>();
collection.AddScoped<IEventConsumer<UserLockedOutEventArgs>, UserLockedOutLogger>();
collection.AddScoped<IEventConsumer<UserPasswordChangedEventArgs>, UserPasswordChangedLogger>();