示例#1
0
        private async Task ExecuteSendGroupMessageAsync(CreateGroupChatMessageDto model, CancellationToken ct = default)
        {
            GetGroupChatMessageDto message = await _groupChatMessageService.AddMessageAsync(model, ct);

            IReadOnlyList <string> userIds =
                message.Users.Select(t => t.Id).Where(t => t != Context.UserIdentifier).ToList();

            await Clients.Users(userIds).SendAsync(nameof(ChatMessageHub), message, cancellationToken: ct);
        }
        public async Task <GetGroupChatMessageDto> AddMessageAsync(CreateGroupChatMessageDto messageDto, CancellationToken ct = default)
        {
            _logger.LogInformation("Create group chat message {GroupChatMessage}", messageDto);

            GroupChat chat = await _unitOfWork.GroupChatRepository.GetAsync(messageDto.ChatId, ct);

            if (chat == null)
            {
                _logger.LogWarning("Group chat with id {GroupChatId} not found", messageDto.ChatId);
                throw new ChatNotFoundException();
            }

            GroupChatMessage message = _mapper.Map <GroupChatMessage>(messageDto);

            message.CreatedAt = message.UpdatedAt = DateTime.UtcNow;

            _unitOfWork.GroupChatMessageRepository.Create(message);

            await _unitOfWork.CommitAsync(ct);

            return(_mapper.Map <GetGroupChatMessageDto>(message));
        }
示例#3
0
 public async Task SendGroupMessageAsync(CreateGroupChatMessageDto model)
 {
     await ExecuteActionAsync(model, ExecuteSendGroupMessageAsync, _createGroupChatMessageValidator);
 }