diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2020-08-25 16:59:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-25 16:59:35 -0400 |
| commit | cf6ef9958da4a50bd315d37792567ae51773a6a7 (patch) | |
| tree | 28423f47c93d5246009bc3dd952d90162fa64e0c /Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs | |
| parent | 25be1a9b20a09979146c382b0a5c2325bf3ba21f (diff) | |
| parent | b5bbbb9cefb7b360e12b44522d6494bfb4c0f848 (diff) | |
Merge pull request #3910 from barronpm/event-rewrite-1
Event Rewrite (Part 1)
Diffstat (limited to 'Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs new file mode 100644 index 0000000000..6a0f29b09f --- /dev/null +++ b/Jellyfin.Server.Implementations/Events/Consumers/Session/SessionStartedLogger.cs @@ -0,0 +1,54 @@ +using System.Globalization; +using System.Threading.Tasks; +using Jellyfin.Data.Entities; +using MediaBrowser.Controller.Events; +using MediaBrowser.Controller.Events.Session; +using MediaBrowser.Model.Activity; +using MediaBrowser.Model.Globalization; + +namespace Jellyfin.Server.Implementations.Events.Consumers.Session +{ + /// <summary> + /// Creates an entry in the activity log when a session is started. + /// </summary> + public class SessionStartedLogger : IEventConsumer<SessionStartedEventArgs> + { + private readonly ILocalizationManager _localizationManager; + private readonly IActivityManager _activityManager; + + /// <summary> + /// Initializes a new instance of the <see cref="SessionStartedLogger"/> class. + /// </summary> + /// <param name="localizationManager">The localization manager.</param> + /// <param name="activityManager">The activity manager.</param> + public SessionStartedLogger(ILocalizationManager localizationManager, IActivityManager activityManager) + { + _localizationManager = localizationManager; + _activityManager = activityManager; + } + + /// <inheritdoc /> + public async Task OnEvent(SessionStartedEventArgs eventArgs) + { + if (string.IsNullOrEmpty(eventArgs.Argument.UserName)) + { + return; + } + + await _activityManager.CreateAsync(new ActivityLog( + string.Format( + CultureInfo.InvariantCulture, + _localizationManager.GetLocalizedString("UserOnlineFromDevice"), + eventArgs.Argument.UserName, + eventArgs.Argument.DeviceName), + "SessionStarted", + eventArgs.Argument.UserId) + { + ShortOverview = string.Format( + CultureInfo.InvariantCulture, + _localizationManager.GetLocalizedString("LabelIpAddressValue"), + eventArgs.Argument.RemoteEndPoint) + }).ConfigureAwait(false); + } + } +} |
