jellyfin/Emby.Notifications/CoreNotificationTypes.cs

124 lines
4.2 KiB
C#
Raw Normal View History

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