public async Task <SuccessOrError <Unit> > Handle(SendChatMessageRequest request, CancellationToken cancellationToken) { var(participant, _, channel, _) = request; var conferenceId = participant.ConferenceId; var message = await BuildChatMessage(request); var channelId = ChannelSerializer.Encode(channel); var messagesCount = await _chatRepository.AddChatMessageAndGetMessageCount(conferenceId, channelId.ToString(), message); var subscribedParticipants = await _mediator.Send(new FetchSubscribedParticipantsRequest(conferenceId, channelId)); if (channel is PrivateChatChannel privateChatChannel) { subscribedParticipants = await UpdateParticipantsSubscriptionsIfNecessary(subscribedParticipants, privateChatChannel, participant.ConferenceId); } await _mediator.Publish(new ChatMessageReceivedNotification(conferenceId, subscribedParticipants, message, channel, messagesCount)); await _mediator.Send(new SetParticipantTypingRequest(participant, channel, false)); return(Unit.Value); }