private void MessagesRequest() { DateTime ts = new DateTime(); const uint messagesCount = 20U; var recivedMessages = new List <Message>(); if (messageHistories[currentGroup.groupID].Count == 0) { ts = DateTime.Now; recivedMessages = ClientRequests.ServerRequest <List <Message> >($"{configInfo.serverAddress}/api/chat/messages/" + $"{currentUser?.nickname}/{currentUser.userID}/{currentGroup.groupID}/" + $"{ts.ToUniversalTime().ToString("O", System.Globalization.CultureInfo.InvariantCulture)}/{messagesCount}/", null, "GET"); } else { ts = messageHistories[currentGroup.groupID][^ 1].timestamp;
//Sending a post request storing the message to the server private async void Send(object sender, RoutedEventArgs e) { if ((connectLabel.Content as string) == "Online") { bool infoAvailable = false; foreach (char symbol in messageTextBox.Text) { if (symbol != ' ' && symbol != '\r' && symbol != '\n') { infoAvailable = true; break; } } if (!String.IsNullOrEmpty(messageTextBox.Text) && infoAvailable) { int end = messageTextBox.Text.Length - 1; for (int i = 1; i < end; i++) { if (messageTextBox.Text[i] == ' ' && messageTextBox.Text[i - 1] == ' ' && messageTextBox.Text[i + 1] == ' ') { messageTextBox.Text = messageTextBox.Text.Remove(i - 1, 1); i -= 1; end -= 1; } if (i > 1 && i < end - 1) { if (messageTextBox.Text[i] == '\r' && messageTextBox.Text[i - 2] == '\r' && messageTextBox.Text[i + 2] == '\r') { messageTextBox.Text = messageTextBox.Text.Remove(i - 1, 2); i -= 1; end -= 2; } } } Message mes = new Message() { content = messageTextBox.Text, timestamp = DateTime.Now, fromID = currentUser.ToString(), groupID = currentGroup.groupID }; messageTextBox.Text = string.Empty; await Task.Run(() => ClientRequests.ServerRequest <AuthResponse>($"{configInfo.serverAddress}/api/chat/messages", mes)); } } }