]> git.giacomolli.uk - onechat/blobdiff - whatsapp_inbox.go
Pass caller contexts through WhatsApp callbacks
[onechat] / whatsapp_inbox.go
index 5121976c6d00307e8e227a57cdca558a11a64a9b..06f1c558d03b930bd52f597c4bd61e49806ca9e5 100644 (file)
@@ -228,17 +228,17 @@ func (i *WhatsAppInbox) startCatchup() {
 // 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
 // message that the batches do not take is handled with nothing to do.
-func (i *WhatsAppInbox) receive(link WhatsAppLink, event *events.Message) bool {
-       ctx, cancel := context.WithTimeout(context.Background(), i.lookupTime)
+func (i *WhatsAppInbox) receive(ctx context.Context, link WhatsAppLink, event *events.Message) bool {
+       lookupCtx, cancel := context.WithTimeout(ctx, i.lookupTime)
        defer cancel()
 
-       chat, message, found := whatsappMessage(ctx, link.device, link.own, event)
+       chat, message, found := whatsappMessage(lookupCtx, link.device, link.own, event)
        if !found {
                return true
        }
 
        if event.Message.GetImageMessage() != nil {
-               ctx, cancel := context.WithTimeout(context.Background(), i.imageTime)
+               ctx, cancel := context.WithTimeout(ctx, i.imageTime)
                defer cancel()
 
                message.Text = i.imageText(ctx, link, event, message.Text)