private async Task ExecuteSendPrivateMessageAsync(CreatePrivateChatMessageDto model, CancellationToken ct = default) { model.UserId = Context.UserIdentifier; GetPrivateChatMessageDto message = await _privateChatMessageService.AddMessageAsync(model, ct); GetPrivateChatDto chat = await _privateChatService.GetChatByIdAsync(model.ChatId, ct); await Clients.Users(chat.InvitedUser.Id, chat.CreatedByUser.Id).SendAsync(nameof(ChatMessageHub), message, cancellationToken: ct); }
public async Task <IActionResult> CreateChatAsync([FromBody] CreatePrivateChatDto privateChatDto) { try { privateChatDto.UserId = User.GetUserId(); GetPrivateChatDto chat = await _privateChatService.CreatePrivateChatAsync(privateChatDto); return(Ok(chat)); } catch (UserNotFoundException) { return(BadRequest()); } catch (PrivateChatAlreadyExistException) { return(BadRequest()); } }