mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-02-03 10:47:35 +01:00
Show profile on tap
Bridge account to user as long as Profile-screen doesn't work with Mastodon.Entity.Account, but MastodonUser
This commit is contained in:
parent
0951e658a2
commit
d15181dcb6
@ -8,6 +8,7 @@
|
||||
import UIKit
|
||||
import CoreDataStack
|
||||
import MastodonCore
|
||||
import MastodonSDK
|
||||
|
||||
extension DataSourceFacade {
|
||||
|
||||
@ -54,6 +55,30 @@ extension DataSourceFacade {
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func coordinateToProfileScene(
|
||||
provider: ViewControllerWithDependencies & AuthContextProvider,
|
||||
account: Mastodon.Entity.Account
|
||||
) async {
|
||||
provider.coordinator.showLoading()
|
||||
|
||||
guard let domain = account.domain else { return provider.coordinator.hideLoading() }
|
||||
|
||||
Task {
|
||||
do {
|
||||
let user = try await provider.context.apiService.fetchUser(username: account.username,
|
||||
domain: domain,
|
||||
authenticationBox: provider.authContext.mastodonAuthenticationBox)
|
||||
provider.coordinator.hideLoading()
|
||||
|
||||
if let user {
|
||||
await coordinateToProfileScene(provider: provider, user: user.asRecord)
|
||||
}
|
||||
} catch {
|
||||
provider.coordinator.hideLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DataSourceFacade {
|
||||
|
@ -17,7 +17,8 @@ extension DataSourceFacade {
|
||||
item: DataSourceItem
|
||||
) async {
|
||||
switch item {
|
||||
case .status:
|
||||
|
||||
case .status, .account(_, _):
|
||||
break // not create search history for status
|
||||
case .user(let record):
|
||||
let authenticationBox = provider.authContext.mastodonAuthenticationBox
|
||||
|
@ -21,6 +21,8 @@ extension UITableViewDelegate where Self: DataSourceProvider & AuthContextProvid
|
||||
return
|
||||
}
|
||||
switch item {
|
||||
case .account(let account, relationship: _):
|
||||
await DataSourceFacade.coordinateToProfileScene(provider: self, account: account)
|
||||
case .status(let status):
|
||||
await DataSourceFacade.coordinateToStatusThreadScene(
|
||||
provider: self,
|
||||
|
@ -16,6 +16,7 @@ enum DataSourceItem: Hashable {
|
||||
case user(record: ManagedObjectRecord<MastodonUser>)
|
||||
case hashtag(tag: TagKind)
|
||||
case notification(record: ManagedObjectRecord<Notification>)
|
||||
case account(account: Mastodon.Entity.Account, relationship: Mastodon.Entity.Relationship?)
|
||||
}
|
||||
|
||||
extension DataSourceItem {
|
||||
|
@ -20,6 +20,8 @@ extension FollowingListViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
switch item {
|
||||
case .account(let account, let relationship):
|
||||
return .account(account: account, relationship: relationship)
|
||||
case .user(let record):
|
||||
return .user(record: record)
|
||||
default:
|
||||
|
@ -52,6 +52,9 @@ extension SearchResultViewController {
|
||||
)
|
||||
|
||||
switch item {
|
||||
case .account(account: _, relationship: _):
|
||||
// do nothing
|
||||
break
|
||||
case .status(let status):
|
||||
await DataSourceFacade.coordinateToStatusThreadScene(
|
||||
provider: self,
|
||||
|
@ -91,11 +91,15 @@ extension Mastodon.Entity.Account {
|
||||
}
|
||||
return acct
|
||||
}
|
||||
}
|
||||
|
||||
extension Mastodon.Entity.Account {
|
||||
public var verifiedLink: Mastodon.Entity.Field? {
|
||||
let firstVerified = fields?.first(where: { $0.verifiedAt != nil })
|
||||
return firstVerified
|
||||
}
|
||||
|
||||
public var domain: String? {
|
||||
guard let components = URLComponents(string: url) else { return nil }
|
||||
|
||||
return components.host
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user