Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix requestContact invalid async executor #550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-planets-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@telegram-apps/sdk": patch
---

Fix `requestContact` invalid async executor
12 changes: 8 additions & 4 deletions packages/sdk/src/scopes/utilities/privacy/requestContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ function getRequestedContact(options?: AsyncOptions): CancelablePromise<Requeste
export const requestContact = wrapSafe(
'requestContact',
(options?: AsyncOptions): CancelablePromise<RequestedContact> => {
return new CancelablePromise(
async (res, _, abortSignal) => {
return CancelablePromise.withFn(
async (abortSignal) => {
const asyncOptions = { abortSignal };

// First of all, let's try to get the requested contact.
// Probably, we already requested it before.
try {
return res(await getRequestedContact(asyncOptions));
return await getRequestedContact(asyncOptions);
} catch {
}

Expand All @@ -93,7 +93,7 @@ export const requestContact = wrapSafe(
// We are trying to retrieve the requested contact until the deadline was reached.
while (!abortSignal.aborted) {
try {
return res(await getRequestedContact(asyncOptions));
return await getRequestedContact(asyncOptions);
} catch {
}

Expand All @@ -103,6 +103,10 @@ export const requestContact = wrapSafe(
// Increase the sleep time not to kill the backend service.
sleepTime += 50;
}

// Reachable code, but the promise will be rejected and this result will be
// ignored.
return null as any;
}, options,
);
},
Expand Down
Loading