Usernames: Fetch own username from /whoami not /profile

This commit is contained in:
Scott Nonnenberg 2021-12-15 12:02:55 -08:00 committed by GitHub
parent 70ae5bb613
commit a023fc1bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 26 deletions

View file

@ -135,6 +135,7 @@ import { ToastConversationUnarchived } from './components/ToastConversationUnarc
import { showToast } from './util/showToast'; import { showToast } from './util/showToast';
import { startInteractionMode } from './windows/startInteractionMode'; import { startInteractionMode } from './windows/startInteractionMode';
import { deliveryReceiptsJobQueue } from './jobs/deliveryReceiptsJobQueue'; import { deliveryReceiptsJobQueue } from './jobs/deliveryReceiptsJobQueue';
import { updateOurUsername } from './util/updateOurUsername';
const MAX_ATTACHMENT_DOWNLOAD_AGE = 3600 * 72 * 1000; const MAX_ATTACHMENT_DOWNLOAD_AGE = 3600 * 72 * 1000;
@ -2137,13 +2138,16 @@ export async function startApp(): Promise<void> {
try { try {
// Note: we always have to register our capabilities all at once, so we do this // Note: we always have to register our capabilities all at once, so we do this
// after connect on every startup // after connect on every startup
await server.registerCapabilities({ await Promise.all([
announcementGroup: true, server.registerCapabilities({
'gv2-3': true, announcementGroup: true,
'gv1-migration': true, 'gv2-3': true,
senderKey: true, 'gv1-migration': true,
changeNumber: true, senderKey: true,
}); changeNumber: true,
}),
updateOurUsername(),
]);
} catch (error) { } catch (error) {
log.error( log.error(
'Error: Unable to register our capabilities.', 'Error: Unable to register our capabilities.',
@ -3458,7 +3462,7 @@ export async function startApp(): Promise<void> {
case FETCH_LATEST_ENUM.LOCAL_PROFILE: { case FETCH_LATEST_ENUM.LOCAL_PROFILE: {
const ourUuid = window.textsecure.storage.user.getUuid()?.toString(); const ourUuid = window.textsecure.storage.user.getUuid()?.toString();
const ourE164 = window.textsecure.storage.user.getNumber(); const ourE164 = window.textsecure.storage.user.getNumber();
await getProfile(ourUuid, ourE164); await Promise.all([getProfile(ourUuid, ourE164), updateOurUsername()]);
break; break;
} }
case FETCH_LATEST_ENUM.STORAGE_MANIFEST: case FETCH_LATEST_ENUM.STORAGE_MANIFEST:

View file

@ -18,15 +18,16 @@ import { refMerger } from '../util/refMerger';
import { byteLength } from '../Bytes'; import { byteLength } from '../Bytes';
export type PropsType = { export type PropsType = {
countLength?: (value: string) => number;
countBytes?: (value: string) => number; countBytes?: (value: string) => number;
countLength?: (value: string) => number;
disabled?: boolean; disabled?: boolean;
disableSpellcheck?: boolean;
expandable?: boolean; expandable?: boolean;
hasClearButton?: boolean; hasClearButton?: boolean;
i18n: LocalizerType; i18n: LocalizerType;
icon?: ReactNode; icon?: ReactNode;
maxLengthCount?: number;
maxByteCount?: number; maxByteCount?: number;
maxLengthCount?: number;
moduleClassName?: string; moduleClassName?: string;
onChange: (value: string) => unknown; onChange: (value: string) => unknown;
onEnter?: () => unknown; onEnter?: () => unknown;
@ -58,15 +59,16 @@ export const Input = forwardRef<
>( >(
( (
{ {
countLength = grapheme.count,
countBytes = byteLength, countBytes = byteLength,
countLength = grapheme.count,
disabled, disabled,
disableSpellcheck,
expandable, expandable,
hasClearButton, hasClearButton,
i18n, i18n,
icon, icon,
maxLengthCount = 0,
maxByteCount = 0, maxByteCount = 0,
maxLengthCount = 0,
moduleClassName, moduleClassName,
onChange, onChange,
onEnter, onEnter,
@ -201,6 +203,7 @@ export const Input = forwardRef<
isLarge && getClassName('__input--large') isLarge && getClassName('__input--large')
), ),
disabled: Boolean(disabled), disabled: Boolean(disabled),
spellcheck: disableSpellcheck ? 'false' : 'true',
onChange: handleChange, onChange: handleChange,
onKeyDown: handleKeyDown, onKeyDown: handleKeyDown,
onPaste: handlePaste, onPaste: handlePaste,

View file

@ -617,6 +617,7 @@ export const ProfileEditor = ({
<Input <Input
i18n={i18n} i18n={i18n}
disabled={isCurrentlySaving} disabled={isCurrentlySaving}
disableSpellcheck
onChange={changedUsername => { onChange={changedUsername => {
setUsernameError(undefined); setUsernameError(undefined);
setNewUsername(changedUsername); setNewUsername(changedUsername);

View file

@ -3,6 +3,7 @@
import dataInterface from '../sql/Client'; import dataInterface from '../sql/Client';
import { handleMessageSend } from '../util/handleMessageSend'; import { handleMessageSend } from '../util/handleMessageSend';
import { updateOurUsername } from '../util/updateOurUsername';
export async function writeUsername({ export async function writeUsername({
username, username,
@ -12,7 +13,7 @@ export async function writeUsername({
previousUsername: string | undefined; previousUsername: string | undefined;
}): Promise<void> { }): Promise<void> {
const me = window.ConversationController.getOurConversationOrThrow(); const me = window.ConversationController.getOurConversationOrThrow();
await me.getProfiles(); await updateOurUsername();
if (me.get('username') !== previousUsername) { if (me.get('username') !== previousUsername) {
throw new Error('Username has changed on another device'); throw new Error('Username has changed on another device');

View file

@ -1814,10 +1814,6 @@ async function checkForUsername(
username username
); );
if (!profile.username || profile.username !== username) {
log.error("checkForUsername: Returned username didn't match searched");
return;
}
if (!profile.uuid) { if (!profile.uuid) {
log.error("checkForUsername: Returned profile didn't include a uuid"); log.error("checkForUsername: Returned profile didn't include a uuid");
return; return;
@ -1825,7 +1821,7 @@ async function checkForUsername(
return { return {
uuid: UUID.cast(profile.uuid), uuid: UUID.cast(profile.uuid),
username: profile.username, username,
}; };
} catch (error: unknown) { } catch (error: unknown) {
if (!isRecord(error)) { if (!isRecord(error)) {

View file

@ -2236,4 +2236,7 @@ export default class MessageSender {
async deleteUsername(): Promise<ReturnType<WebAPIType['deleteUsername']>> { async deleteUsername(): Promise<ReturnType<WebAPIType['deleteUsername']>> {
return this.server.deleteUsername(); return this.server.deleteUsername();
} }
async whoami(): Promise<ReturnType<WebAPIType['whoami']>> {
return this.server.whoami();
}
} }

View file

@ -715,7 +715,6 @@ export type ProfileType = Readonly<{
avatar?: string; avatar?: string;
unidentifiedAccess?: string; unidentifiedAccess?: string;
unrestrictedUnidentifiedAccess?: string; unrestrictedUnidentifiedAccess?: string;
username?: string;
uuid?: string; uuid?: string;
credential?: string; credential?: string;
capabilities?: CapabilitiesType; capabilities?: CapabilitiesType;
@ -751,6 +750,7 @@ export type WhoamiResultType = Readonly<{
uuid?: UUIDStringType; uuid?: UUIDStringType;
pni?: UUIDStringType; pni?: UUIDStringType;
number?: string; number?: string;
username?: string;
}>; }>;
export type ConfirmCodeResultType = Readonly<{ export type ConfirmCodeResultType = Readonly<{

View file

@ -174,13 +174,6 @@ export async function getProfile(
}); });
} }
const { username } = profile;
if (username) {
c.set({ username });
} else {
c.unset('username');
}
if (profile.about) { if (profile.about) {
const key = c.get('profileKey'); const key = c.get('profileKey');
if (key) { if (key) {

View file

@ -0,0 +1,16 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export async function updateOurUsername(): Promise<void> {
if (!window.textsecure.messaging) {
throw new Error(
'updateOurUsername: window.textsecure.messaging not available'
);
}
const me = window.ConversationController.getOurConversationOrThrow();
const { username } = await window.textsecure.messaging.whoami();
me.set({ username });
window.Signal.Data.updateConversation(me.attributes);
}