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 UIKit
|
||||||
import CoreDataStack
|
import CoreDataStack
|
||||||
import MastodonCore
|
import MastodonCore
|
||||||
|
import MastodonSDK
|
||||||
|
|
||||||
extension DataSourceFacade {
|
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 {
|
extension DataSourceFacade {
|
||||||
|
@ -17,7 +17,8 @@ extension DataSourceFacade {
|
|||||||
item: DataSourceItem
|
item: DataSourceItem
|
||||||
) async {
|
) async {
|
||||||
switch item {
|
switch item {
|
||||||
case .status:
|
|
||||||
|
case .status, .account(_, _):
|
||||||
break // not create search history for status
|
break // not create search history for status
|
||||||
case .user(let record):
|
case .user(let record):
|
||||||
let authenticationBox = provider.authContext.mastodonAuthenticationBox
|
let authenticationBox = provider.authContext.mastodonAuthenticationBox
|
||||||
|
@ -21,6 +21,8 @@ extension UITableViewDelegate where Self: DataSourceProvider & AuthContextProvid
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch item {
|
switch item {
|
||||||
|
case .account(let account, relationship: _):
|
||||||
|
await DataSourceFacade.coordinateToProfileScene(provider: self, account: account)
|
||||||
case .status(let status):
|
case .status(let status):
|
||||||
await DataSourceFacade.coordinateToStatusThreadScene(
|
await DataSourceFacade.coordinateToStatusThreadScene(
|
||||||
provider: self,
|
provider: self,
|
||||||
|
@ -16,6 +16,7 @@ enum DataSourceItem: Hashable {
|
|||||||
case user(record: ManagedObjectRecord<MastodonUser>)
|
case user(record: ManagedObjectRecord<MastodonUser>)
|
||||||
case hashtag(tag: TagKind)
|
case hashtag(tag: TagKind)
|
||||||
case notification(record: ManagedObjectRecord<Notification>)
|
case notification(record: ManagedObjectRecord<Notification>)
|
||||||
|
case account(account: Mastodon.Entity.Account, relationship: Mastodon.Entity.Relationship?)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DataSourceItem {
|
extension DataSourceItem {
|
||||||
|
@ -20,6 +20,8 @@ extension FollowingListViewController: DataSourceProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch item {
|
switch item {
|
||||||
|
case .account(let account, let relationship):
|
||||||
|
return .account(account: account, relationship: relationship)
|
||||||
case .user(let record):
|
case .user(let record):
|
||||||
return .user(record: record)
|
return .user(record: record)
|
||||||
default:
|
default:
|
||||||
|
@ -52,6 +52,9 @@ extension SearchResultViewController {
|
|||||||
)
|
)
|
||||||
|
|
||||||
switch item {
|
switch item {
|
||||||
|
case .account(account: _, relationship: _):
|
||||||
|
// do nothing
|
||||||
|
break
|
||||||
case .status(let status):
|
case .status(let status):
|
||||||
await DataSourceFacade.coordinateToStatusThreadScene(
|
await DataSourceFacade.coordinateToStatusThreadScene(
|
||||||
provider: self,
|
provider: self,
|
||||||
|
@ -91,11 +91,15 @@ extension Mastodon.Entity.Account {
|
|||||||
}
|
}
|
||||||
return acct
|
return acct
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
extension Mastodon.Entity.Account {
|
|
||||||
public var verifiedLink: Mastodon.Entity.Field? {
|
public var verifiedLink: Mastodon.Entity.Field? {
|
||||||
let firstVerified = fields?.first(where: { $0.verifiedAt != nil })
|
let firstVerified = fields?.first(where: { $0.verifiedAt != nil })
|
||||||
return firstVerified
|
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