@@ -7,17 +7,6 @@ import GRDB
77import LibSignalClient
88import SignalCoreKit
99
10- /// We need to query the system preferences to achieve the behaviour at Messages on iOS.
11- ///
12- /// If we ask NSPersonNameComponentsFormatter for "short" we will get the nickname if it
13- /// exists but if it _doesn't_ exit we'll just get the first name. (Or the name pattern
14- /// the user has selected in their system preferences. This means that in the conversation
15- /// list in the left, where Messages displays the full name of a contact if they don't
16- /// have a nickname, we'd just display the Short Name. To match the behaviour we ask
17- /// UserDefaults for the value of this key and prefer to use the nickname, if available,
18- /// in the conversation list.
19- private let kSignalPreferNicknamesPreference = " NSPersonNameDefaultShouldPreferNicknamesPreference "
20-
2110@objc ( SignalAccount)
2211public final class SignalAccount : NSObject , SDSCodableModel , Decodable {
2312 public static let databaseTableName = " model_SignalAccount "
@@ -271,11 +260,16 @@ extension SignalAccount {
271260 return components
272261 }
273262
274- /// Whether nicknames should be used.
275- ///
276- /// - SeeAlso: docs on``kSignalPreferNicknamesPreference``.
277- public static func shouldUseNicknames( userDefaults: UserDefaults = . standard) -> Bool {
278- userDefaults. bool ( forKey: kSignalPreferNicknamesPreference)
263+ /// If we ask PersonNameComponentsFormatter for `.short`, we will get the
264+ /// nickname (if it exists). To match the system behavior for the chat list,
265+ /// we use the nickname in lieu of the full name as well.
266+ public static func shouldUseNicknames( ) -> Bool {
267+ var nameComponents = PersonNameComponents ( )
268+ nameComponents. givenName = " givenName "
269+ nameComponents. nickname = " nickname "
270+ let nameFormatter = PersonNameComponentsFormatter ( )
271+ nameFormatter. style = . short
272+ return nameFormatter. string ( from: nameComponents) == " nickname "
279273 }
280274}
281275
0 commit comments