]> git.giacomolli.uk - onechat/blobdiff - whatsapp_inbox.go
Run each child with its own files and loop
[onechat] / whatsapp_inbox.go
index d76e43ca3b97ade93d2c2af60d0c421a8f31c12b..c7fbf51ff4ece235dd6b39de109818b6b4ce90e4 100644 (file)
@@ -89,12 +89,14 @@ func (i *WhatsAppInbox) due() <-chan time.Time {
 // first. With all, it closes and logs all batches also during a catch-up.
 func (i *WhatsAppInbox) deliver(ctx context.Context, l *TurnLoop, link WhatsAppLink, all bool) error {
        i.mutex.Lock()
+
        catchingUp := i.catchingUp
        caughtUp := i.caughtUp
        i.caughtUp = false
        i.mutex.Unlock()
 
        var err error
+
        switch {
        case all || caughtUp:
                err = i.state.CloseAll()
@@ -109,6 +111,7 @@ func (i *WhatsAppInbox) deliver(ctx context.Context, l *TurnLoop, link WhatsAppL
        }
 
        var turns []Message
+
        for _, batch := range i.state.Closed() {
                if batch.Chat.Group && batch.Chat.Name == "" {
                        batch.Chat.Name = i.groups.name(ctx, link, batch.Chat.ID)