That is indeed how Matrix works already. And Discord is also doable with https://gitlab.com/An0/SimpleDiscordCrypt