|
|
|
@ -47,10 +47,27 @@ export class FriendPageComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
onAcceptOrDeny(id: string, choice: string){
|
|
|
|
|
if (choice == "accept"){
|
|
|
|
|
this.friendService.acceptFriendById(id).subscribe()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.friendService.denyFriendById(id).subscribe()
|
|
|
|
|
// If return code is 200, then the friend has been accepted so we can change the status of the friend to accepted
|
|
|
|
|
this.friendService.acceptFriendById(id).subscribe((data: any) => {
|
|
|
|
|
if (data.message == "Friend request accepted"){
|
|
|
|
|
this.listFriend.forEach(friend => {
|
|
|
|
|
if (friend.id == id){
|
|
|
|
|
friend.status = "accepted";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// If return code is 200, then the friend has been denied so we can delete the friend from the list
|
|
|
|
|
this.friendService.denyFriendById(id).subscribe((data: any) => {
|
|
|
|
|
if (data.message == "Friend request denied"){
|
|
|
|
|
this.listFriend.forEach((friend, index) => {
|
|
|
|
|
if (friend.id == id){
|
|
|
|
|
this.listFriend.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|