X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/48d7bce28b18ecef4c52c98821675605464cecb9..3cdbd017da9ae7a7045f4272f16d4b262fd01c79:/whatsapp_inbox.go diff --git a/whatsapp_inbox.go b/whatsapp_inbox.go index 392593f..9d2183e 100644 --- a/whatsapp_inbox.go +++ b/whatsapp_inbox.go @@ -16,19 +16,20 @@ import ( ) const ( - // whatsappLookupTime is the longest time of a read of names in the - // session. - whatsappLookupTime = 10 * time.Second + // whatsappContactLookupTimeout is the longest time of a read of names + // in the session. + whatsappContactLookupTimeout = 10 * time.Second - // whatsappImageTime is the longest time of an image download. - whatsappImageTime = 2 * time.Minute + // whatsappImageDownloadTimeout is the longest time of an image + // download. + whatsappImageDownloadTimeout = 2 * time.Minute // whatsappSource is the source of the work events of the batches. whatsappSource = "whatsapp" - // whatsappCatchupLimit is the longest wait for the end of the catch-up - // after a connection. - whatsappCatchupLimit = time.Minute + // whatsappCatchupTimeout is the longest wait for the end of the + // catch-up after a connection. + whatsappCatchupTimeout = time.Minute ) // newWhatsAppInbox returns the inbox of the batches in state, with clock for @@ -52,7 +53,7 @@ func newWhatsAppInbox(state *WhatsAppState, clock func() time.Time, groups *What // // After each connection, the servers send the messages that came while the // daemon was away, and then OfflineSyncCompleted. Until then, or until -// whatsappCatchupLimit passes, the closed batches wait in the state file. At +// whatsappCatchupTimeout passes, the closed batches wait in the state file. At // the end of the catch-up, deliver closes all batches and logs them. It wakes // the root once for its batches, so their catch-up gives one turn, not one for // each chat. The batches of the state file at the start wait for the first @@ -207,7 +208,7 @@ func (i *WhatsAppInbox) waitForCatchup() { } // startCatchup starts the catch-up of a new connection, which ends at -// endCatchup or after whatsappCatchupLimit. +// endCatchup or after whatsappCatchupTimeout. func (i *WhatsAppInbox) startCatchup() { i.mutex.Lock() defer i.mutex.Unlock() @@ -219,7 +220,7 @@ func (i *WhatsAppInbox) startCatchup() { i.catchupTimer.Stop() } - i.catchupTimer = time.AfterFunc(whatsappCatchupLimit, func() { + i.catchupTimer = time.AfterFunc(whatsappCatchupTimeout, func() { i.caughtUpBy(catchups) }) } @@ -230,7 +231,7 @@ func (i *WhatsAppInbox) startCatchup() { // daemon. An image that cannot be downloaded or stored gets a text marker. A // message that the batches do not take is handled with nothing to do. func (i *WhatsAppInbox) receive(ctx context.Context, link WhatsAppLink, event *events.Message) bool { - lookupCtx, cancel := context.WithTimeout(ctx, whatsappLookupTime) + lookupCtx, cancel := context.WithTimeout(ctx, whatsappContactLookupTimeout) defer cancel() chat, message, found := whatsappMessage(lookupCtx, link.device, link.own, event) @@ -239,7 +240,7 @@ func (i *WhatsAppInbox) receive(ctx context.Context, link WhatsAppLink, event *e } if event.Message.GetImageMessage() != nil { - ctx, cancel := context.WithTimeout(ctx, whatsappImageTime) + ctx, cancel := context.WithTimeout(ctx, whatsappImageDownloadTimeout) defer cancel() message.Text = i.imageText(ctx, link, event, message.Text)