Implement alternative Author for DataSourceFacade.MenuContext (IOS-176)

This commit is contained in:
Marcus Kida 2023-12-27 14:46:31 +01:00
parent 80df919da1
commit 405b175bdf
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
6 changed files with 51 additions and 2 deletions

View File

@ -126,4 +126,13 @@ extension DataSourceFacade {
for: user,
authenticationBox: dependency.authContext.mastodonAuthenticationBox)
}
static func responseToShowHideReblogAction(
dependency: NeedsDependency & AuthContextProvider,
user: Mastodon.Entity.Account
) async throws {
_ = try await dependency.context.apiService.toggleShowReblogs(
for: user,
authenticationBox: dependency.authContext.mastodonAuthenticationBox)
}
}

View File

@ -144,7 +144,8 @@ extension DataSourceFacade {
extension DataSourceFacade {
struct MenuContext {
let author: ManagedObjectRecord<MastodonUser>?
let author: ManagedObjectRecord<MastodonUser>? // todo: Remove once IOS-192 is ready
let authorEntity: Mastodon.Entity.Account?
let statusViewModel: StatusView.ViewModel?
let button: UIButton?
let barButtonItem: UIBarButtonItem?

View File

@ -44,6 +44,7 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Aut
action: action,
menuContext: .init(
author: author,
authorEntity: notification.entity.account,
statusViewModel: nil,
button: button,
barButtonItem: nil

View File

@ -471,8 +471,10 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
assertionFailure("only works for status data provider")
return
}
let status = _status.reblog ?? _status
let _author: ManagedObjectRecord<MastodonUser>? = try await self.context.managedObjectContext.perform {
let status = _status.reblog ?? _status
let request = MastodonUser.sortedFetchRequest
request.predicate = MastodonUser.predicate(domain: self.authContext.mastodonAuthenticationBox.domain, id: status.entity.account.id)
request.fetchLimit = 1
@ -518,6 +520,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
action: action,
menuContext: .init(
author: author,
authorEntity: status.entity.account,
statusViewModel: statusViewModel,
button: button,
barButtonItem: nil

View File

@ -895,6 +895,7 @@ extension ProfileViewController: MastodonMenuDelegate {
action: action,
menuContext: DataSourceFacade.MenuContext(
author: userRecord,
authorEntity: nil,
statusViewModel: nil,
button: nil,
barButtonItem: self.moreMenuBarButtonItem

View File

@ -195,4 +195,38 @@ extension APIService {
return try result.get()
}
public func toggleShowReblogs(
for user: Mastodon.Entity.Account,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let result: Result<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error>
let relationship = try await Mastodon.API.Account.relationships(
session: session,
domain: authenticationBox.domain,
query: .init(ids: [user.id]),
authorization: authenticationBox.userAuthorization
).singleOutput().value.first
let oldShowReblogs = relationship?.showingReblogs == true
let newShowReblogs = (oldShowReblogs == false)
do {
let response = try await Mastodon.API.Account.follow(
session: session,
domain: authenticationBox.domain,
accountID: user.id,
followQueryType: .follow(query: .init(reblogs: newShowReblogs)),
authorization: authenticationBox.userAuthorization
).singleOutput()
result = .success(response)
} catch {
result = .failure(error)
}
return try result.get()
}
}