This should fix the problems we've been having with out-of-order message deliveries, and is also an important prerequisite for showing historical messages. (imported from commit 77a18a526bf8ec4f1f70b776ac8b7e189d00bcf4)