From 480c1f4882c1cbc671c5e90ad7683e6f60d904ee Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 2 May 2024 23:39:04 +0200 Subject: [PATCH] Simplify group request making --- ts/groups.ts | 52 +++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index 45a0f089c9..8dd76cc5cd 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -353,7 +353,7 @@ export async function getPreJoinGroupInfo( Bytes.fromBase64(masterKeyBase64) ); - return makeRequestWithTemporalRetry({ + return makeRequestWithCredentials({ logId: `getPreJoinInfo/groupv2(${data.id})`, publicParams: Bytes.toBase64(data.publicParams), secretParams: Bytes.toBase64(data.secretParams), @@ -462,7 +462,7 @@ async function uploadAvatar( }).finish(); const ciphertext = encryptGroupBlob(clientZkGroupCipher, blobPlaintext); - const key = await makeRequestWithTemporalRetry({ + const key = await makeRequestWithCredentials({ logId: `uploadGroupAvatar/${logId}`, publicParams, secretParams, @@ -1458,7 +1458,7 @@ async function uploadGroupChange({ throw new Error('uploadGroupChange: group was missing publicParams!'); } - return makeRequestWithTemporalRetry({ + return makeRequestWithCredentials({ logId: `uploadGroupChange/${logId}`, publicParams: group.publicParams, secretParams: group.secretParams, @@ -1676,7 +1676,7 @@ export function deriveGroupFields(masterKey: Uint8Array): GroupFields { return fresh; } -async function makeRequestWithTemporalRetry({ +async function makeRequestWithCredentials({ logId, publicParams, secretParams, @@ -1688,17 +1688,17 @@ async function makeRequestWithTemporalRetry({ request: (sender: MessageSender, options: GroupCredentialsType) => Promise; }): Promise { const groupCredentials = getCheckedGroupCredentialsForToday( - `makeRequestWithTemporalRetry/${logId}` + `makeRequestWithCredentials/${logId}` ); const sender = window.textsecure.messaging; if (!sender) { throw new Error( - `makeRequestWithTemporalRetry/${logId}: textsecure.messaging is not available!` + `makeRequestWithCredentials/${logId}: textsecure.messaging is not available!` ); } - log.info(`makeRequestWithTemporalRetry/${logId}: starting`); + log.info(`makeRequestWithCredentials/${logId}: starting`); const todayOptions = getGroupCredentials({ authCredentialBase64: groupCredentials.today.credential, @@ -1707,25 +1707,7 @@ async function makeRequestWithTemporalRetry({ serverPublicParamsBase64: window.getServerPublicParams(), }); - try { - return await request(sender, todayOptions); - } catch (todayError) { - if (todayError.code === TEMPORAL_AUTH_REJECTED_CODE) { - log.warn( - `makeRequestWithTemporalRetry/${logId}: Trying again with tomorrow's credentials` - ); - const tomorrowOptions = getGroupCredentials({ - authCredentialBase64: groupCredentials.tomorrow.credential, - groupPublicParamsBase64: publicParams, - groupSecretParamsBase64: secretParams, - serverPublicParamsBase64: window.getServerPublicParams(), - }); - - return request(sender, tomorrowOptions); - } - - throw todayError; - } + return request(sender, todayOptions); } export async function fetchMembershipProof({ @@ -1745,7 +1727,7 @@ export async function fetchMembershipProof({ throw new Error('fetchMembershipProof: group was missing secretParams!'); } - const response = await makeRequestWithTemporalRetry({ + const response = await makeRequestWithCredentials({ logId: 'fetchMembershipProof', publicParams, secretParams, @@ -1897,7 +1879,7 @@ export async function createGroupV2( }); try { - await makeRequestWithTemporalRetry({ + await makeRequestWithCredentials({ logId: `createGroupV2/${logId}`, publicParams, secretParams, @@ -2053,7 +2035,7 @@ export async function hasV1GroupBeenMigrated( const fields = deriveGroupFields(masterKeyBuffer); try { - await makeRequestWithTemporalRetry({ + await makeRequestWithCredentials({ logId: `getGroup/${logId}`, publicParams: Bytes.toBase64(fields.publicParams), secretParams: Bytes.toBase64(fields.secretParams), @@ -2410,7 +2392,7 @@ export async function initiateMigrationToGroupV2( }); try { - await makeRequestWithTemporalRetry({ + await makeRequestWithCredentials({ logId: `createGroup/${logId}`, publicParams, secretParams, @@ -2731,7 +2713,7 @@ export async function respondToGroupV2Migration({ let firstGroupState: Proto.IGroup | null | undefined; try { - const response: GroupLogResponseType = await makeRequestWithTemporalRetry({ + const response: GroupLogResponseType = await makeRequestWithCredentials({ logId: `getGroupLog/${logId}`, publicParams, secretParams, @@ -2755,7 +2737,7 @@ export async function respondToGroupV2Migration({ `respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state` ); try { - firstGroupState = await makeRequestWithTemporalRetry({ + firstGroupState = await makeRequestWithCredentials({ logId: `getGroup/${logId}`, publicParams, secretParams, @@ -3601,7 +3583,7 @@ async function updateGroupViaPreJoinInfo({ // No password, but if we're already pending approval, we can access this without it. const inviteLinkPassword = undefined; - const preJoinInfo = await makeRequestWithTemporalRetry({ + const preJoinInfo = await makeRequestWithCredentials({ logId: `getPreJoinInfo/${logId}`, publicParams, secretParams, @@ -3669,7 +3651,7 @@ async function updateGroupViaState({ throw new Error('updateGroupViaState: group was missing publicParams!'); } - const groupState = await makeRequestWithTemporalRetry({ + const groupState = await makeRequestWithCredentials({ logId: `getGroup/${logId}`, publicParams, secretParams, @@ -3813,7 +3795,7 @@ async function updateGroupViaLogs({ const changes: Array = []; do { // eslint-disable-next-line no-await-in-loop - response = await makeRequestWithTemporalRetry({ + response = await makeRequestWithCredentials({ logId: `getGroupLog/${logId}`, publicParams, secretParams,