private void removed(string whoRemoved) { //a temp value in order to update friendlist var temp = new friend(); temp.name = whoRemoved; temp.alreadyFriend = false; for (int i = 0; i < friendList.Count(); i++) { if (friendList[i].name == whoRemoved && friendList[i].alreadyFriend == true) { friendList[i] = temp; break; } } showFriendsList(); showNewFriendList(); }
//accept invitation button clicked private void button_acceptInvation_Click(object sender, EventArgs e) { //for every checked items accept foreach (string indexChecked in waitingInvations.CheckedItems) { string checkedFriend = indexChecked.ToString(); string addMessage = name + ": accepted the invitation from =>" + checkedFriend + "\n"; Byte[] buffer4 = Encoding.Default.GetBytes(addMessage); clientSocket.Send(buffer4); //*************** waitingInvationsList.Remove(checkedFriend); var temp = new friend(); temp.name = checkedFriend; temp.alreadyFriend = true; for (int i = 0; i < friendList.Count(); i++) { if (friendList[i].name == checkedFriend) { friendList[i] = temp; break; } } } //update waiting invations showWaitingInvations(); //show our friends showFriendsList(); }
//if this user is accepted this function runs private void accepted(string whoAccepted) { //a temp value in order to update friendlist var temp = new friend(); temp.name = whoAccepted; temp.alreadyFriend = true; for (int i = 0; i < friendList.Count(); i++) { if (friendList[i].name == whoAccepted) { //now we are friend !! so we made alreadyfriend true for which friend name == who accept us friendList[i] = temp; break; } } //updating pending requests. since we received no pending request so remove it from list and update friendlist and also pending list text box pendingRequests.Remove(whoAccepted); showFriendsList(); pendingRequestsFunction(); }
//this is the way who we can add as friend . this is for add new friends part public void addFriendList() { //CHANGE THIS PARTTTTTTT ACCORDING TO YOUR PATH string[] lines = System.IO.File.ReadAllLines(@"../../friendlistDB.txt"); var temp = new friend(); // Add all the names from txt to allClientNames. alreadyFriendsList.Items.Clear(); for (int i = 1; i < lines.Count(); i++) { temp.name = lines[i].Substring(0, lines[i].IndexOf('(')); temp.alreadyFriend = false; friendList.Add(temp); if (temp.name == name) { string friends = lines[i].Substring(lines[i].IndexOf('(') + 1, lines[i].IndexOf(')') - lines[i].IndexOf('(') - 1); string friendName = ""; foreach (char ch in friends) { if (ch == ',') { if (!alreadyFriendsList.Items.Contains(friendName)) { alreadyFriendsList.Items.Add(friendName); } for (int k = 0; k < friendList.Count(); k++) { if (friendList[k].name == friendName) { var tempF = new friend(); tempF.name = friendName; tempF.alreadyFriend = true; friendList[k] = tempF; button_remove_friend.Enabled = true; button_send_private.Enabled = true; } } friendName = ""; } else { friendName += ch; } } } } //foreach (string line in lines) //{ // temp.name = line; // temp.alreadyFriend = false; // friendList.Add(temp); //} //show add new friendlist showNewFriendList(); //enable the newfriendlist checkbox newFriendList.Enabled = true; //enable the send invation button button_sendInvitation.Enabled = true; }