Implement alternative Author for DataSourceFacade.MenuContext (IOS-176)
This commit is contained in:
parent
80df919da1
commit
405b175bdf
|
@ -126,4 +126,13 @@ extension DataSourceFacade {
|
||||||
for: user,
|
for: user,
|
||||||
authenticationBox: dependency.authContext.mastodonAuthenticationBox)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,8 @@ extension DataSourceFacade {
|
||||||
extension DataSourceFacade {
|
extension DataSourceFacade {
|
||||||
|
|
||||||
struct MenuContext {
|
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 statusViewModel: StatusView.ViewModel?
|
||||||
let button: UIButton?
|
let button: UIButton?
|
||||||
let barButtonItem: UIBarButtonItem?
|
let barButtonItem: UIBarButtonItem?
|
||||||
|
|
|
@ -44,6 +44,7 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Aut
|
||||||
action: action,
|
action: action,
|
||||||
menuContext: .init(
|
menuContext: .init(
|
||||||
author: author,
|
author: author,
|
||||||
|
authorEntity: notification.entity.account,
|
||||||
statusViewModel: nil,
|
statusViewModel: nil,
|
||||||
button: button,
|
button: button,
|
||||||
barButtonItem: nil
|
barButtonItem: nil
|
||||||
|
|
|
@ -471,8 +471,10 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
||||||
assertionFailure("only works for status data provider")
|
assertionFailure("only works for status data provider")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let status = _status.reblog ?? _status
|
||||||
|
|
||||||
let _author: ManagedObjectRecord<MastodonUser>? = try await self.context.managedObjectContext.perform {
|
let _author: ManagedObjectRecord<MastodonUser>? = try await self.context.managedObjectContext.perform {
|
||||||
let status = _status.reblog ?? _status
|
|
||||||
let request = MastodonUser.sortedFetchRequest
|
let request = MastodonUser.sortedFetchRequest
|
||||||
request.predicate = MastodonUser.predicate(domain: self.authContext.mastodonAuthenticationBox.domain, id: status.entity.account.id)
|
request.predicate = MastodonUser.predicate(domain: self.authContext.mastodonAuthenticationBox.domain, id: status.entity.account.id)
|
||||||
request.fetchLimit = 1
|
request.fetchLimit = 1
|
||||||
|
@ -518,6 +520,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
||||||
action: action,
|
action: action,
|
||||||
menuContext: .init(
|
menuContext: .init(
|
||||||
author: author,
|
author: author,
|
||||||
|
authorEntity: status.entity.account,
|
||||||
statusViewModel: statusViewModel,
|
statusViewModel: statusViewModel,
|
||||||
button: button,
|
button: button,
|
||||||
barButtonItem: nil
|
barButtonItem: nil
|
||||||
|
|
|
@ -895,6 +895,7 @@ extension ProfileViewController: MastodonMenuDelegate {
|
||||||
action: action,
|
action: action,
|
||||||
menuContext: DataSourceFacade.MenuContext(
|
menuContext: DataSourceFacade.MenuContext(
|
||||||
author: userRecord,
|
author: userRecord,
|
||||||
|
authorEntity: nil,
|
||||||
statusViewModel: nil,
|
statusViewModel: nil,
|
||||||
button: nil,
|
button: nil,
|
||||||
barButtonItem: self.moreMenuBarButtonItem
|
barButtonItem: self.moreMenuBarButtonItem
|
||||||
|
|
|
@ -195,4 +195,38 @@ extension APIService {
|
||||||
|
|
||||||
return try result.get()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue