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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,6 +288,7 @@ export async function resolveUsernameByLinkBase64(
strictAssert(serverId, 'Failed to re-encode server id as uuid');
strictAssert(window.textsecure.server, 'WebAPI must be available');
try {
const { usernameLinkEncryptedValue } = await server.resolveUsernameLink(
serverId
);
@ -296,4 +297,10 @@ export async function resolveUsernameByLinkBase64(
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,