From 27a2ce9a42dc1eeaa4be95bb47ac34ed76a5bbd9 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 26 Oct 2024 12:16:58 -0600 Subject: [PATCH] 10.10 (#296) --- .../Helpers/DataObjectHelpers.cs | 51 +++++++++++++++++-- .../IItemDeletedManager.cs | 2 +- .../ItemDeletedNotifierEntryPoint.cs | 2 +- .../ItemDeletedScheduledTask.cs | 2 +- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Jellyfin.Plugin.Webhook/Helpers/DataObjectHelpers.cs b/Jellyfin.Plugin.Webhook/Helpers/DataObjectHelpers.cs index a935753..c420feb 100644 --- a/Jellyfin.Plugin.Webhook/Helpers/DataObjectHelpers.cs +++ b/Jellyfin.Plugin.Webhook/Helpers/DataObjectHelpers.cs @@ -326,15 +326,60 @@ public static class DataObjectHelpers /// The modified data object. public static Dictionary AddSessionInfoData(this Dictionary dataObject, SessionInfo sessionInfo) { - dataObject[nameof(sessionInfo.Id)] = sessionInfo.Id; + if (!string.IsNullOrEmpty(sessionInfo.Id)) + { + dataObject[nameof(sessionInfo.Id)] = sessionInfo.Id; + } + dataObject[nameof(sessionInfo.UserId)] = sessionInfo.UserId; dataObject["NotificationUsername"] = sessionInfo.UserName.Escape(); dataObject[nameof(sessionInfo.Client)] = sessionInfo.Client.Escape(); dataObject[nameof(sessionInfo.LastActivityDate)] = sessionInfo.LastActivityDate; dataObject[nameof(sessionInfo.LastPlaybackCheckIn)] = sessionInfo.LastPlaybackCheckIn; dataObject[nameof(sessionInfo.DeviceName)] = sessionInfo.DeviceName.Escape(); - dataObject[nameof(sessionInfo.DeviceId)] = sessionInfo.DeviceId; - dataObject[nameof(sessionInfo.RemoteEndPoint)] = sessionInfo.RemoteEndPoint; + + if (!string.IsNullOrEmpty(sessionInfo.DeviceId)) + { + dataObject[nameof(sessionInfo.DeviceId)] = sessionInfo.DeviceId; + } + + if (!string.IsNullOrEmpty(sessionInfo.RemoteEndPoint)) + { + dataObject[nameof(sessionInfo.RemoteEndPoint)] = sessionInfo.RemoteEndPoint; + } + + return dataObject; + } + + /// + /// Add session info data. + /// + /// The data object. + /// The session info to add. + /// The modified data object. + public static Dictionary AddSessionInfoData(this Dictionary dataObject, SessionInfoDto sessionInfo) + { + if (!string.IsNullOrEmpty(sessionInfo.Id)) + { + dataObject[nameof(sessionInfo.Id)] = sessionInfo.Id; + } + + dataObject[nameof(sessionInfo.UserId)] = sessionInfo.UserId; + dataObject["NotificationUsername"] = sessionInfo.UserName.Escape(); + dataObject[nameof(sessionInfo.Client)] = sessionInfo.Client.Escape(); + dataObject[nameof(sessionInfo.LastActivityDate)] = sessionInfo.LastActivityDate; + dataObject[nameof(sessionInfo.LastPlaybackCheckIn)] = sessionInfo.LastPlaybackCheckIn; + dataObject[nameof(sessionInfo.DeviceName)] = sessionInfo.DeviceName.Escape(); + + if (!string.IsNullOrEmpty(sessionInfo.DeviceId)) + { + dataObject[nameof(sessionInfo.DeviceId)] = sessionInfo.DeviceId; + } + + if (!string.IsNullOrEmpty(sessionInfo.RemoteEndPoint)) + { + dataObject[nameof(sessionInfo.RemoteEndPoint)] = sessionInfo.RemoteEndPoint; + } return dataObject; } diff --git a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/IItemDeletedManager.cs b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/IItemDeletedManager.cs index b80e569..82ba0f4 100644 --- a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/IItemDeletedManager.cs +++ b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/IItemDeletedManager.cs @@ -19,4 +19,4 @@ public interface IItemDeletedManager /// /// The deleted item. public void AddItem(BaseItem item); -} \ No newline at end of file +} diff --git a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedNotifierEntryPoint.cs b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedNotifierEntryPoint.cs index f68245b..78f443f 100644 --- a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedNotifierEntryPoint.cs +++ b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedNotifierEntryPoint.cs @@ -50,4 +50,4 @@ public class ItemDeletedNotifierEntryPoint : IHostedService _libraryManager.ItemRemoved -= ItemDeletedHandler; return Task.CompletedTask; } -} \ No newline at end of file +} diff --git a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedScheduledTask.cs b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedScheduledTask.cs index 4e88336..633b1c2 100644 --- a/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedScheduledTask.cs +++ b/Jellyfin.Plugin.Webhook/Notifiers/ItemDeletedNotifier/ItemDeletedScheduledTask.cs @@ -68,4 +68,4 @@ public class ItemDeletedScheduledTask : IScheduledTask, IConfigurableScheduledTa } }; } -} \ No newline at end of file +}