diff --git a/Package.swift b/Package.swift index 765baf34f12334b980d07658783cd9d1e1eeb914..bcec957c2be3321cb1b9f1bcc1dd176814764b54 100644 --- a/Package.swift +++ b/Package.swift @@ -224,6 +224,7 @@ let package = Package( "Shared", "Keychain", "InputField", + "Presentation", "DependencyInjection", .product( name: "Shout", diff --git a/Sources/SearchFeature/Controllers/SearchLeftController.swift b/Sources/SearchFeature/Controllers/SearchLeftController.swift index d305c6140292d3ec728224c60855b5b007b958e8..bbfabd2836990bb00c86e01a09527bdbac8b1145 100644 --- a/Sources/SearchFeature/Controllers/SearchLeftController.swift +++ b/Sources/SearchFeature/Controllers/SearchLeftController.swift @@ -54,20 +54,27 @@ final class SearchLeftController: UIViewController { let contact: Contact let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: AvatarCell.self) + let h1Text: String + var h2Text: String? + switch item { case .stranger(let stranger): contact = stranger - case .connection(let connection): - contact = connection - } + h1Text = stranger.username ?? "" - let h1Text: String - var h2Text: String? + if stranger.authStatus == .requested { + h2Text = "Request pending" + } else if stranger.authStatus == .requestFailed { + h2Text = "Request failed" + } - h1Text = (contact.nickname ?? contact.username) ?? "" + case .connection(let connection): + contact = connection + h1Text = (connection.nickname ?? contact.username) ?? "" - if let _ = contact.nickname, let username = contact.username { - h2Text = username + if connection.nickname != nil { + h2Text = contact.username ?? "" + } } cell.setup( diff --git a/Sources/SearchFeature/Utils/SearchDiffableDataSource.swift b/Sources/SearchFeature/Utils/SearchDiffableDataSource.swift index 4fef0dfacc14889b3074da1635bb119bde721a11..10d7bccc8c0f100b32cd34bf7a91312796ae9f15 100644 --- a/Sources/SearchFeature/Utils/SearchDiffableDataSource.swift +++ b/Sources/SearchFeature/Utils/SearchDiffableDataSource.swift @@ -17,7 +17,7 @@ class SearchDiffableDataSource: UITableViewDiffableDataSource<SearchSection, Sea case .stranger: return "" case .connections: - return "CONNECTIONS" + return "LOCAL RESULTS" } } } diff --git a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift index b6d8a5f1526531f34af8c227e0347e3e92af2db3..30f77b191cbd9115f856d6133a2df3b2fa01fb0b 100644 --- a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift +++ b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift @@ -110,21 +110,26 @@ final class SearchLeftViewModel { } } - private func appendToLocalSearch(_ contact: Contact?) { + private func appendToLocalSearch(_ user: Contact?) { var snapshot = SearchSnapshot() - if let contact = contact { - snapshot.appendSections([.stranger]) - snapshot.appendItems([.stranger(contact)], toSection: .stranger) + if var user = user { + if let contact = try? session.dbManager.fetchContacts(.init(id: [user.id])).first { + user.authStatus = contact.authStatus + } + + if user.authStatus != .friend { + snapshot.appendSections([.stranger]) + snapshot.appendItems([.stranger(user)], toSection: .stranger) + } } - let localsQuery = Contact.Query(text: stateSubject.value.input) + let localsQuery = Contact.Query(text: stateSubject.value.input, authStatus: [.friend]) if let locals = try? session.dbManager.fetchContacts(localsQuery), locals.count > 0 { - // TODO: Remove myself - // + let localsWithoutMe = locals.filter { $0.id != session.myId } snapshot.appendSections([.connections]) - snapshot.appendItems(locals.map(SearchItem.connection), toSection: .connections) + snapshot.appendItems(localsWithoutMe.map(SearchItem.connection), toSection: .connections) } stateSubject.value.snapshot = snapshot