A convicted sex offender who shared explicit messages with what he thought were children on social media has been jailed.