-// receive stores an image before its batch and wakes Run. link gives the device
-// and the own IDs. It returns false when the state file cannot hold the
-// message, so that the library does not acknowledge it, and Run stops the
-// daemon. An image that cannot be downloaded or stored gets a text marker. A
+// caughtUpBy ends the catch-up of the connection with the number catchups, when
+// no later connection started a new one.
+func (i *WhatsAppInbox) caughtUpBy(catchups int) {
+ i.mutex.Lock()
+ defer i.mutex.Unlock()
+
+ if i.catchups == catchups {
+ i.finishCatchup()
+ }
+}
+
+// finishCatchup ends a running catch-up and wakes Run, which logs all batches.
+// The caller holds the mutex.
+func (i *WhatsAppInbox) finishCatchup() {
+ if !i.catchingUp {
+ return
+ }
+
+ i.catchingUp = false
+ i.caughtUp = true
+ if i.catchupTimer != nil {
+ i.catchupTimer.Stop()
+ }
+
+ select {
+ case i.wake <- struct{}{}:
+ default:
+ }
+}
+
+// receive stores images and transcribed voice notes before their batches and
+// wakes Run. link gives the device and the own IDs. It returns false when the
+// state file cannot hold the message, so that the library does not acknowledge
+// it, and Run stops the daemon. Failed media input gets a text marker. A