diff --git a/ement.el b/ement.el index 0441200..f8193fb 100644 --- a/ement.el +++ b/ement.el @@ -614,16 +614,20 @@ To be called in `ement-sync-callback-hook'." do (run-hook-with-args 'ement-event-hook event room session) (when (ement--sync-messages-p session) (ement-progress-update))) - (when (alist-get 'limited timeline) - ;; Timeline was limited: start filling gap. We start the - ;; gap-filling, retrieving up to the session's current - ;; next-batch token (this function is not called when retrieving - ;; older messages, so the session's next-batch token is only - ;; evaluated once, when this chain begins, and then that token - ;; is passed to repeated calls to `ement-room-retro-to-token' - ;; until the gap is filled). - (ement-room-retro-to-token joined-room session (alist-get 'prev_batch timeline) - (ement-session-next-batch session))))) + (when (ement-session-has-synced-p session) + ;; NOTE: We don't fill gaps in "limited" requests on initial + ;; sync, only in subsequent syncs, e.g. after the system has + ;; slept and awakened. + (when (alist-get 'limited timeline) + ;; Timeline was limited: start filling gap. We start the + ;; gap-filling, retrieving up to the session's current + ;; next-batch token (this function is not called when retrieving + ;; older messages, so the session's next-batch token is only + ;; evaluated once, when this chain begins, and then that token + ;; is passed to repeated calls to `ement-room-retro-to-token' + ;; until the gap is filled). + (ement-room-retro-to-token room session (alist-get 'prev_batch timeline) + (ement-session-next-batch session)))))) (defun ement--make-event (event) "Return `ement-event' struct for raw EVENT list.