When you do something good for someone else and they appreciate it, you feel good.
Let’s say you do the same good thing and the other person doesn’t appreciate it — you’ll feel bad, resentful and betrayed, but only if you link your emotions to that other person’s reaction.
This is why the motivation behind your action is the key. If you do something good because you feel good simply for doing it, you won’t need other person’s acknowledgment or recognition, and their bad reaction tom it, however unfortunate, won’t be able to make you feel bad.
It might, however, make you think less of them or question the foundation of your relationship with such people, but that’s another story.