"What you pet is what you get"
This is a popular saying among dog trainers and something that all dog owners want to keep in mind.
If a human is upset it is natural to want to give them some comfort through touch. A big hug or calming presence of a hand on our shoulder can do wonders to help us calm down.
This is not how dogs interpret that same kind of affection.
A loving pet or pat while your dog is practicing any difficult behavior (barking, lunging, growling) or emotion (sad, scared, angry) is only going to increase the intensity and/or the frequency of the reaction.
A pet to a dog means that you agree with them. So be careful to pet a dog doing behaviors that you like and with a state of mind/emotions that you also like.
That can go a long way to showing your dog that is good to be calm, happy and relaxed.