Merge client-resynchronisation-bug [r=therve,jkakar] [f=144475]
This fixes a long-standing bug in the client which causes resynchronisations on
the server.
The "persistent" data we record about a client's state wasn't being persisted
regularly enough, so there was a window between enqueuing a message with a
state change, and the new state being recorded, if the client was shutdown
during this window, the new state wasn't recorded, but the message remained, so
the state change was notified again after the client was brought back up,
triggering a resynchronisation.