File size: 1,341 Bytes
64a3c1d
 
 
 
 
 
 
 
 
 
 
 
 
 
ecb51fa
64a3c1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
using Microsoft.AspNetCore.SignalR;
using TaskTrackingSystem.Shared.Models.Notification;

namespace TaskTrackingSystem.WebApi.Features.Notification;

public class NotificationRealtimeService
{
    private readonly IHubContext<NotificationHub> _hubContext;

    public NotificationRealtimeService(IHubContext<NotificationHub> hubContext)
    {
        _hubContext = hubContext;
    }

    public async global::System.Threading.Tasks.Task SendCreatedAsync(long recipientId, NotificationDto notification, int unreadCount)
    {
        var group = _hubContext.Clients.Group(NotificationHub.GetUserGroupName(recipientId));
        await group.SendAsync("NotificationCreated", notification);
        await group.SendAsync("UnreadCountChanged", unreadCount);
    }

    public global::System.Threading.Tasks.Task SendUnreadCountAsync(long recipientId, int unreadCount)
    {
        return _hubContext.Clients
            .Group(NotificationHub.GetUserGroupName(recipientId))
            .SendAsync("UnreadCountChanged", unreadCount);
    }

    public global::System.Threading.Tasks.Task SendReadAsync(long recipientId, long notificationId, int unreadCount)
    {
        return _hubContext.Clients
            .Group(NotificationHub.GetUserGroupName(recipientId))
            .SendAsync("NotificationRead", notificationId, unreadCount);
    }
}