jellyfin/Emby.Notifications/CoreNotificationTypes.cs

124 lines
4.2 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2014-04-27 05:42:05 +02:00
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Notifications;
2016-10-24 04:45:23 +02:00
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Notifications;
2014-04-27 05:42:05 +02:00
2018-09-12 19:26:21 +02:00
namespace Emby.Notifications
2014-04-27 05:42:05 +02:00
{
public class CoreNotificationTypes : INotificationTypeFactory
{
private readonly ILocalizationManager _localization;
2019-02-06 20:53:05 +01:00
public CoreNotificationTypes(ILocalizationManager localization)
2014-04-27 05:42:05 +02:00
{
_localization = localization;
}
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
{
2019-02-06 20:53:05 +01:00
var knownTypes = new NotificationTypeInfo[]
2014-04-27 05:42:05 +02:00
{
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.ApplicationUpdateInstalled)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.InstallationFailed)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.PluginInstalled)
2014-04-27 05:42:05 +02:00
},
2014-04-29 05:56:20 +02:00
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.PluginError)
2014-04-29 05:56:20 +02:00
},
2014-04-27 05:42:05 +02:00
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.PluginUninstalled)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.PluginUpdateInstalled)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.ServerRestartRequired)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.TaskFailed)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.NewLibraryContent)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.AudioPlayback)
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.VideoPlayback)
2014-05-16 19:11:07 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.AudioPlaybackStopped)
2014-05-16 19:11:07 +02:00
},
new NotificationTypeInfo
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.VideoPlaybackStopped)
},
new NotificationTypeInfo
2015-03-02 06:16:29 +01:00
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.UserLockedOut)
2019-02-06 20:53:05 +01:00
},
new NotificationTypeInfo
2014-04-27 19:54:43 +02:00
{
2021-12-15 18:25:36 +01:00
Type = nameof(NotificationType.ApplicationUpdateAvailable)
2019-02-06 20:53:05 +01:00
}
};
2014-04-27 19:54:43 +02:00
2014-04-27 05:42:05 +02:00
foreach (var type in knownTypes)
{
Update(type);
}
2017-10-13 07:44:20 +02:00
var systemName = _localization.GetLocalizedString("System");
2014-04-29 05:56:20 +02:00
return knownTypes.OrderByDescending(i => string.Equals(i.Category, systemName, StringComparison.OrdinalIgnoreCase))
.ThenBy(i => i.Category)
.ThenBy(i => i.Name);
2014-04-27 05:42:05 +02:00
}
private void Update(NotificationTypeInfo note)
{
2021-12-15 18:25:36 +01:00
note.Name = _localization.GetLocalizedString("NotificationOption" + note.Type);
2014-04-27 05:42:05 +02:00
note.IsBasedOnUserEvent = note.Type.IndexOf("Playback", StringComparison.OrdinalIgnoreCase) != -1;
if (note.Type.IndexOf("Playback", StringComparison.OrdinalIgnoreCase) != -1)
{
2017-10-13 07:44:20 +02:00
note.Category = _localization.GetLocalizedString("User");
2014-04-27 05:42:05 +02:00
}
else if (note.Type.IndexOf("Plugin", StringComparison.OrdinalIgnoreCase) != -1)
2014-04-29 05:56:20 +02:00
{
2017-10-13 07:44:20 +02:00
note.Category = _localization.GetLocalizedString("Plugin");
2014-04-29 05:56:20 +02:00
}
2015-03-02 06:16:29 +01:00
else if (note.Type.IndexOf("UserLockedOut", StringComparison.OrdinalIgnoreCase) != -1)
{
2017-10-13 07:44:20 +02:00
note.Category = _localization.GetLocalizedString("User");
2015-03-02 06:16:29 +01:00
}
2014-04-27 05:42:05 +02:00
else
{
2017-10-13 07:44:20 +02:00
note.Category = _localization.GetLocalizedString("System");
2014-04-27 05:42:05 +02:00
}
}
}
}