From fc3a534496dd4245df305080f1041f216be73453 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Sat, 13 Dec 2025 05:26:32 +0300 Subject: [PATCH] fix contact add and contact edit --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 18 ++++++++++++++++++ yobble/Views/Contacts/ContactAddView.swift | 13 +++++++++++-- yobble/Views/Contacts/ContactEditView.swift | 13 +++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 981c53c..bf3dddc 100644 --- a/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,4 +3,22 @@ uuid = "AEE1609A-17B4-4FCC-80A6-0D556940F4D7" type = "1" version = "2.0"> + + + + + + diff --git a/yobble/Views/Contacts/ContactAddView.swift b/yobble/Views/Contacts/ContactAddView.swift index 7fb12b4..988fbe9 100644 --- a/yobble/Views/Contacts/ContactAddView.swift +++ b/yobble/Views/Contacts/ContactAddView.swift @@ -97,8 +97,8 @@ struct ContactAddView: View { private var avatarInitial: String { let trimmedName = displayName.trimmedNonEmpty ?? contact.preferredName - if let first = trimmedName.trimmingCharacters(in: .whitespacesAndNewlines).first { - return String(first).uppercased() + if let initials = initials(from: trimmedName) { + return initials } if let login = contact.login?.trimmingCharacters(in: .whitespacesAndNewlines), !login.isEmpty { return String(login.prefix(1)).uppercased() @@ -185,3 +185,12 @@ private extension String { return value.isEmpty ? nil : value } } + +private func initials(from text: String) -> String? { + let components = text + .split { $0.isWhitespace } + .filter { !$0.isEmpty } + let letters = components.prefix(2).compactMap { $0.first } + guard !letters.isEmpty else { return nil } + return letters.map { String($0).uppercased() }.joined() +} diff --git a/yobble/Views/Contacts/ContactEditView.swift b/yobble/Views/Contacts/ContactEditView.swift index e7d8178..9c2a058 100644 --- a/yobble/Views/Contacts/ContactEditView.swift +++ b/yobble/Views/Contacts/ContactEditView.swift @@ -203,8 +203,8 @@ struct ContactEditView: View { private var avatarInitial: String { let trimmedName = displayName.trimmedNonEmpty ?? contact.preferredName - if let first = trimmedName.trimmingCharacters(in: .whitespacesAndNewlines).first { - return String(first).uppercased() + if let initials = initials(from: trimmedName) { + return initials } if let login = contact.login?.trimmingCharacters(in: .whitespacesAndNewlines), !login.isEmpty { return String(login.prefix(1)).uppercased() @@ -336,3 +336,12 @@ private extension String { return value.isEmpty ? nil : value } } + +private func initials(from text: String) -> String? { + let components = text + .split { $0.isWhitespace } + .filter { !$0.isEmpty } + let letters = components.prefix(2).compactMap { $0.first } + guard !letters.isEmpty else { return nil } + return letters.map { String($0).uppercased() }.joined() +}