jellyfin/MediaBrowser.Model/Notifications/NotificationOptions.cs

132 lines
4.3 KiB
C#
Raw Normal View History

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