public async Task OnMessageReceived(ChatMsgReceivedContext ctx)
        {
            bool inJail = await UserIsInJail(ctx.Message.UserInfo.UserId);

            if (inJail)
            {
                ctx.Destination = DestinationType.Self;
                ctx.Message.Metadata["flood"] = true;
                ctx.MessageDto.Metadata       = ctx.Message.Metadata.ToString();
            }
            await Task.CompletedTask;
        }
        public async Task OnMessageReceived(IScenePeerClient client, string text, Action <ChatMessageDto, DestinationType> sender)
        {
            // Check if user is connected
            ChatUserInfoDto userInfo = null;

            _connectedUsers.TryGetValue(client, out userInfo);
            if (userInfo == null)
            {
                throw new ClientException($"User not found {client.Id} .");
            }

            // Store message in log
            ChatMessage messageLog = new ChatMessage
            {
                Channel  = client.SceneId,
                Date     = DateTime.UtcNow,
                Message  = text,
                Metadata = new JObject(),
                UserInfo = new UserInfo
                {
                    UserId = userInfo.UserId,
                    Data   = JObject.Parse(userInfo.Data)
                }
            };

            ChatMessageDto messageDto = new ChatMessageDto
            {
                Message   = text,
                TimeStamp = _env.Clock,
                UserInfo  = userInfo,
            };

            ChatMsgReceivedContext receiveCtx = new ChatMsgReceivedContext(messageLog, messageDto);

            receiveCtx.Destination = DestinationType.All;

            await _chatEventHandler?.RunEventHandler(eh =>
            {
                return(eh.OnMessageReceived(receiveCtx));
            }, ex =>
            {
                _log.Log(LogLevel.Error, _logCategory, "An error occured when the chat service check if the user is in jail.", ex);
                throw new ClientException($"An error occured when the chat service check if the user is in jail.");
            });

            _chatRepository.AddMessageLog(receiveCtx.Message);
            _messagesSource.OnNext(receiveCtx.Message);
            sender(receiveCtx.MessageDto, receiveCtx.Destination);
        }