Пример #1
0
        /// <summary>
        /// Handler for message sending.
        /// Persists message in database and then sends it through the hub to listeners
        /// </summary>
        /// <param name="message"></param>
        public async Task SendMessage(MessageViewModel message)
        {
            var createRequest = _mapper.Map <MessageViewModel, CreateChatMessageRequest>(message);
            await _mediator.Send(createRequest);

            var sender = AllConnectedParticipants.FirstOrDefault(x => x.Key == message.FromId);

            if (sender.Value != null)
            {
                // get fresh presigned url for display
                message.DownloadUrl = await _s3AccessService.RenewPresignedUrl(message.DownloadUrl, message.S3Filename);

                // send message
                await Clients.User(message.ToId).SendAsync("messageReceived", sender.Value.Participant, message);
            }
        }