diff --git a/clientapi/routing/sendtodevice.go b/clientapi/routing/sendtodevice.go index 45ea86c75..5d3060d74 100644 --- a/clientapi/routing/sendtodevice.go +++ b/clientapi/routing/sendtodevice.go @@ -33,13 +33,11 @@ func SendToDevice( eventType string, txnID *string, ) util.JSONResponse { if txnID != nil { - // Try to fetch response from transactionsCache if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok { return *res } } - // parse the incoming http request var httpReq struct { Messages map[string]map[string]json.RawMessage `json:"messages"` } @@ -59,8 +57,14 @@ func SendToDevice( } } - return util.JSONResponse{ + res := util.JSONResponse{ Code: http.StatusOK, JSON: struct{}{}, } + + if txnID != nil { + txnCache.AddTransaction(device.AccessToken, *txnID, &res) + } + + return res } diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 402ac5dcf..725952ed8 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -174,11 +174,9 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea // This is a bit of a hack until we can do something better with the sync API // than this mess. If we have pending send-to-device updates then we want to // deliver them pretty quickly. We still want the next step to run so that the - // sync tokens are updated properly. Set a short timeout on the next step so - // that we return faster. - ctx, cancel := context.WithTimeout(req.ctx, time.Second) - defer cancel() - req.ctx = ctx + // sync tokens are updated properly. Set a zero timeout on the next step so + // that we return immediately. + req.timeout = 0 } // TODO: handle ignored users