We would all be lying if we said that we didn't act a certain way around certain people. We do this because we want to be able to be on the "same level" as the other person, or not come across as too over the top or reserved for them. In some cases, that is just natural instinct. We can sometimes change the levels of energy we project because of the energy levels we receive from the other person. This is normal and is totally okay to do.
What is not okay to do, is to compromise your feelings and morals to make someone else feel better.
Let's say, for example, you have a friend who tends to have a negative personality the majority of the time. What I mean by this is that they are a person who complains and vents about everything at any given time, tends to talk behind others backs and does not say nice things all the time. When this friend of yours one day says something rude and uncalled for about someone else, the common on the spot reaction is to just stay quiet and leave it be. You choose to not interject because you fear that they will get mad at you for being defensive over something that they deem "unimportant" or "silly".
If what they said hurt your feelings or made you feel bad in any way, then that is not okay. You choosing to stay quiet is choosing to compromise your morals for the sake of your friend. When this friend keeps taking advantage of that since they know you will keep listening, it encourages them to continue to talk badly and negatively and it will help nothing at all.
The idea of interjecting can be kind of scary when it can affect the flow of a relationship. But if you really think about it, if they are truly your friend, then they would take your feelings into account and would adhere to your concerns. Letting someone fill your life with the negativity that they have for others does not sound like a decent friend to have. And if they say all these negative things about other people all the time, then maybe they are saying negative things about you to others as well.
Your feelings and morals are valid, and you should never compromise them for the benefit of someone else who you know is in the wrong. It is important to keep positive lights in your life, and maybe if you use your voice in those uncomfortable situations, then maybe it can help that person see that positive light that they need to apply to their life.
Sometimes these situations are a lot more complex and could cost you friendships. But, it is always better to keep to your moral standards, because then the more positive friendships will become ever more present in your life.