Surprised nobody here is talking about Matrix. Open source, client side / end to end encrypted, chat history stored (encrypted) on the server so it syncs to every device, supports federation, and supports bridges so you can use Matrix to access your other accounts like Signal, WhatsApp, etc and have everything in one place.
Beeper.com is based on Matrix and worth a look. But you can also self-host everything.