Handle username link 404 by showing toast

This commit is contained in:
Fedor Indutny
2023-08-28 19:01:41 +02:00
committed by GitHub
parent 2532e8902a
commit b13cc693c7
2 changed files with 19 additions and 9 deletions

View File

@@ -274,7 +274,7 @@ const USERNAME_LINK_ENTROPY_SIZE = 32;
export async function resolveUsernameByLinkBase64(
base64: string
): Promise<string> {
): Promise<string | undefined> {
const { server } = window.textsecure;
if (!server) {
throw new Error('server interface is not available!');
@@ -288,12 +288,19 @@ export async function resolveUsernameByLinkBase64(
strictAssert(serverId, 'Failed to re-encode server id as uuid');
strictAssert(window.textsecure.server, 'WebAPI must be available');
const { usernameLinkEncryptedValue } = await server.resolveUsernameLink(
serverId
);
try {
const { usernameLinkEncryptedValue } = await server.resolveUsernameLink(
serverId
);
return usernames.decryptUsernameLink({
entropy: Buffer.from(entropy),
encryptedUsername: Buffer.from(usernameLinkEncryptedValue),
});
return usernames.decryptUsernameLink({
entropy: Buffer.from(entropy),
encryptedUsername: Buffer.from(usernameLinkEncryptedValue),
});
} catch (error) {
if (error instanceof HTTPError && error.code === 404) {
return undefined;
}
throw error;
}
}

View File

@@ -566,9 +566,12 @@ export function createIPCEvents(
}
const maybeUsernameBase64 = parseUsernameBase64FromSignalDotMeHash(hash);
let username: string | undefined;
if (maybeUsernameBase64) {
const username = await resolveUsernameByLinkBase64(maybeUsernameBase64);
username = await resolveUsernameByLinkBase64(maybeUsernameBase64);
}
if (username) {
const convoId = await lookupConversationWithoutServiceId({
type: 'username',
username,