Beispiel #1
0
        public async Task <Unit> Handle(DeleteSingleCommand request, CancellationToken cancellationToken)
        {
            var userId         = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id;
            var notificationId = Guid.Parse(request.NotificationId);

            await _notificationRepository.RemoveById(notificationId);

            var notifications = await _notificationCache.Get(userId);

            _notificationCache.Set(userId, notifications.Where(x => x.Id != notificationId));

            return(await Unit.Task);
        }
        public override async Task OnConnectedAsync()
        {
            var httpContext = Context.GetHttpContext();
            var userId      = httpContext.User.Claims.ToTokenPayload().UserClaims.Id;

            var connectionId = Context.ConnectionId;

            _connectionManager.Add(userId, connectionId);

            var notifications = await _notificationCache.Get(userId);

            await Clients.Caller.SeedNotifications(notifications.Select(x => x.ToDto()));

            await base.OnConnectedAsync();
        }
        public async Task <Unit> Handle(ReadAllCommand request, CancellationToken cancellationToken)
        {
            var userId = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id;
            await _notificationRepository.MarkAllAsRead(userId);

            var notifications = await _notificationCache.Get(userId);

            foreach (var notification in notifications)
            {
                notification.SetIsRead(true);
            }
            _notificationCache.Set(userId, notifications);

            return(await Unit.Task);
        }
Beispiel #4
0
        public async Task <Unit> Handle(RefreshCacheAndSeedUsersCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Refreshing cache and seeding users");

            foreach (var userId in request.UserIds)
            {
                _notificationCache.Delete(userId);

                var connectionIds = _connectionManager.Get(userId).ToList();
                if (connectionIds.Count == 0)
                {
                    continue;
                }

                var notifications = await _notificationCache.Get(userId);

                await _notificationHubContext.Clients.Clients(connectionIds)
                .SeedNotifications(notifications.Select(x => x.ToDto()));
            }

            return(await Unit.Task);
        }