Process username changes in storage service
This commit is contained in:
parent
71c97e9580
commit
1381e8df5d
8 changed files with 252 additions and 53 deletions
|
@ -36,7 +36,7 @@ export function getTitleNoDefault(
|
|||
|
||||
return (
|
||||
(isShort ? attributes.systemGivenName : undefined) ||
|
||||
attributes.name ||
|
||||
getSystemName(attributes) ||
|
||||
(isShort ? attributes.profileName : undefined) ||
|
||||
getProfileName(attributes) ||
|
||||
getNumber(attributes) ||
|
||||
|
@ -44,6 +44,30 @@ export function getTitleNoDefault(
|
|||
);
|
||||
}
|
||||
|
||||
// Note that the used attributes field should match the ones we listen for
|
||||
// change on in ConversationModel (see `ConversationModel#maybeClearUsername`)
|
||||
export function canHaveUsername(
|
||||
attributes: Pick<
|
||||
ConversationAttributesType,
|
||||
'id' | 'type' | 'name' | 'profileName' | 'profileFamilyName' | 'e164'
|
||||
>,
|
||||
ourConversationId: string | undefined
|
||||
): boolean {
|
||||
if (!isDirectConversation(attributes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ourConversationId === attributes.id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
!getSystemName(attributes) &&
|
||||
!getProfileName(attributes) &&
|
||||
!getNumber(attributes)
|
||||
);
|
||||
}
|
||||
|
||||
export function getProfileName(
|
||||
attributes: Pick<
|
||||
ConversationAttributesType,
|
||||
|
@ -57,6 +81,22 @@ export function getProfileName(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export function getSystemName(
|
||||
attributes: Pick<
|
||||
ConversationAttributesType,
|
||||
'systemGivenName' | 'systemFamilyName' | 'type'
|
||||
>
|
||||
): string | undefined {
|
||||
if (isDirectConversation(attributes)) {
|
||||
return combineNames(
|
||||
attributes.systemGivenName,
|
||||
attributes.systemFamilyName
|
||||
);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getNumber(
|
||||
attributes: Pick<ConversationAttributesType, 'e164' | 'type'>
|
||||
): string {
|
||||
|
|
|
@ -97,7 +97,7 @@ export async function lookupConversationWithoutUuid(
|
|||
|
||||
conversationId = convo.id;
|
||||
|
||||
convo.set({ username: foundUsername.username });
|
||||
await convo.updateUsername(foundUsername.username);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from './assert';
|
||||
import { dropNull } from './dropNull';
|
||||
|
||||
export async function updateOurUsernameAndPni(): Promise<void> {
|
||||
const { server } = window.textsecure;
|
||||
|
||||
strictAssert(
|
||||
server,
|
||||
'updateOurUsernameAndPni: window.textsecure.server not available'
|
||||
);
|
||||
|
||||
const me = window.ConversationController.getOurConversationOrThrow();
|
||||
const { username } = await server.whoami();
|
||||
|
||||
me.set({ username: dropNull(username) });
|
||||
window.Signal.Data.updateConversation(me.attributes);
|
||||
|
||||
const manager = window.getAccountManager();
|
||||
strictAssert(
|
||||
manager,
|
||||
'updateOurUsernameAndPni: AccountManager not available'
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue