This is tough! I have this with a close family member, ever time I saw them it was draining AF.
So to change this, I had to change my mindset as they clearly weren't going to change, and I can't help but spend time with them in family situations.
Firstly - I don't entertain the negativity. When they're commenting open negative comments, looking for a reception from me or an "oh no you poor thing / that's terrible / how could that happen / oh my god you're right that's awful" I either just sit and smile, do a tinkly laugh and don't respond or say something non committal "oh really" "hmmm" etc.
Secondly - I don't bring it out of the situation with them, whatever negativity they spew I don't allow myself to think about once they're out of my company. This stops is "leaking" into my life and bringing me down with their negativity! The easiest way I've found is on the way home from seeing them, I listen to loud music and sing along / moan out loud about them. Once the journey is over, so is my time spent on the situation!
Thirdly - I don't do things alone with them. Easier said than done sometimes, but always easier to stay positive / change topic when another person is present.
This got long quickly 😂 hope any of my ramble is of some use!