Exemplo n.º 1
0
        public override async Task JoinChat(GetChat request,
                                            IServerStreamWriter <Message> responseStream,
                                            ServerCallContext context)
        {
            if (request?.ChatId is null)
            {
                _logger.LogError("Request is null");
                return;
            }

            var prevMessages = new List <Message>();
            var listMessages = new List <Message>();

            while (!context.CancellationToken.IsCancellationRequested)
            {
                var chat = await _chatRepository.GetChatAsync(request.ChatId);

                listMessages = chat.History.Except(prevMessages).ToList();

                foreach (var message in listMessages)
                {
                    await responseStream.WriteAsync(message);
                }

                if (listMessages.Count != 0 || prevMessages.Count == 0)
                {
                    prevMessages.AddRange(listMessages);
                }
            }

            listMessages.Clear();
            prevMessages.Clear();
        }
Exemplo n.º 2
0
        public PostChat Register(GetChat input)
        {
            var registerInfo = JsonConvert.SerializeObject(input);
            var httpContent  = new StringContent(registerInfo, Encoding.UTF8, "application/json");

            string apiLink = "https://latest-chat.herokuapp.com/api/user/register";

            var response = _client.PostAsync(apiLink, httpContent).Result;
            var data     = response.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <PostChat>(data));
        }
Exemplo n.º 3
0
        public Dictionary <string, string> Login(GetChat input)
        {
            var loginInfo   = JsonConvert.SerializeObject(input);
            var httpContent = new StringContent(loginInfo, Encoding.UTF8, "application/json");

            string apiLink = "https://latest-chat.herokuapp.com/api/user/login";

            var response = _client.PostAsync(apiLink, httpContent).Result;
            var data     = response.Content.ReadAsStringAsync().Result;

            var returned = JsonConvert.DeserializeObject <Dictionary <string, string> >(data);

            returned.TryGetValue("apiKey", out string apiKey);
            ApiKey   = apiKey;
            LoggedIn = new User()
            {
                ApiKey = ApiKey, Login = input.Login
            };
            return(returned);
        }
 public IChatModel Any(GetChat request)
 {
     return(workflow.Get(request.ID));
 }
Exemplo n.º 5
0
        public IActionResult LoginUser(GetChat input)
        {
            var loggedIn = chatService.Login(input);

            return(View("MainPage"));
        }
Exemplo n.º 6
0
        public IActionResult Register(GetChat input)
        {
            var registered = chatService.Register(input);

            return(View("MainPage"));
        }
 public static ValidationResult <GetChat> CreateValidation(this GetChat value) =>
 new ValidationResult <GetChat>(value).ValidateRequired(x => x.ChatId);
Exemplo n.º 8
0
 public ChatModel(GetChat getChat)
 {
     _getChat = getChat;
 }
Exemplo n.º 9
0
 public async Task <IActionResult> GetChat([FromServices] GetChat getChat, int id)
 {
     return(Ok(await getChat.Do(id)));
 }