jellyfin/Emby.Server.Implementations/Notifications/CoreNotificationTypes.cs

199 lines
8 KiB
C#
Raw Normal View History

2014-04-27 19:54:43 +02:00
using MediaBrowser.Controller;
2014-04-27 05:42:05 +02:00
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Model.Notifications;
using System;
using System.Collections.Generic;
using System.Linq;
2016-10-24 04:45:23 +02:00
using MediaBrowser.Model.Globalization;
2014-04-27 05:42:05 +02:00
2016-11-03 08:35:00 +01:00
namespace Emby.Server.Implementations.Notifications
2014-04-27 05:42:05 +02:00
{
public class CoreNotificationTypes : INotificationTypeFactory
{
private readonly ILocalizationManager _localization;
2014-04-27 19:54:43 +02:00
private readonly IServerApplicationHost _appHost;
2014-04-27 05:42:05 +02:00
2014-04-27 19:54:43 +02:00
public CoreNotificationTypes(ILocalizationManager localization, IServerApplicationHost appHost)
2014-04-27 05:42:05 +02:00
{
_localization = localization;
2014-04-27 19:54:43 +02:00
_appHost = appHost;
2014-04-27 05:42:05 +02:00
}
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
{
var knownTypes = new List<NotificationTypeInfo>
{
new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateInstalled.ToString(),
2014-05-01 05:24:55 +02:00
DefaultDescription = "{ReleaseNotes}",
2015-03-21 17:10:02 +01:00
DefaultTitle = "A new version of Emby Server has been installed.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Version"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.InstallationFailed.ToString(),
DefaultTitle = "{Name} installation failed.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "Version"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.PluginInstalled.ToString(),
DefaultTitle = "{Name} was installed.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "Version"}
2014-04-27 05:42:05 +02:00
},
2014-04-29 05:56:20 +02:00
new NotificationTypeInfo
{
Type = NotificationType.PluginError.ToString(),
2014-04-30 17:07:02 +02:00
DefaultTitle = "{Name} has encountered an error.",
DefaultDescription = "{ErrorMessage}",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "ErrorMessage"}
2014-04-29 05:56:20 +02:00
},
2014-04-27 05:42:05 +02:00
new NotificationTypeInfo
{
Type = NotificationType.PluginUninstalled.ToString(),
DefaultTitle = "{Name} was uninstalled.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "Version"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.PluginUpdateInstalled.ToString(),
DefaultTitle = "{Name} was updated.",
2014-04-30 17:07:02 +02:00
DefaultDescription = "{ReleaseNotes}",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "ReleaseNotes", "Version"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.ServerRestartRequired.ToString(),
2015-03-21 17:10:02 +01:00
DefaultTitle = "Please restart Emby Server to finish updating."
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.TaskFailed.ToString(),
DefaultTitle = "{Name} failed.",
2014-04-30 17:07:02 +02:00
DefaultDescription = "{ErrorMessage}",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name", "ErrorMessage"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.NewLibraryContent.ToString(),
DefaultTitle = "{Name} has been added to your media library.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"Name"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.AudioPlayback.ToString(),
DefaultTitle = "{UserName} is playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.GamePlayback.ToString(),
DefaultTitle = "{UserName} is playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
2014-04-27 05:42:05 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.VideoPlayback.ToString(),
DefaultTitle = "{UserName} is playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
2014-05-16 19:11:07 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.AudioPlaybackStopped.ToString(),
DefaultTitle = "{UserName} has finished playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
2014-05-16 19:11:07 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.GamePlaybackStopped.ToString(),
DefaultTitle = "{UserName} has finished playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
2014-05-16 19:11:07 +02:00
},
new NotificationTypeInfo
{
Type = NotificationType.VideoPlaybackStopped.ToString(),
DefaultTitle = "{UserName} has finished playing {ItemName} on {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName", "ItemName", "DeviceName", "AppName"}
},
new NotificationTypeInfo
{
Type = NotificationType.CameraImageUploaded.ToString(),
DefaultTitle = "A new camera image has been uploaded from {DeviceName}.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"DeviceName"}
2015-03-02 06:16:29 +01:00
},
new NotificationTypeInfo
{
Type = NotificationType.UserLockedOut.ToString(),
DefaultTitle = "{UserName} has been locked out.",
2017-08-19 21:43:35 +02:00
Variables = new string[]{"UserName"}
2014-04-27 05:42:05 +02:00
}
};
2014-04-27 19:54:43 +02:00
if (!_appHost.CanSelfUpdate)
{
knownTypes.Add(new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateAvailable.ToString(),
2015-03-21 17:10:02 +01:00
DefaultTitle = "A new version of Emby Server is available for download."
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)
{
note.Name = _localization.GetLocalizedString("NotificationOption" + note.Type) ?? note.Type;
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
}
else if (note.Type.IndexOf("CameraImageUploaded", StringComparison.OrdinalIgnoreCase) != -1)
{
2017-10-13 07:44:20 +02:00
note.Category = _localization.GetLocalizedString("Sync");
}
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
}
}
}
}