Remove Emby.Notifications (#9147)
This commit is contained in:
parent
abffd160c3
commit
fec23de427
|
@ -1,123 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using MediaBrowser.Controller.Notifications;
|
|
||||||
using MediaBrowser.Model.Globalization;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace Emby.Notifications
|
|
||||||
{
|
|
||||||
public class CoreNotificationTypes : INotificationTypeFactory
|
|
||||||
{
|
|
||||||
private readonly ILocalizationManager _localization;
|
|
||||||
|
|
||||||
public CoreNotificationTypes(ILocalizationManager localization)
|
|
||||||
{
|
|
||||||
_localization = localization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
|
|
||||||
{
|
|
||||||
var knownTypes = new NotificationTypeInfo[]
|
|
||||||
{
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.ApplicationUpdateInstalled)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.InstallationFailed)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.PluginInstalled)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.PluginError)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.PluginUninstalled)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.PluginUpdateInstalled)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.ServerRestartRequired)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.TaskFailed)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.NewLibraryContent)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.AudioPlayback)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.VideoPlayback)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.AudioPlaybackStopped)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.VideoPlaybackStopped)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.UserLockedOut)
|
|
||||||
},
|
|
||||||
new NotificationTypeInfo
|
|
||||||
{
|
|
||||||
Type = nameof(NotificationType.ApplicationUpdateAvailable)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var type in knownTypes)
|
|
||||||
{
|
|
||||||
Update(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
var systemName = _localization.GetLocalizedString("System");
|
|
||||||
|
|
||||||
return knownTypes.OrderByDescending(i => string.Equals(i.Category, systemName, StringComparison.OrdinalIgnoreCase))
|
|
||||||
.ThenBy(i => i.Category)
|
|
||||||
.ThenBy(i => i.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update(NotificationTypeInfo note)
|
|
||||||
{
|
|
||||||
note.Name = _localization.GetLocalizedString("NotificationOption" + note.Type);
|
|
||||||
|
|
||||||
note.IsBasedOnUserEvent = note.Type.IndexOf("Playback", StringComparison.OrdinalIgnoreCase) != -1;
|
|
||||||
|
|
||||||
if (note.Type.IndexOf("Playback", StringComparison.OrdinalIgnoreCase) != -1)
|
|
||||||
{
|
|
||||||
note.Category = _localization.GetLocalizedString("User");
|
|
||||||
}
|
|
||||||
else if (note.Type.IndexOf("Plugin", StringComparison.OrdinalIgnoreCase) != -1)
|
|
||||||
{
|
|
||||||
note.Category = _localization.GetLocalizedString("Plugin");
|
|
||||||
}
|
|
||||||
else if (note.Type.IndexOf("UserLockedOut", StringComparison.OrdinalIgnoreCase) != -1)
|
|
||||||
{
|
|
||||||
note.Category = _localization.GetLocalizedString("User");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
note.Category = _localization.GetLocalizedString("System");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
|
|
||||||
<PropertyGroup>
|
|
||||||
<ProjectGuid>{2E030C33-6923-4530-9E54-FA29FA6AD1A9}</ProjectGuid>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="..\SharedVersion.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
|
||||||
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
|
|
||||||
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<!-- Code analyzers-->
|
|
||||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
|
@ -1,23 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using MediaBrowser.Common.Configuration;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace Emby.Notifications
|
|
||||||
{
|
|
||||||
public class NotificationConfigurationFactory : IConfigurationFactory
|
|
||||||
{
|
|
||||||
public IEnumerable<ConfigurationStore> GetConfigurations()
|
|
||||||
{
|
|
||||||
return new ConfigurationStore[]
|
|
||||||
{
|
|
||||||
new ConfigurationStore
|
|
||||||
{
|
|
||||||
Key = "notifications",
|
|
||||||
ConfigurationType = typeof(NotificationOptions)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,314 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Jellyfin.Data.Events;
|
|
||||||
using Jellyfin.Extensions;
|
|
||||||
using MediaBrowser.Common.Configuration;
|
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
|
||||||
using MediaBrowser.Controller.Library;
|
|
||||||
using MediaBrowser.Controller.Notifications;
|
|
||||||
using MediaBrowser.Controller.Plugins;
|
|
||||||
using MediaBrowser.Model.Activity;
|
|
||||||
using MediaBrowser.Model.Globalization;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Emby.Notifications
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates notifications for various system events.
|
|
||||||
/// </summary>
|
|
||||||
public class NotificationEntryPoint : IServerEntryPoint
|
|
||||||
{
|
|
||||||
private readonly ILogger<NotificationEntryPoint> _logger;
|
|
||||||
private readonly IActivityManager _activityManager;
|
|
||||||
private readonly ILocalizationManager _localization;
|
|
||||||
private readonly INotificationManager _notificationManager;
|
|
||||||
private readonly ILibraryManager _libraryManager;
|
|
||||||
private readonly IServerApplicationHost _appHost;
|
|
||||||
private readonly IConfigurationManager _config;
|
|
||||||
|
|
||||||
private readonly object _libraryChangedSyncLock = new object();
|
|
||||||
private readonly List<BaseItem> _itemsAdded = new List<BaseItem>();
|
|
||||||
|
|
||||||
private Timer? _libraryUpdateTimer;
|
|
||||||
|
|
||||||
private string[] _coreNotificationTypes;
|
|
||||||
|
|
||||||
private bool _disposed = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="NotificationEntryPoint" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="logger">The logger.</param>
|
|
||||||
/// <param name="activityManager">The activity manager.</param>
|
|
||||||
/// <param name="localization">The localization manager.</param>
|
|
||||||
/// <param name="notificationManager">The notification manager.</param>
|
|
||||||
/// <param name="libraryManager">The library manager.</param>
|
|
||||||
/// <param name="appHost">The application host.</param>
|
|
||||||
/// <param name="config">The configuration manager.</param>
|
|
||||||
public NotificationEntryPoint(
|
|
||||||
ILogger<NotificationEntryPoint> logger,
|
|
||||||
IActivityManager activityManager,
|
|
||||||
ILocalizationManager localization,
|
|
||||||
INotificationManager notificationManager,
|
|
||||||
ILibraryManager libraryManager,
|
|
||||||
IServerApplicationHost appHost,
|
|
||||||
IConfigurationManager config)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
_activityManager = activityManager;
|
|
||||||
_localization = localization;
|
|
||||||
_notificationManager = notificationManager;
|
|
||||||
_libraryManager = libraryManager;
|
|
||||||
_appHost = appHost;
|
|
||||||
_config = config;
|
|
||||||
|
|
||||||
_coreNotificationTypes = new CoreNotificationTypes(localization).GetNotificationTypes().Select(i => i.Type).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task RunAsync()
|
|
||||||
{
|
|
||||||
_libraryManager.ItemAdded += OnLibraryManagerItemAdded;
|
|
||||||
_appHost.HasPendingRestartChanged += OnAppHostHasPendingRestartChanged;
|
|
||||||
_activityManager.EntryCreated += OnActivityManagerEntryCreated;
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnAppHostHasPendingRestartChanged(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var type = NotificationType.ServerRestartRequired.ToString();
|
|
||||||
|
|
||||||
var notification = new NotificationRequest
|
|
||||||
{
|
|
||||||
NotificationType = type,
|
|
||||||
Name = string.Format(
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
_localization.GetLocalizedString("ServerNameNeedsToBeRestarted"),
|
|
||||||
_appHost.Name)
|
|
||||||
};
|
|
||||||
|
|
||||||
await SendNotification(notification, null).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnActivityManagerEntryCreated(object? sender, GenericEventArgs<ActivityLogEntry> e)
|
|
||||||
{
|
|
||||||
var entry = e.Argument;
|
|
||||||
|
|
||||||
var type = entry.Type;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(type) || !_coreNotificationTypes.Contains(type, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var userId = e.Argument.UserId;
|
|
||||||
|
|
||||||
if (!userId.Equals(default) && !GetOptions().IsEnabledToMonitorUser(type, userId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var notification = new NotificationRequest
|
|
||||||
{
|
|
||||||
NotificationType = type,
|
|
||||||
Name = entry.Name,
|
|
||||||
Description = entry.Overview
|
|
||||||
};
|
|
||||||
|
|
||||||
await SendNotification(notification, null).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NotificationOptions GetOptions()
|
|
||||||
{
|
|
||||||
return _config.GetConfiguration<NotificationOptions>("notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnLibraryManagerItemAdded(object? sender, ItemChangeEventArgs e)
|
|
||||||
{
|
|
||||||
if (!FilterItem(e.Item))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_libraryChangedSyncLock)
|
|
||||||
{
|
|
||||||
if (_libraryUpdateTimer is null)
|
|
||||||
{
|
|
||||||
_libraryUpdateTimer = new Timer(
|
|
||||||
LibraryUpdateTimerCallback,
|
|
||||||
null,
|
|
||||||
5000,
|
|
||||||
Timeout.Infinite);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_libraryUpdateTimer.Change(5000, Timeout.Infinite);
|
|
||||||
}
|
|
||||||
|
|
||||||
_itemsAdded.Add(e.Item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool FilterItem(BaseItem item)
|
|
||||||
{
|
|
||||||
if (item.IsFolder)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!item.HasPathProtocol)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is IItemByName)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item.SourceType == SourceType.Library;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void LibraryUpdateTimerCallback(object? state)
|
|
||||||
{
|
|
||||||
List<BaseItem> items;
|
|
||||||
|
|
||||||
lock (_libraryChangedSyncLock)
|
|
||||||
{
|
|
||||||
items = _itemsAdded.ToList();
|
|
||||||
_itemsAdded.Clear();
|
|
||||||
_libraryUpdateTimer!.Dispose(); // Shouldn't be null as it just set off this callback
|
|
||||||
_libraryUpdateTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items.Count > 10)
|
|
||||||
{
|
|
||||||
items = items.GetRange(0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
var notification = new NotificationRequest
|
|
||||||
{
|
|
||||||
NotificationType = NotificationType.NewLibraryContent.ToString(),
|
|
||||||
Name = string.Format(
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
_localization.GetLocalizedString("ValueHasBeenAddedToLibrary"),
|
|
||||||
GetItemName(item)),
|
|
||||||
Description = item.Overview
|
|
||||||
};
|
|
||||||
|
|
||||||
await SendNotification(notification, item).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a human readable name for the item.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item">The item.</param>
|
|
||||||
/// <returns>A human readable name for the item.</returns>
|
|
||||||
public static string GetItemName(BaseItem item)
|
|
||||||
{
|
|
||||||
var name = item.Name;
|
|
||||||
if (item is Episode episode)
|
|
||||||
{
|
|
||||||
if (episode.IndexNumber.HasValue)
|
|
||||||
{
|
|
||||||
name = string.Format(
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
"Ep{0} - {1}",
|
|
||||||
episode.IndexNumber.Value,
|
|
||||||
name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (episode.ParentIndexNumber.HasValue)
|
|
||||||
{
|
|
||||||
name = string.Format(
|
|
||||||
CultureInfo.InvariantCulture,
|
|
||||||
"S{0}, {1}",
|
|
||||||
episode.ParentIndexNumber.Value,
|
|
||||||
name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is IHasSeries hasSeries)
|
|
||||||
{
|
|
||||||
name = hasSeries.SeriesName + " - " + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item is IHasAlbumArtist hasAlbumArtist)
|
|
||||||
{
|
|
||||||
var artists = hasAlbumArtist.AlbumArtists;
|
|
||||||
|
|
||||||
if (artists.Count > 0)
|
|
||||||
{
|
|
||||||
name = artists[0] + " - " + name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (item is IHasArtist hasArtist)
|
|
||||||
{
|
|
||||||
var artists = hasArtist.Artists;
|
|
||||||
|
|
||||||
if (artists.Count > 0)
|
|
||||||
{
|
|
||||||
name = artists[0] + " - " + name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task SendNotification(NotificationRequest notification, BaseItem? relatedItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _notificationManager.SendNotification(notification, relatedItem, CancellationToken.None).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error sending notification");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Releases unmanaged and optionally managed resources.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (_disposed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
_libraryUpdateTimer?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
_libraryUpdateTimer = null;
|
|
||||||
|
|
||||||
_libraryManager.ItemAdded -= OnLibraryManagerItemAdded;
|
|
||||||
_appHost.HasPendingRestartChanged -= OnAppHostHasPendingRestartChanged;
|
|
||||||
_activityManager.EntryCreated -= OnActivityManagerEntryCreated;
|
|
||||||
|
|
||||||
_disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,224 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Jellyfin.Data.Entities;
|
|
||||||
using Jellyfin.Data.Enums;
|
|
||||||
using MediaBrowser.Common.Configuration;
|
|
||||||
using MediaBrowser.Common.Extensions;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using MediaBrowser.Controller.Library;
|
|
||||||
using MediaBrowser.Controller.Notifications;
|
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Emby.Notifications
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// NotificationManager class.
|
|
||||||
/// </summary>
|
|
||||||
public class NotificationManager : INotificationManager
|
|
||||||
{
|
|
||||||
private readonly ILogger<NotificationManager> _logger;
|
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
private readonly IServerConfigurationManager _config;
|
|
||||||
|
|
||||||
private INotificationService[] _services = Array.Empty<INotificationService>();
|
|
||||||
private INotificationTypeFactory[] _typeFactories = Array.Empty<INotificationTypeFactory>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="NotificationManager" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="logger">The logger.</param>
|
|
||||||
/// <param name="userManager">The user manager.</param>
|
|
||||||
/// <param name="config">The server configuration manager.</param>
|
|
||||||
public NotificationManager(
|
|
||||||
ILogger<NotificationManager> logger,
|
|
||||||
IUserManager userManager,
|
|
||||||
IServerConfigurationManager config)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
_userManager = userManager;
|
|
||||||
_config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NotificationOptions GetConfiguration()
|
|
||||||
{
|
|
||||||
return _config.GetConfiguration<NotificationOptions>("notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task SendNotification(NotificationRequest request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return SendNotification(request, null, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task SendNotification(NotificationRequest request, BaseItem? relatedItem, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var notificationType = request.NotificationType;
|
|
||||||
|
|
||||||
var options = string.IsNullOrEmpty(notificationType) ?
|
|
||||||
null :
|
|
||||||
GetConfiguration().GetOptions(notificationType);
|
|
||||||
|
|
||||||
var users = GetUserIds(request, options)
|
|
||||||
.Select(i => _userManager.GetUserById(i))
|
|
||||||
.Where(i => relatedItem is null || relatedItem.IsVisibleStandalone(i))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
var title = request.Name;
|
|
||||||
var description = request.Description;
|
|
||||||
|
|
||||||
var tasks = _services.Where(i => IsEnabled(i, notificationType))
|
|
||||||
.Select(i => SendNotification(request, i, users, title, description, cancellationToken));
|
|
||||||
|
|
||||||
return Task.WhenAll(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task SendNotification(
|
|
||||||
NotificationRequest request,
|
|
||||||
INotificationService service,
|
|
||||||
IEnumerable<User> users,
|
|
||||||
string title,
|
|
||||||
string description,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
users = users.Where(i => IsEnabledForUser(service, i));
|
|
||||||
|
|
||||||
var tasks = users.Select(i => SendNotification(request, service, title, description, i, cancellationToken));
|
|
||||||
|
|
||||||
return Task.WhenAll(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<Guid> GetUserIds(NotificationRequest request, NotificationOption? options)
|
|
||||||
{
|
|
||||||
if (request.SendToUserMode.HasValue)
|
|
||||||
{
|
|
||||||
switch (request.SendToUserMode.Value)
|
|
||||||
{
|
|
||||||
case SendToUserType.Admins:
|
|
||||||
return _userManager.Users.Where(i => i.HasPermission(PermissionKind.IsAdministrator))
|
|
||||||
.Select(i => i.Id);
|
|
||||||
case SendToUserType.All:
|
|
||||||
return _userManager.UsersIds;
|
|
||||||
case SendToUserType.Custom:
|
|
||||||
return request.UserIds;
|
|
||||||
default:
|
|
||||||
throw new ArgumentException("Unrecognized SendToUserMode: " + request.SendToUserMode.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options is not null && !string.IsNullOrEmpty(request.NotificationType))
|
|
||||||
{
|
|
||||||
var config = GetConfiguration();
|
|
||||||
|
|
||||||
return _userManager.Users
|
|
||||||
.Where(i => config.IsEnabledToSendToUser(request.NotificationType, i.Id.ToString("N", CultureInfo.InvariantCulture), i))
|
|
||||||
.Select(i => i.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return request.UserIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task SendNotification(
|
|
||||||
NotificationRequest request,
|
|
||||||
INotificationService service,
|
|
||||||
string title,
|
|
||||||
string description,
|
|
||||||
User user,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var notification = new UserNotification
|
|
||||||
{
|
|
||||||
Date = request.Date,
|
|
||||||
Description = description,
|
|
||||||
Level = request.Level,
|
|
||||||
Name = title,
|
|
||||||
Url = request.Url,
|
|
||||||
User = user
|
|
||||||
};
|
|
||||||
|
|
||||||
_logger.LogDebug("Sending notification via {0} to user {1}", service.Name, user.Username);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await service.SendNotification(notification, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error sending notification to {0}", service.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsEnabledForUser(INotificationService service, User user)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return service.IsEnabledForUser(user);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error in IsEnabledForUser");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsEnabled(INotificationService service, string notificationType)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(notificationType))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetConfiguration().IsServiceEnabled(service.Name, notificationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void AddParts(IEnumerable<INotificationService> services, IEnumerable<INotificationTypeFactory> notificationTypeFactories)
|
|
||||||
{
|
|
||||||
_services = services.ToArray();
|
|
||||||
_typeFactories = notificationTypeFactories.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public List<NotificationTypeInfo> GetNotificationTypes()
|
|
||||||
{
|
|
||||||
var list = _typeFactories.Select(i =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return i.GetNotificationTypes().ToList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error in GetNotificationTypes");
|
|
||||||
return new List<NotificationTypeInfo>();
|
|
||||||
}
|
|
||||||
}).SelectMany(i => i).ToList();
|
|
||||||
|
|
||||||
var config = GetConfiguration();
|
|
||||||
|
|
||||||
foreach (var i in list)
|
|
||||||
{
|
|
||||||
i.Enabled = config.IsEnabled(i.Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IEnumerable<NameIdPair> GetNotificationServices()
|
|
||||||
{
|
|
||||||
return _services.Select(i => new NameIdPair
|
|
||||||
{
|
|
||||||
Name = i.Name,
|
|
||||||
Id = i.Name.GetMD5().ToString("N", CultureInfo.InvariantCulture)
|
|
||||||
}).OrderBy(i => i.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
using System.Reflection;
|
|
||||||
using System.Resources;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("Emby.Notifications")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("Jellyfin Project")]
|
|
||||||
[assembly: AssemblyProduct("Jellyfin Server")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
[assembly: NeutralResourcesLanguage("en")]
|
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
|
||||||
// to COM components. If you need to access a type in this assembly from
|
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
|
||||||
[assembly: ComVisible(false)]
|
|
|
@ -19,7 +19,6 @@ using Emby.Dlna;
|
||||||
using Emby.Dlna.Main;
|
using Emby.Dlna.Main;
|
||||||
using Emby.Dlna.Ssdp;
|
using Emby.Dlna.Ssdp;
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using Emby.Notifications;
|
|
||||||
using Emby.Photos;
|
using Emby.Photos;
|
||||||
using Emby.Server.Implementations.Channels;
|
using Emby.Server.Implementations.Channels;
|
||||||
using Emby.Server.Implementations.Collections;
|
using Emby.Server.Implementations.Collections;
|
||||||
|
@ -70,7 +69,6 @@ using MediaBrowser.Controller.LiveTv;
|
||||||
using MediaBrowser.Controller.Lyrics;
|
using MediaBrowser.Controller.Lyrics;
|
||||||
using MediaBrowser.Controller.MediaEncoding;
|
using MediaBrowser.Controller.MediaEncoding;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
using MediaBrowser.Controller.Notifications;
|
|
||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using MediaBrowser.Controller.Playlists;
|
using MediaBrowser.Controller.Playlists;
|
||||||
using MediaBrowser.Controller.Plugins;
|
using MediaBrowser.Controller.Plugins;
|
||||||
|
@ -615,8 +613,6 @@ namespace Emby.Server.Implementations
|
||||||
|
|
||||||
serviceCollection.AddSingleton<IUserViewManager, UserViewManager>();
|
serviceCollection.AddSingleton<IUserViewManager, UserViewManager>();
|
||||||
|
|
||||||
serviceCollection.AddSingleton<INotificationManager, NotificationManager>();
|
|
||||||
|
|
||||||
serviceCollection.AddSingleton<IDeviceDiscovery, DeviceDiscovery>();
|
serviceCollection.AddSingleton<IDeviceDiscovery, DeviceDiscovery>();
|
||||||
|
|
||||||
serviceCollection.AddSingleton<IChapterManager, ChapterManager>();
|
serviceCollection.AddSingleton<IChapterManager, ChapterManager>();
|
||||||
|
@ -791,8 +787,6 @@ namespace Emby.Server.Implementations
|
||||||
Resolve<IChannelManager>().AddParts(GetExports<IChannel>());
|
Resolve<IChannelManager>().AddParts(GetExports<IChannel>());
|
||||||
|
|
||||||
Resolve<IMediaSourceManager>().AddParts(GetExports<IMediaSourceProvider>());
|
Resolve<IMediaSourceManager>().AddParts(GetExports<IMediaSourceProvider>());
|
||||||
|
|
||||||
Resolve<INotificationManager>().AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -991,9 +985,6 @@ namespace Emby.Server.Implementations
|
||||||
// Local metadata
|
// Local metadata
|
||||||
yield return typeof(BoxSetXmlSaver).Assembly;
|
yield return typeof(BoxSetXmlSaver).Assembly;
|
||||||
|
|
||||||
// Notifications
|
|
||||||
yield return typeof(NotificationManager).Assembly;
|
|
||||||
|
|
||||||
// Xbmc
|
// Xbmc
|
||||||
yield return typeof(ArtistNfoProvider).Assembly;
|
yield return typeof(ArtistNfoProvider).Assembly;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
|
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
|
||||||
<ProjectReference Include="..\Emby.Notifications\Emby.Notifications.csproj" />
|
|
||||||
<ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
|
<ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
|
||||||
<ProjectReference Include="..\Jellyfin.Server.Implementations\Jellyfin.Server.Implementations.csproj" />
|
<ProjectReference Include="..\Jellyfin.Server.Implementations\Jellyfin.Server.Implementations.csproj" />
|
||||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using Jellyfin.Api.Constants;
|
|
||||||
using MediaBrowser.Controller.Notifications;
|
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace Jellyfin.Api.Controllers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The notification controller.
|
|
||||||
/// </summary>
|
|
||||||
[Authorize(Policy = Policies.DefaultAuthorization)]
|
|
||||||
public class NotificationsController : BaseJellyfinApiController
|
|
||||||
{
|
|
||||||
private readonly INotificationManager _notificationManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="NotificationsController" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="notificationManager">The notification manager.</param>
|
|
||||||
public NotificationsController(INotificationManager notificationManager)
|
|
||||||
{
|
|
||||||
_notificationManager = notificationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets notification types.
|
|
||||||
/// </summary>
|
|
||||||
/// <response code="200">All notification types returned.</response>
|
|
||||||
/// <returns>An <cref see="OkResult"/> containing a list of all notification types.</returns>
|
|
||||||
[HttpGet("Types")]
|
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
||||||
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
|
|
||||||
{
|
|
||||||
return _notificationManager.GetNotificationTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets notification services.
|
|
||||||
/// </summary>
|
|
||||||
/// <response code="200">All notification services returned.</response>
|
|
||||||
/// <returns>An <cref see="OkResult"/> containing a list of all notification services.</returns>
|
|
||||||
[HttpGet("Services")]
|
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
||||||
public IEnumerable<NameIdPair> GetNotificationServices()
|
|
||||||
{
|
|
||||||
return _notificationManager.GetNotificationServices();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,8 +27,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RSSDP", "RSSDP\RSSDP.csproj
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Dlna", "Emby.Dlna\Emby.Dlna.csproj", "{805844AB-E92F-45E6-9D99-4F6D48D129A5}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Dlna", "Emby.Dlna\Emby.Dlna.csproj", "{805844AB-E92F-45E6-9D99-4F6D48D129A5}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Notifications", "Emby.Notifications\Emby.Notifications.csproj", "{2E030C33-6923-4530-9E54-FA29FA6AD1A9}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Naming", "Emby.Naming\Emby.Naming.csproj", "{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Naming", "Emby.Naming\Emby.Naming.csproj", "{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.MediaEncoding", "MediaBrowser.MediaEncoding\MediaBrowser.MediaEncoding.csproj", "{960295EE-4AF4-4440-A525-B4C295B01A61}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.MediaEncoding", "MediaBrowser.MediaEncoding\MediaBrowser.MediaEncoding.csproj", "{960295EE-4AF4-4440-A525-B4C295B01A61}"
|
||||||
|
@ -149,10 +147,6 @@ Global
|
||||||
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{805844AB-E92F-45E6-9D99-4F6D48D129A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Notifications
|
|
||||||
{
|
|
||||||
public interface INotificationManager
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Sends the notification.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>Task.</returns>
|
|
||||||
Task SendNotification(NotificationRequest request, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
Task SendNotification(NotificationRequest request, BaseItem? relatedItem, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the parts.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services">The services.</param>
|
|
||||||
/// <param name="notificationTypeFactories">The notification type factories.</param>
|
|
||||||
void AddParts(IEnumerable<INotificationService> services, IEnumerable<INotificationTypeFactory> notificationTypeFactories);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the notification types.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>IEnumerable{NotificationTypeInfo}.</returns>
|
|
||||||
List<NotificationTypeInfo> GetNotificationTypes();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the notification services.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>IEnumerable{NotificationServiceInfo}.</returns>
|
|
||||||
IEnumerable<NameIdPair> GetNotificationServices();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Jellyfin.Data.Entities;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Notifications
|
|
||||||
{
|
|
||||||
public interface INotificationService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The name.</value>
|
|
||||||
string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sends the notification.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>Task.</returns>
|
|
||||||
Task SendNotification(UserNotification request, CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether [is enabled for user] [the specified user identifier].
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">The user.</param>
|
|
||||||
/// <returns><c>true</c> if [is enabled for user] [the specified user identifier]; otherwise, <c>false</c>.</returns>
|
|
||||||
bool IsEnabledForUser(User user);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Notifications
|
|
||||||
{
|
|
||||||
public interface INotificationTypeFactory
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the notification types.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>IEnumerable{NotificationTypeInfo}.</returns>
|
|
||||||
IEnumerable<NotificationTypeInfo> GetNotificationTypes();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Jellyfin.Data.Entities;
|
|
||||||
using MediaBrowser.Model.Notifications;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Notifications
|
|
||||||
{
|
|
||||||
public class UserNotification
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
public string Url { get; set; }
|
|
||||||
|
|
||||||
public NotificationLevel Level { get; set; }
|
|
||||||
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
public User User { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public enum NotificationLevel
|
|
||||||
{
|
|
||||||
Normal = 0,
|
|
||||||
Warning = 1,
|
|
||||||
Error = 2
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
#pragma warning disable CA1819 // Properties should not return arrays
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public class NotificationOption
|
|
||||||
{
|
|
||||||
public NotificationOption(string type)
|
|
||||||
{
|
|
||||||
Type = type;
|
|
||||||
DisabledServices = Array.Empty<string>();
|
|
||||||
DisabledMonitorUsers = Array.Empty<string>();
|
|
||||||
SendToUsers = Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NotificationOption()
|
|
||||||
{
|
|
||||||
DisabledServices = Array.Empty<string>();
|
|
||||||
DisabledMonitorUsers = Array.Empty<string>();
|
|
||||||
SendToUsers = Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? Type { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets user Ids to not monitor (it's opt out).
|
|
||||||
/// </summary>
|
|
||||||
public string[] DisabledMonitorUsers { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets user Ids to send to (if SendToUserMode == Custom).
|
|
||||||
/// </summary>
|
|
||||||
public string[] SendToUsers { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a value indicating whether this <see cref="NotificationOption"/> is enabled.
|
|
||||||
/// </summary>
|
|
||||||
/// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
|
|
||||||
public bool Enabled { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the disabled services.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The disabled services.</value>
|
|
||||||
public string[] DisabledServices { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the send to user mode.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The send to user mode.</value>
|
|
||||||
public SendToUserType SendToUserMode { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
#nullable disable
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Jellyfin.Data.Entities;
|
|
||||||
using Jellyfin.Data.Enums;
|
|
||||||
using Jellyfin.Extensions;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public class NotificationOptions
|
|
||||||
{
|
|
||||||
public NotificationOptions()
|
|
||||||
{
|
|
||||||
Options = new[]
|
|
||||||
{
|
|
||||||
new NotificationOption(NotificationType.TaskFailed.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.ServerRestartRequired.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.ApplicationUpdateAvailable.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.ApplicationUpdateInstalled.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.PluginUpdateInstalled.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.PluginUninstalled.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.InstallationFailed.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.PluginInstalled.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.PluginError.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
},
|
|
||||||
new NotificationOption(NotificationType.UserLockedOut.ToString())
|
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
SendToUserMode = SendToUserType.Admins
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public NotificationOption[] Options { get; set; }
|
|
||||||
|
|
||||||
public NotificationOption GetOptions(string type)
|
|
||||||
{
|
|
||||||
foreach (NotificationOption i in Options)
|
|
||||||
{
|
|
||||||
if (string.Equals(type, i.Type, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabled(string type)
|
|
||||||
{
|
|
||||||
NotificationOption opt = GetOptions(type);
|
|
||||||
|
|
||||||
return opt is not null && opt.Enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsServiceEnabled(string service, string notificationType)
|
|
||||||
{
|
|
||||||
NotificationOption opt = GetOptions(notificationType);
|
|
||||||
|
|
||||||
return opt is null
|
|
||||||
|| !opt.DisabledServices.Contains(service, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabledToMonitorUser(string type, Guid userId)
|
|
||||||
{
|
|
||||||
NotificationOption opt = GetOptions(type);
|
|
||||||
|
|
||||||
return opt is not null
|
|
||||||
&& opt.Enabled
|
|
||||||
&& !opt.DisabledMonitorUsers.Contains(userId.ToString("N"), StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabledToSendToUser(string type, string userId, User user)
|
|
||||||
{
|
|
||||||
NotificationOption opt = GetOptions(type);
|
|
||||||
|
|
||||||
if (opt is not null && opt.Enabled)
|
|
||||||
{
|
|
||||||
if (opt.SendToUserMode == SendToUserType.All)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opt.SendToUserMode == SendToUserType.Admins && user.HasPermission(PermissionKind.IsAdministrator))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return opt.SendToUsers.Contains(userId, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
#nullable disable
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public class NotificationRequest
|
|
||||||
{
|
|
||||||
public NotificationRequest()
|
|
||||||
{
|
|
||||||
UserIds = Array.Empty<Guid>();
|
|
||||||
Date = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
public string Url { get; set; }
|
|
||||||
|
|
||||||
public NotificationLevel Level { get; set; }
|
|
||||||
|
|
||||||
public Guid[] UserIds { get; set; }
|
|
||||||
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the corresponding type name used in configuration. Not for display.
|
|
||||||
/// </summary>
|
|
||||||
public string NotificationType { get; set; }
|
|
||||||
|
|
||||||
public SendToUserType? SendToUserMode { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
#nullable disable
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public class NotificationTypeInfo
|
|
||||||
{
|
|
||||||
public string Type { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public bool Enabled { get; set; }
|
|
||||||
|
|
||||||
public string Category { get; set; }
|
|
||||||
|
|
||||||
public bool IsBasedOnUserEvent { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Notifications
|
|
||||||
{
|
|
||||||
public enum SendToUserType
|
|
||||||
{
|
|
||||||
All = 0,
|
|
||||||
Admins = 1,
|
|
||||||
Custom = 2
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user