From db463d3b63f88708f7b0758293c2482d13f8293e Mon Sep 17 00:00:00 2001 From: Michelle Linington Date: Wed, 22 Dec 2021 11:22:42 -0800 Subject: [PATCH 1/2] Fix for duplicate names Greyson reported an issue where his linked iPad was reporting a contact's name twice. --- SignalServiceKit/src/Contacts/SignalAccount.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalAccount.m b/SignalServiceKit/src/Contacts/SignalAccount.m index 8e3a66970d..67003c9eca 100644 --- a/SignalServiceKit/src/Contacts/SignalAccount.m +++ b/SignalServiceKit/src/Contacts/SignalAccount.m @@ -190,9 +190,9 @@ static NSString *kSignalPreferNicknamesPreference = @"NSPersonNameDefaultShouldP // try our best to create appropriate components to represent it. NSArray *components = [self.contactFullName componentsSeparatedByString:@" "]; - // If there are only two words separated by a space, this is probably a given - // and family name. - if (components.count <= 2) { + // If there are at least two words separated by a space, we can use the first and last as + // a given and family name. Otherwise, we'll use whatever we have as a given name. + if (components.count >= 2) { nameComponents.givenName = components.firstObject; nameComponents.familyName = components.lastObject; } else { From da55f1d8a3ec155adb0e79d36094facc70206c43 Mon Sep 17 00:00:00 2001 From: Michelle Linington Date: Wed, 22 Dec 2021 14:55:11 -0800 Subject: [PATCH 2/2] PR Feedback --- SignalServiceKit/src/Contacts/SignalAccount.m | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalAccount.m b/SignalServiceKit/src/Contacts/SignalAccount.m index 67003c9eca..2aa6a45c64 100644 --- a/SignalServiceKit/src/Contacts/SignalAccount.m +++ b/SignalServiceKit/src/Contacts/SignalAccount.m @@ -186,18 +186,10 @@ static NSString *kSignalPreferNicknamesPreference = @"NSPersonNameDefaultShouldP nameComponents.givenName = self.contactFirstName; nameComponents.familyName = self.contactLastName; } else if (self.contactFullName.length > 0) { - // If we don't have a first name or last name, but we *do* have a full name, - // try our best to create appropriate components to represent it. - NSArray *components = [self.contactFullName componentsSeparatedByString:@" "]; - - // If there are at least two words separated by a space, we can use the first and last as - // a given and family name. Otherwise, we'll use whatever we have as a given name. - if (components.count >= 2) { - nameComponents.givenName = components.firstObject; - nameComponents.familyName = components.lastObject; - } else { - nameComponents.givenName = self.contactFullName; - } + // Originally we had a heuristic to try and guess which was the given and family name. It + // wasn't always correct. We're probably better off just sticking the entire name in the + // given name. + nameComponents.givenName = self.contactFullName; } nameComponents.nickname = self.contactNicknameIfAvailable;