Beispiel #1
0
        public async void getFriends()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                ConvoList.Items.Clear();
                ConvoList.Items.Add(" ");
                ConvoList.SelectedItem = " ";
                if (friendRequestList.Items.Contains(" ") == false)
                {
                    friendRequestList.Items.Add(" ");
                    friendRequestList.SelectedItem = " ";
                }
            }));
            usr    userName = new usr(theUser);
            string json     = JsonConvert.SerializeObject(userName);
            var    data     = new StringContent(json, Encoding.UTF8, "application/json");
            var    rec      = await client.PostAsync(url + "getFriends", data);

            var res = rec.Content.ReadAsStringAsync().Result;

            Console.WriteLine(res);
            if (res.Contains(theUser))
            {
                res = res.Replace("\"", "");
                res = res.Replace("_id:", "");
                res = res.Replace("accepted:", "");
                res = res.Replace("sender:", "");
                res = res.Replace("secondUsername:"******"");
                res = res.Replace("dateEntered:", "");
                var friendList = res.Split(',');
                Console.WriteLine(res);
                int numFriends = friendList.Length / 6;
                Console.WriteLine(numFriends);
                for (int i = 3; i < friendList.Length; i += 6)
                {
                    if (friendList[i - 2] == "true")
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            ConvoList.Items.Add(friendList[i]);
                        }));
                    }
                }
            }
        }
Beispiel #2
0
        public async void getFriendRequest(object sender, EventArgs e)
        {
            usr    userName = new usr(theUser);
            string json     = JsonConvert.SerializeObject(userName);
            var    data     = new StringContent(json, Encoding.UTF8, "application/json");
            var    rec      = await client.PostAsync(url + "getFriendRequests", data);

            var res = rec.Content.ReadAsStringAsync().Result;

            Console.WriteLine(res);

            if (res != "[]" && res != null)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    var friendReq = JsonConvert.DeserializeObject <List <friendRequest> >(res);
                    Console.WriteLine(res);
                    int reqs = 0;
                    foreach (friendRequest f in friendReq)
                    {
                        if (f.accepted != true)
                        {
                            reqs++;
                        }
                    }
                    if (reqs != 0 && friendReq != null)
                    {
                        newFriendRequestLbl.Content = reqs + " New Friend Requests!";

                        foreach (friendRequest f in friendReq)
                        {
                            if (f != null && f.accepted != true &&
                                friendRequestList.Items.Contains(f.secondUsername) == false)
                            {
                                Console.WriteLine(f.secondUsername);
                                friendRequestList.Items.Add(f.secondUsername);
                            }
                        }
                    }
                }));
            }
        }