diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift index 161e52e87..219e7ddef 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift @@ -127,227 +127,6 @@ extension DataSourceFacade { let barButtonItem: UIBarButtonItem? } -// @MainActor -// static func createProfileActionMenu( -// dependency: NeedsDependency, -// user: ManagedObjectRecord -// ) -> UIMenu { -// var children: [UIMenuElement] = [] -// let name = mastodonUser.displayNameWithFallback -// -// if let shareUser = shareUser { -// let shareAction = UIAction( -// title: L10n.Common.Controls.Actions.shareUser(name), -// image: UIImage(systemName: "square.and.arrow.up"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [], -// state: .off -// ) { [weak provider, weak sourceView, weak barButtonItem] _ in -// guard let provider = provider else { return } -// let activityViewController = createActivityViewControllerForMastodonUser(mastodonUser: shareUser, dependency: provider) -// provider.coordinator.present( -// scene: .activityViewController( -// activityViewController: activityViewController, -// sourceView: sourceView, -// barButtonItem: barButtonItem -// ), -// from: provider, -// transition: .activityViewControllerPresent(animated: true, completion: nil) -// ) -// } -// children.append(shareAction) -// } -// -// if let shareStatus = shareStatus { -// let shareAction = UIAction( -// title: L10n.Common.Controls.Actions.sharePost, -// image: UIImage(systemName: "square.and.arrow.up"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [], -// state: .off -// ) { [weak provider, weak sourceView, weak barButtonItem] _ in -// guard let provider = provider else { return } -// let activityViewController = createActivityViewControllerForMastodonUser(status: shareStatus, dependency: provider) -// provider.coordinator.present( -// scene: .activityViewController( -// activityViewController: activityViewController, -// sourceView: sourceView, -// barButtonItem: barButtonItem -// ), -// from: provider, -// transition: .activityViewControllerPresent(animated: true, completion: nil) -// ) -// } -// children.append(shareAction) -// } -// -// if !isMyself { -// // mute -// let muteAction = UIAction( -// title: isMuting ? L10n.Common.Controls.Friendship.unmuteUser(name) : L10n.Common.Controls.Friendship.mute, -// image: isMuting ? UIImage(systemName: "speaker") : UIImage(systemName: "speaker.slash"), -// discoverabilityTitle: isMuting ? nil : L10n.Common.Controls.Friendship.muteUser(name), -// attributes: isMuting ? [] : .destructive, -// state: .off -// ) { [weak provider, weak cell] _ in -// guard let provider = provider else { return } -// -// UserProviderFacade.toggleUserMuteRelationship( -// provider: provider, -// cell: cell -// ) -// .sink { _ in -// // do nothing -// } receiveValue: { _ in -// // do nothing -// } -// .store(in: &provider.context.disposeBag) -// } -// if isMuting { -// children.append(muteAction) -// } else { -// let muteMenu = UIMenu(title: L10n.Common.Controls.Friendship.muteUser(name), image: UIImage(systemName: "speaker.slash"), options: [], children: [muteAction]) -// children.append(muteMenu) -// } -// } -// -// if !isMyself { -// // block -// let blockAction = UIAction( -// title: isBlocking ? L10n.Common.Controls.Friendship.unblockUser(name) : L10n.Common.Controls.Friendship.block, -// image: isBlocking ? UIImage(systemName: "hand.raised.slash") : UIImage(systemName: "hand.raised"), -// discoverabilityTitle: isBlocking ? nil : L10n.Common.Controls.Friendship.blockUser(name), -// attributes: isBlocking ? [] : .destructive, -// state: .off -// ) { [weak provider, weak cell] _ in -// guard let provider = provider else { return } -// -// UserProviderFacade.toggleUserBlockRelationship( -// provider: provider, -// cell: cell -// ) -// .sink { _ in -// // do nothing -// } receiveValue: { _ in -// // do nothing -// } -// .store(in: &provider.context.disposeBag) -// } -// if isBlocking { -// children.append(blockAction) -// } else { -// let blockMenu = UIMenu(title: L10n.Common.Controls.Friendship.blockUser(name), image: UIImage(systemName: "hand.raised"), options: [], children: [blockAction]) -// children.append(blockMenu) -// } -// } -// -// if !isMyself { -// let reportAction = UIAction( -// title: L10n.Common.Controls.Actions.reportUser(name), -// image: UIImage(systemName: "flag"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [], -// state: .off -// ) { [weak provider] _ in -// guard let provider = provider else { return } -// guard let authenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { -// return -// } -// let viewModel = ReportViewModel( -// context: provider.context, -// domain: authenticationBox.domain, -// user: mastodonUser, -// status: nil -// ) -// provider.coordinator.present( -// scene: .report(viewModel: viewModel), -// from: provider, -// transition: .modal(animated: true, completion: nil) -// ) -// } -// children.append(reportAction) -// } -// -// if !isInSameDomain { -// if isDomainBlocking { -// let unblockDomainAction = UIAction( -// title: L10n.Common.Controls.Actions.unblockDomain(mastodonUser.domainFromAcct), -// image: UIImage(systemName: "nosign"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [], -// state: .off -// ) { [weak provider, weak cell] _ in -// guard let provider = provider else { return } -// provider.context.blockDomainService.unblockDomain(userProvider: provider, cell: cell) -// } -// children.append(unblockDomainAction) -// } else { -// let blockDomainAction = UIAction( -// title: L10n.Common.Controls.Actions.blockDomain(mastodonUser.domainFromAcct), -// image: UIImage(systemName: "nosign"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [], -// state: .off -// ) { [weak provider, weak cell] _ in -// guard let provider = provider else { return } -// -// let alertController = UIAlertController(title: L10n.Common.Alerts.BlockDomain.title(mastodonUser.domainFromAcct), message: nil, preferredStyle: .alert) -// let cancelAction = UIAlertAction(title: L10n.Common.Controls.Actions.cancel, style: .default) { _ in } -// alertController.addAction(cancelAction) -// let blockDomainAction = UIAlertAction(title: L10n.Common.Alerts.BlockDomain.blockEntireDomain, style: .destructive) { [weak provider, weak cell] _ in -// guard let provider = provider else { return } -// provider.context.blockDomainService.blockDomain(userProvider: provider, cell: cell) -// } -// alertController.addAction(blockDomainAction) -// provider.present(alertController, animated: true, completion: nil) -// } -// children.append(blockDomainAction) -// } -// } -// -// if let status = shareStatus, isMyself { -// let deleteAction = UIAction( -// title: L10n.Common.Controls.Actions.delete, -// image: UIImage(systemName: "delete.left"), -// identifier: nil, -// discoverabilityTitle: nil, -// attributes: [.destructive], -// state: .off -// ) { [weak provider] _ in -// guard let provider = provider else { return } -// -// let alertController = UIAlertController(title: L10n.Common.Alerts.DeletePost.title, message: nil, preferredStyle: .alert) -// let cancelAction = UIAlertAction(title: L10n.Common.Controls.Actions.cancel, style: .default) { _ in } -// alertController.addAction(cancelAction) -// let deleteAction = UIAlertAction(title: L10n.Common.Alerts.DeletePost.delete, style: .destructive) { [weak provider] _ in -// guard let provider = provider else { return } -// guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { return } -// provider.context.apiService.deleteStatus( -// domain: activeMastodonAuthenticationBox.domain, -// statusID: status.id, -// authorizationBox: activeMastodonAuthenticationBox -// ) -// .sink { _ in -// // do nothing -// } receiveValue: { _ in -// // do nothing -// } -// .store(in: &provider.context.disposeBag) -// } -// alertController.addAction(deleteAction) -// provider.present(alertController, animated: true, completion: nil) -// } -// children.append(deleteAction) -// } -// -// return UIMenu(title: "", options: [], children: children) -// } - static func createActivityViewController( dependency: NeedsDependency, user: ManagedObjectRecord diff --git a/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift b/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift index 229a5296f..ccfd4fc73 100644 --- a/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift @@ -195,7 +195,7 @@ class SearchResultsOverviewTableViewController: UIViewController, NeedsDependenc ) await DataSourceFacade.responseToCreateSearchHistory(provider: self, - item: .hashtag(tag: .entity(tag))) + item: .hashtag(tag: .entity(tag))) } } @@ -219,7 +219,7 @@ class SearchResultsOverviewTableViewController: UIViewController, NeedsDependenc user: user.asRecord) await DataSourceFacade.responseToCreateSearchHistory(provider: self, - item: .user(record: user.asRecord)) + item: .user(record: user.asRecord)) } } } @@ -237,6 +237,33 @@ class SearchResultsOverviewTableViewController: UIViewController, NeedsDependenc coordinator.present(scene: .searchResult(viewModel: searchResultViewModel), transition: .show) } + + func searchForPerson(username: String, domain: String) { + let acct = "\(username)@\(domain)" + let query = Mastodon.API.V2.Search.Query( + q: acct, + type: .default, + resolve: true + ) + + Task { + let searchResult = try await context.apiService.search( + query: query, + authenticationBox: authContext.mastodonAuthenticationBox + ).value + + if let account = searchResult.accounts.first(where: { $0.acctWithDomainIfMissing(domain).lowercased() == acct.lowercased() }) { + showProfile(for: account) + } else { + await MainActor.run { + let alertController = UIAlertController(title: "No User Account", message: "There's no Useraccount \"\(username)\" on \(domain)", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default) + alertController.addAction(okAction) + coordinator.present(scene: .alertController(alertController: alertController), transition: .alertController(animated: true)) + } + } + } + } } //MARK: UITableViewDelegate @@ -255,8 +282,8 @@ extension SearchResultsOverviewTableViewController: UITableViewDelegate { searchForPosts(withSearchText: searchText) case .people(let searchText): searchForPeople(withName: searchText) - case .profile(let profile, let instanceName): - delegate?.showProfile(self) + case .profile(let username, let domain): + searchForPerson(username: username, domain: domain) case .openLink(let string): delegate?.openLink(self) }