Hey Brian,
First of all i set the title of the editProfileFollowButton to "Loading". So that you don't see the Edit Profile title when opening a userprofile that is not yours. Secondly to guarantee that you can't follow and unfollow yourself so that your button only has the title "Edit Profile" you have to change the handleEditProfileOrFollowButton() method. Wrap the code inside it with the following if statement if currentLoggedInUser != userId { ....} and then create an else part to execute code that belongs to edit Profile.
func handleEditProfileOrFollowButton(){
print("Execute Edit profile / follow/ Unfollow logic")
guard let currentLoggedInUser = FIRAuth.auth()?.currentUser?.uid
else { return }
guard let userId = user?.uid
else { return }
if currentLoggedInUser != userId {
if editProfileFollowButton.titleLabel?.text == "Unfollow" {
FIRDatabase.database().reference().child("following").child(currentLoggedInUser).child(userId).removeValue(completionBlock: { (err, ref) in
if let err = err {
print("Failed to unfollow user", err)
return
}
print("Succesfully unfollowd user", self.user?.username ?? "")
self.setupFollowStyle()
})
}else {
// Follow logic
let ref = FIRDatabase.database().reference().child("following").child(currentLoggedInUser)
let values = [userId: 1]
ref.updateChildValues(values) { (err, ref) in
if let err = err {
print("Failed to follow user ", err)
return
}
print("Succesfully followed user", self.user?.username ?? "")
self.setupUnfollowStyle()
}
}
}
else {
print("HandlEditProfile ")
}
}