Consider mastodon-domains for other instances and profiles (IOS-141)

This commit is contained in:
Nathan Mattes 2023-09-17 17:21:53 +02:00
parent 4378c1e971
commit cb4c5a938d
2 changed files with 15 additions and 3 deletions

View File

@ -17,7 +17,7 @@ enum SearchResultOverviewItem: Hashable {
enum DefaultSectionEntry: Hashable {
case posts(String)
case people(String)
case profile(String, String)
case profile(username: String, domain: String)
case openLink(String)
var title: String {

View File

@ -123,8 +123,20 @@ class SearchResultsOverviewTableViewController: UIViewController, NeedsDependenc
var snapshot = dataSource.snapshot()
snapshot.deleteItems(snapshot.itemIdentifiers(inSection: .default))
snapshot.appendItems([.default(.posts(searchText)),
.default(.people(searchText)),
.default(.profile(searchText, authContext.mastodonAuthenticationBox.domain))], toSection: .default)
.default(.people(searchText))], toSection: .default)
let components = searchText.split(separator: "@")
if components.count == 2 {
let username = String(components[0])
let domain = String(components[1])
if domain.split(separator: ".").count >= 2 {
snapshot.appendItems([.default(.profile(username: username, domain: domain))], toSection: .default)
} else {
snapshot.appendItems([.default(.profile(username: username, domain: authContext.mastodonAuthenticationBox.domain))], toSection: .default)
}
} else {
snapshot.appendItems([.default(.profile(username: searchText, domain: authContext.mastodonAuthenticationBox.domain))], toSection: .default)
}
if URL(string: searchText)?.isValidURL() ?? false {
snapshot.appendItems([.default(.openLink(searchText))], toSection: .default)