Fix crash when changing your username

This commit is contained in:
Evan Hahn 2022-01-13 15:25:20 -06:00 committed by GitHub
parent 48836d5761
commit 393b740fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -1753,7 +1753,10 @@ export class ConversationModel extends window.Backbone
id: this.id,
uuid: this.get('uuid'),
e164: this.get('e164'),
username: this.get('username'),
// We had previously stored `null` instead of `undefined` in some cases. We should
// be able to remove this `dropNull` once usernames have gone to production.
username: dropNull(this.get('username')),
about: this.getAboutText(),
aboutText: this.get('about'),

View File

@ -1,4 +1,4 @@
// Copyright 2020-2021 Signal Messenger, LLC
// Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable no-param-reassign */
@ -38,7 +38,7 @@ import type { SocketStatus } from '../types/SocketStatus';
import { toLogFormat } from '../types/errors';
import { isPackIdValid, redactPackId } from '../types/Stickers';
import type { UUID, UUIDStringType } from '../types/UUID';
import { UUIDKind } from '../types/UUID';
import { isValidUuid, UUIDKind } from '../types/UUID';
import * as Bytes from '../Bytes';
import {
constantTimeEqual,
@ -1265,12 +1265,25 @@ export function initialize({
return `identity=${value}`;
}
async function whoami() {
return (await _ajax({
async function whoami(): Promise<WhoamiResultType> {
const response = await _ajax({
call: 'whoami',
httpType: 'GET',
responseType: 'json',
})) as WhoamiResultType;
});
if (!isRecord(response)) {
return {};
}
return {
uuid: isValidUuid(response.uuid) ? response.uuid : undefined,
pni: isValidUuid(response.pni) ? response.pni : undefined,
number:
typeof response.number === 'string' ? response.number : undefined,
username:
typeof response.username === 'string' ? response.username : undefined,
};
}
async function sendChallengeResponse(challengeResponse: ChallengeType) {