How can I keep Mac messages in sync while the Mac is idle or off?

At night, after 9 p.m., my iMac is asleep or turned off. If during that time I receive messages on my phone, they will not appear in the Mac message history when I turn it on or turn it back on.

I hate that my different devices (phone, tablet, laptop, desktop computer) have different message histories. In general, the phone is the only complete one, since it almost never shuts down.

Is it even possible to get a Mac to recover recent messages that were lost?