jellyfin/MediaBrowser.Model/Notifications/NotificationOptions.cs

126 lines
4.1 KiB
C#
Raw Normal View History

2014-07-02 20:34:08 +02:00
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Extensions;
2014-04-27 05:42:05 +02:00
2014-07-02 20:34:08 +02:00
namespace MediaBrowser.Model.Notifications
2014-04-27 05:42:05 +02:00
{
public class NotificationOptions
{
public NotificationOption[] Options { get; set; }
public NotificationOptions()
{
Options = new[]
{
new NotificationOption
{
Type = NotificationType.TaskFailed.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.ServerRestartRequired.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.ApplicationUpdateAvailable.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.ApplicationUpdateInstalled.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.PluginUpdateInstalled.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.PluginUninstalled.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.InstallationFailed.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
},
new NotificationOption
{
Type = NotificationType.PluginInstalled.ToString(),
2014-04-27 19:54:43 +02:00
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-29 05:56:20 +02:00
},
new NotificationOption
{
Type = NotificationType.PluginError.ToString(),
Enabled = true,
SendToUserMode = SendToUserType.Admins
2014-04-27 05:42:05 +02:00
}
};
}
public NotificationOption GetOptions(string type)
{
foreach (NotificationOption i in Options)
{
if (StringHelper.EqualsIgnoreCase(type, i.Type)) return i;
}
return null;
2014-04-27 05:42:05 +02:00
}
public bool IsEnabled(string type)
{
NotificationOption opt = GetOptions(type);
2014-04-27 05:42:05 +02:00
return opt != null && opt.Enabled;
}
public bool IsServiceEnabled(string service, string notificationType)
{
NotificationOption opt = GetOptions(notificationType);
2014-04-27 05:42:05 +02:00
return opt == null ||
2014-07-01 06:06:28 +02:00
!ListHelper.ContainsIgnoreCase(opt.DisabledServices, service);
2014-04-27 05:42:05 +02:00
}
public bool IsEnabledToMonitorUser(string type, string userId)
{
NotificationOption opt = GetOptions(type);
2014-04-27 05:42:05 +02:00
return opt != null && opt.Enabled &&
2014-07-01 06:06:28 +02:00
!ListHelper.ContainsIgnoreCase(opt.DisabledMonitorUsers, userId);
2014-04-27 05:42:05 +02:00
}
2014-04-27 19:54:43 +02:00
public bool IsEnabledToSendToUser(string type, string userId, UserConfiguration userConfig)
2014-04-27 05:42:05 +02:00
{
NotificationOption opt = GetOptions(type);
2014-04-27 05:42:05 +02:00
2014-04-27 19:54:43 +02:00
if (opt != null && opt.Enabled)
{
if (opt.SendToUserMode == SendToUserType.All)
{
return true;
}
if (opt.SendToUserMode == SendToUserType.Admins && userConfig.IsAdministrator)
{
return true;
}
2014-07-01 06:06:28 +02:00
return ListHelper.ContainsIgnoreCase(opt.SendToUsers, userId);
2014-04-27 19:54:43 +02:00
}
return false;
2014-04-27 05:42:05 +02:00
}
}
}