private async void RadGridView_SelectionChanged(object sender, SelectionChangeEventArgs e) { ChatMessages.Items.Clear(); //deleting all messages in a UI ActiveUserClient activeUsers = new ActiveUserClient(); var activeUserInfo = await activeUsers.ActiveUsers(AccessToken); MessageToFrom message = new MessageToFrom(); message.To = Username; foreach (var contact in activeUserInfo) { if (contact.Username.Contains(ContactsList.SelectedItem.ToString())) { message.From = contact.Username; //checking the contact name } } MessageClient messageClient = new MessageClient(AccessToken); var messages = await messageClient.ReadAllMessages(message); //getting all messages foreach (var mess in messages) { ChatMessages.Items.Add(mess.From + ": " + mess.MessageText); } }
//oldList.Add("Vzgo"); //oldList.Add("Tigran"); //oldList.Add("Suren"); //oldList.Add("Areg"); //oldList.Add("Narek"); //oldList.Add("Arthur"); //foreach (var item in oldList) //{ // RadGridView.Items.Add(item); //} private async void Window_Loaded(object sender, RoutedEventArgs e) { NameUser.Content = Username; string currentPath = Environment.CurrentDirectory + "\\token.txt"; string accesstoken = File.ReadAllText(currentPath); var accessTokenDeserialised = JsonConvert.DeserializeObject <AuthServerResponse>(accesstoken); ActiveUserClient activeUsers = new ActiveUserClient(); var activeUserInfo = await activeUsers.ActiveUsers(AccessToken); if (activeUserInfo != null) { foreach (var user in activeUserInfo) { Contacts.Add(user); ContactsList.Items.Add(user.Username); } } //RadGridView.ItemsSource = Contacts.Select(cont => cont.Username); var dueTime = TimeSpan.FromSeconds(1); var interval = TimeSpan.FromSeconds(1); await CallAPIPeriodicAsync(CallingAPIs, dueTime, interval, CancellationToken.None); // MessageToFrom messageNotif = new MessageToFrom(); // messageNotif.From = Username; // messageNotif.To = RadGridView.SelectedItem.ToString(); // MessageClient readMessages = new MessageClient(accessTokenDeserialised.access_token); // var messages = readMessages.ReadAllMessages(messageNotif) //// ActiveUserClient activeUser = new ActiveUserClient(); //HttpClient client = new HttpClient(); ////Post client //var Json = JsonConvert.SerializeObject(Name); //var httpContent = new StringContent(Json, Encoding.UTF8, "application/json"); //await client.PostAsync(messageapi+"/onlineusers/add/"+Name, httpContent); ////post client //while (true) //{ // var response = client.GetAsync(messageapi + "/onlineusers");//.Result.Content.ReadAsStringAsync().Result; // var jsonresult = response.Result.Content.ReadAsStringAsync().Result; // var result = JsonConvert.DeserializeObject<List<UsersFromTo>>(jsonresult); // foreach (var item in result) // { // RadGridView.Items.Add(item.From); // } // Thread.Sleep(5000); //} }
private async void RadGridView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ChatMessages.Items.Clear(); //string currentPath = Environment.CurrentDirectory + "\\token.txt"; //string accesstoken = File.ReadAllText(currentPath); //var accessTokenDeserialised = JsonConvert.DeserializeObject<AuthServerResponse>(accesstoken); ActiveUserClient activeUsers = new ActiveUserClient(); var activeUserInfo = await activeUsers.ActiveUsers(AccessToken); MessageToFrom message = new MessageToFrom(); message.To = Username; MessageClient messageClient = new MessageClient(AccessToken); foreach (var contact in activeUserInfo) { if (ContactsList.SelectedItem.ToString().Contains(contact.Username)) { ContactsList.SelectedItem = contact.Username; message.From = contact.Username; await messageClient.MakeMessageRead(message); break; } } var messages = await messageClient.ReadAllMessages(message); foreach (var mess in messages) { ChatMessages.Items.Add(mess.From + ": " + mess.MessageText); } //ChatMessages.Items.Clear(); //HttpClient client = new HttpClient(); //var response = client.GetAsync(string.Format("{0}/{1}/{2}", messageapi, Username, RadGridView.SelectedItem.ToString()));//.Result.Content.ReadAsStringAsync().Result; //var jsonresult = response.Result.Content.ReadAsStringAsync().Result; //var result = JsonConvert.DeserializeObject<List<Message>>(jsonresult); //foreach (var item in result) //{ // if(!ChatMessages.Items.Contains(item.MessageText)) ChatMessages.Items.Add(item.MessageText); //} MessageTextbox.Text = "Type your message here..."; }
private async void Window_Loaded(object sender, RoutedEventArgs e) { NameUser.Content = Username; ActiveUserClient activeUsers = new ActiveUserClient(); var activeUserInfo = await activeUsers.ActiveUsers(AccessToken); if (activeUserInfo != null) { foreach (var user in activeUserInfo) { Contacts.Add(user); ContactsList.Items.Add(user.Username); } } var dueTime = TimeSpan.FromSeconds(1); var interval = TimeSpan.FromSeconds(1); //calling API's continuosly await CallAPIPeriodicAsync(CallingAPIs, dueTime, interval, CancellationToken.None); }
private async void RadGridView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ChatMessages.Items.Clear(); ActiveUserClient activeUsers = new ActiveUserClient(); var activeUserInfo = await activeUsers.ActiveUsers(AccessToken); //giving client and access token MessageToFrom message = new MessageToFrom { To = Username }; MessageClient messageClient = new MessageClient(AccessToken); foreach (var contact in activeUserInfo) { if (ContactsList.SelectedItem.ToString().Contains(contact.Username)) { ContactsList.SelectedItem = contact.Username; message.From = contact.Username; await messageClient.MakeMessageRead(message); break; } } var messages = await messageClient.ReadAllMessages(message); //reading all messages with this contact foreach (var mess in messages) { ChatMessages.Items.Add(mess.From + ": " + mess.MessageText); // adding all messages to a messageItems } MessageTextbox.Text = "Type your message here..."; }