Handle username link 404 by showing toast
This commit is contained in:
parent
2532e8902a
commit
b13cc693c7
2 changed files with 19 additions and 9 deletions
|
@ -274,7 +274,7 @@ const USERNAME_LINK_ENTROPY_SIZE = 32;
|
||||||
|
|
||||||
export async function resolveUsernameByLinkBase64(
|
export async function resolveUsernameByLinkBase64(
|
||||||
base64: string
|
base64: string
|
||||||
): Promise<string> {
|
): Promise<string | undefined> {
|
||||||
const { server } = window.textsecure;
|
const { server } = window.textsecure;
|
||||||
if (!server) {
|
if (!server) {
|
||||||
throw new Error('server interface is not available!');
|
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(serverId, 'Failed to re-encode server id as uuid');
|
||||||
|
|
||||||
strictAssert(window.textsecure.server, 'WebAPI must be available');
|
strictAssert(window.textsecure.server, 'WebAPI must be available');
|
||||||
|
try {
|
||||||
const { usernameLinkEncryptedValue } = await server.resolveUsernameLink(
|
const { usernameLinkEncryptedValue } = await server.resolveUsernameLink(
|
||||||
serverId
|
serverId
|
||||||
);
|
);
|
||||||
|
@ -296,4 +297,10 @@ export async function resolveUsernameByLinkBase64(
|
||||||
entropy: Buffer.from(entropy),
|
entropy: Buffer.from(entropy),
|
||||||
encryptedUsername: Buffer.from(usernameLinkEncryptedValue),
|
encryptedUsername: Buffer.from(usernameLinkEncryptedValue),
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof HTTPError && error.code === 404) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,9 +566,12 @@ export function createIPCEvents(
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeUsernameBase64 = parseUsernameBase64FromSignalDotMeHash(hash);
|
const maybeUsernameBase64 = parseUsernameBase64FromSignalDotMeHash(hash);
|
||||||
|
let username: string | undefined;
|
||||||
if (maybeUsernameBase64) {
|
if (maybeUsernameBase64) {
|
||||||
const username = await resolveUsernameByLinkBase64(maybeUsernameBase64);
|
username = await resolveUsernameByLinkBase64(maybeUsernameBase64);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username) {
|
||||||
const convoId = await lookupConversationWithoutServiceId({
|
const convoId = await lookupConversationWithoutServiceId({
|
||||||
type: 'username',
|
type: 'username',
|
||||||
username,
|
username,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue