aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Notifications/InternalNotificationService.cs
blob: 61c564f188e37d9ddea8e881c3da368691d45aa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Model.Notifications;
using System.Threading;
using System.Threading.Tasks;
using System;

namespace Emby.Server.Implementations.Notifications
{
    public class InternalNotificationService : INotificationService, IConfigurableNotificationService
    {
        private readonly INotificationsRepository _repo;

        public InternalNotificationService(INotificationsRepository repo)
        {
            _repo = repo;
        }

        public string Name
        {
            get { return "Dashboard Notifications"; }
        }

        public Task SendNotification(UserNotification request, CancellationToken cancellationToken)
        {
            return _repo.AddNotification(new Notification
            {
                Date = request.Date,
                Description = request.Description,
                Level = request.Level,
                Name = request.Name,
                Url = request.Url,
                UserId = request.User.Id.ToString("N")

            }, cancellationToken);
        }

        public bool IsEnabledForUser(User user)
        {
            return user.Policy.IsAdministrator;
        }

        public bool IsHidden
        {
            get { return true; }
        }

        public bool IsEnabled(string notificationType)
        {
            if (notificationType.IndexOf("playback", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return false;
            }
            if (notificationType.IndexOf("newlibrarycontent", StringComparison.OrdinalIgnoreCase) != -1)
            {
                return false;
            }
            return true;
        }
    }
}