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(); }
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)); }
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)); }
public IActionResult LoginUser(GetChat input) { var loggedIn = chatService.Login(input); return(View("MainPage")); }
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);
public ChatModel(GetChat getChat) { _getChat = getChat; }
public async Task <IActionResult> GetChat([FromServices] GetChat getChat, int id) { return(Ok(await getChat.Do(id))); }