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...";
        }
Exemple #2
0
        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...";
        }