Use ContactRecord.systemNickname

This commit is contained in:
Fedor Indutny 2023-02-13 14:40:11 -08:00 committed by GitHub
parent 949efca190
commit 1f95c2299e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 91 additions and 57 deletions

View file

@ -192,7 +192,7 @@
"@babel/preset-typescript": "7.17.12", "@babel/preset-typescript": "7.17.12",
"@electron/fuses": "1.5.0", "@electron/fuses": "1.5.0",
"@mixer/parallel-prettier": "2.0.1", "@mixer/parallel-prettier": "2.0.1",
"@signalapp/mock-server": "2.14.0", "@signalapp/mock-server": "2.15.0",
"@storybook/addon-a11y": "6.5.6", "@storybook/addon-a11y": "6.5.6",
"@storybook/addon-actions": "6.5.6", "@storybook/addon-actions": "6.5.6",
"@storybook/addon-controls": "6.5.6", "@storybook/addon-controls": "6.5.6",

View file

@ -95,6 +95,7 @@ message ContactRecord {
optional uint64 unregisteredAtTimestamp = 16; optional uint64 unregisteredAtTimestamp = 16;
optional string systemGivenName = 17; optional string systemGivenName = 17;
optional string systemFamilyName = 18; optional string systemFamilyName = 18;
optional string systemNickname = 19;
} }
message GroupV1Record { message GroupV1Record {

1
ts/model-types.d.ts vendored
View file

@ -327,6 +327,7 @@ export type ConversationAttributesType = {
name?: string; name?: string;
systemGivenName?: string; systemGivenName?: string;
systemFamilyName?: string; systemFamilyName?: string;
systemNickname?: string;
needsStorageServiceSync?: boolean; needsStorageServiceSync?: boolean;
needsVerification?: boolean; needsVerification?: boolean;
profileSharing?: boolean; profileSharing?: boolean;

View file

@ -352,7 +352,8 @@ export class ConversationModel extends window.Backbone
this.on('newmessage', this.onNewMessage); this.on('newmessage', this.onNewMessage);
this.on('change:profileKey', this.onChangeProfileKey); this.on('change:profileKey', this.onChangeProfileKey);
this.on( this.on(
'change:name change:profileName change:profileFamilyName change:e164', 'change:name change:profileName change:profileFamilyName change:e164 ' +
'change:systemGivenName change:systemFamilyName change:systemNickname',
() => this.maybeClearUsername() () => this.maybeClearUsername()
); );
@ -1910,6 +1911,7 @@ export class ConversationModel extends window.Backbone
name: this.get('name'), name: this.get('name'),
systemGivenName: this.get('systemGivenName'), systemGivenName: this.get('systemGivenName'),
systemFamilyName: this.get('systemFamilyName'), systemFamilyName: this.get('systemFamilyName'),
systemNickname: this.get('systemNickname'),
phoneNumber: this.getNumber(), phoneNumber: this.getNumber(),
profileName: this.getProfileName(), profileName: this.getProfileName(),
profileSharing: this.get('profileSharing'), profileSharing: this.get('profileSharing'),

View file

@ -198,6 +198,10 @@ export async function toContactRecord(
if (systemFamilyName) { if (systemFamilyName) {
contactRecord.systemFamilyName = systemFamilyName; contactRecord.systemFamilyName = systemFamilyName;
} }
const systemNickname = conversation.get('systemNickname');
if (systemNickname) {
contactRecord.systemNickname = systemNickname;
}
contactRecord.blocked = conversation.isBlocked(); contactRecord.blocked = conversation.isBlocked();
contactRecord.whitelisted = Boolean(conversation.get('profileSharing')); contactRecord.whitelisted = Boolean(conversation.get('profileSharing'));
contactRecord.archived = Boolean(conversation.get('isArchived')); contactRecord.archived = Boolean(conversation.get('isArchived'));
@ -1033,6 +1037,7 @@ export async function mergeContactRecord(
conversation.set({ conversation.set({
systemGivenName: dropNull(contactRecord.systemGivenName), systemGivenName: dropNull(contactRecord.systemGivenName),
systemFamilyName: dropNull(contactRecord.systemFamilyName), systemFamilyName: dropNull(contactRecord.systemFamilyName),
systemNickname: dropNull(contactRecord.systemNickname),
}); });
// https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt#L921-L936 // https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt#L921-L936

View file

@ -193,6 +193,7 @@ export type ConversationType = ReadonlyDeep<
name?: string; name?: string;
systemGivenName?: string; systemGivenName?: string;
systemFamilyName?: string; systemFamilyName?: string;
systemNickname?: string;
familyName?: string; familyName?: string;
firstName?: string; firstName?: string;
profileName?: string; profileName?: string;

View file

@ -80,7 +80,9 @@ describe('pnp/username', function needsName() {
await bootstrap.teardown(); await bootstrap.teardown();
}); });
it('drops username when contact name becomes known', async () => { for (const type of ['profile', 'system']) {
// eslint-disable-next-line no-loop-func
it(`drops username when contact's ${type} name becomes known`, async () => {
const { phone } = bootstrap; const { phone } = bootstrap;
const window = await app.getWindow(); const window = await app.getWindow();
@ -93,11 +95,19 @@ describe('pnp/username', function needsName() {
) )
.waitFor(); .waitFor();
debug('adding profile key for username contact');
let state = await phone.expectStorageState('consistency check'); let state = await phone.expectStorageState('consistency check');
if (type === 'profile') {
debug('adding profile key for username contact');
state = state.updateContact(usernameContact, { state = state.updateContact(usernameContact, {
profileKey: usernameContact.profileKey.serialize(), profileKey: usernameContact.profileKey.serialize(),
}); });
} else {
debug('adding nickname for username contact');
state = state.updateContact(usernameContact, {
systemNickname: usernameContact.profileName,
});
}
await phone.setStorageState(state); await phone.setStorageState(state);
await phone.sendFetchStorage({ await phone.sendFetchStorage({
timestamp: bootstrap.getTimestamp(), timestamp: bootstrap.getTimestamp(),
@ -119,7 +129,11 @@ describe('pnp/username', function needsName() {
const { added, removed } = newState.diff(state); const { added, removed } = newState.diff(state);
assert.strictEqual(added.length, 1, 'only one record must be added'); assert.strictEqual(added.length, 1, 'only one record must be added');
assert.strictEqual(removed.length, 1, 'only one record must be removed'); assert.strictEqual(
removed.length,
1,
'only one record must be removed'
);
assert.strictEqual( assert.strictEqual(
added[0].contact?.serviceUuid, added[0].contact?.serviceUuid,
@ -134,6 +148,7 @@ describe('pnp/username', function needsName() {
assert.strictEqual(removed[0].contact?.username, USERNAME); assert.strictEqual(removed[0].contact?.username, USERNAME);
} }
}); });
}
it('reserves/confirms/deletes username', async () => { it('reserves/confirms/deletes username', async () => {
const { phone, server } = bootstrap; const { phone, server } = bootstrap;

View file

@ -49,7 +49,16 @@ export function getTitleNoDefault(
export function canHaveUsername( export function canHaveUsername(
attributes: Pick< attributes: Pick<
ConversationAttributesType, ConversationAttributesType,
'id' | 'type' | 'name' | 'profileName' | 'profileFamilyName' | 'e164' | 'id'
| 'type'
| 'name'
| 'profileName'
| 'profileFamilyName'
| 'e164'
| 'systemGivenName'
| 'systemFamilyName'
| 'systemNickname'
| 'type'
>, >,
ourConversationId: string | undefined ourConversationId: string | undefined
): boolean { ): boolean {
@ -84,13 +93,13 @@ export function getProfileName(
export function getSystemName( export function getSystemName(
attributes: Pick< attributes: Pick<
ConversationAttributesType, ConversationAttributesType,
'systemGivenName' | 'systemFamilyName' | 'type' 'systemGivenName' | 'systemFamilyName' | 'systemNickname' | 'type'
> >
): string | undefined { ): string | undefined {
if (isDirectConversation(attributes)) { if (isDirectConversation(attributes)) {
return combineNames( return (
attributes.systemGivenName, attributes.systemNickname ||
attributes.systemFamilyName combineNames(attributes.systemGivenName, attributes.systemFamilyName)
); );
} }

View file

@ -2170,10 +2170,10 @@
node-gyp-build "^4.2.3" node-gyp-build "^4.2.3"
uuid "^8.3.0" uuid "^8.3.0"
"@signalapp/mock-server@2.14.0": "@signalapp/mock-server@2.15.0":
version "2.14.0" version "2.15.0"
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.14.0.tgz#6309d944cf46e58f6141df45075de882d964ae0a" resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.15.0.tgz#de86ddc4c3f7cbe1e91941832c4b317946e90364"
integrity sha512-NSLnfjho4HCyrz4Y6cyoIK0f+iuhOrxEFmaabdVUepOaSHPZi1MTyYYo0d6NzD/PGREAQFJuzqNaE+7zhSiPEQ== integrity sha512-bxu4hpnEAAvDT7Yg2LZQNIL/9ciNrGG0hPJlj+dT2iwsHo2AAP8Ej4sLfAiy0O2kYbf2bKcvfTE9C+XwkdAW+w==
dependencies: dependencies:
"@signalapp/libsignal-client" "^0.22.0" "@signalapp/libsignal-client" "^0.22.0"
debug "^4.3.2" debug "^4.3.2"