예제 #1
0
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var entities = await _context.Notifications.Where(x => request.Ids.Contains(x.Id) &&
                                                                  !x.IsRead &&
                                                                  x.UserId == _requestContext.UserId)
                               .ToListAsync(cancellationToken);

                entities.ForEach(x => x.IsRead = true);
                await _context.SaveChangesAsync(cancellationToken);

                _signalRHubAggregator.SendToUser(HubEndpointConstants.NotifyReadEndpoint, entities.Count, _requestContext.UserId.Value);

                return(new Response());
            }
예제 #2
0
            private async Task SendNotificationAsync(MaterialComment parentComment, int commentId, string authorUserName, string commentText)
            {
                var notification = new CreateNotificationCommand.Request
                {
                    DateTime  = DateTimeOffset.Now,
                    UserId    = parentComment.AuthorId,
                    Type      = (NotificationType)parentComment.Type,
                    EntityId  = parentComment.MaterialId ?? parentComment.MatchId,
                    CommentId = commentId,
                    Text      = $"Пользователь {authorUserName} оставил ответ на ваш комментарий: \"{commentText}\"."
                };
                var notificationDto = await _mediator.Send(notification);

                _signalRHubAggregator.SendToUser(HubEndpointConstants.NewNotifyEndpoint, notificationDto, parentComment.AuthorId);
            }
예제 #3
0
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                await RemoveOldMessagesAsync(request.ReceiverId, cancellationToken);
                await RemoveOldMessagesAsync(_requestContext.UserId.Value, cancellationToken);

                var entity = _mapper.Map <PrivateMessage>(request);

                entity.SentTime = DateTimeOffset.UtcNow;
                entity.SenderId = _requestContext.UserId.Value;

                _context.PrivateMessages.Add(entity);
                await _context.SaveChangesAsync(cancellationToken);

                await _messageService.SendNewPmToEmailAsync(entity.ReceiverId, entity.Message, entity.Id);

                _signalRHub.SendToUser(HubEndpointConstants.NewPmEndpoint, entity, request.ReceiverId);

                return(new Response {
                    Id = entity.Id
                });
            }
예제 #4
0
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var message = await _context.PrivateMessages
                              .Include(m => m.Receiver)
                              .Include(m => m.Sender)
                              .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);

                if (message == null || message.ReceiverId != _requestContext.UserId && message.SenderId != _requestContext.UserId)
                {
                    throw new NotFoundException(nameof(PrivateMessage), request.Id);
                }

                if (!message.IsRead && message.ReceiverId == _requestContext.UserId)
                {
                    message.IsRead = true;
                    await _context.SaveChangesAsync(cancellationToken);

                    _signalRHub.SendToUser(HubEndpointConstants.PmReadEndpoint, true, _requestContext.UserId.Value);
                }

                return(_mapper.Map <Response>(message));
            }