Add domain-block for MastodonUser (IOS-5)

This commit is contained in:
Nathan Mattes 2023-12-18 19:59:22 +01:00
parent 195029fc15
commit 910e101538
2 changed files with 37 additions and 1 deletions

View File

@ -52,4 +52,17 @@ extension DataSourceFacade {
)
dependency.context.authenticationService.fetchFollowingAndBlockedAsync()
}
static func responseToDomainBlockAction(
dependency: NeedsDependency & AuthContextProvider,
user: ManagedObjectRecord<MastodonUser>
) async throws {
let selectionFeedbackGenerator = await UISelectionFeedbackGenerator()
await selectionFeedbackGenerator.selectionChanged()
let apiService = dependency.context.apiService
let authBox = dependency.authContext.mastodonAuthenticationBox
_ = try await apiService.toggleDomainBlock(user: user, authenticationBox: authBox)
}
}

View File

@ -66,7 +66,30 @@ extension APIService {
}
.eraseToAnyPublisher()
}
public func toggleDomainBlock(
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Empty> {
guard let relationship = try await relationship(records: [user], authenticationBox: authenticationBox).value.first else {
throw APIError.implicit(.badRequest)
}
let response: Mastodon.Response.Content<Mastodon.Entity.Empty>
let domainBlocking = relationship.domainBlocking ?? false
let managedObjectContext = backgroundManagedObjectContext
guard let user = user.object(in: managedObjectContext) else { throw APIError.implicit(.badRequest) }
if domainBlocking {
response = try await unblockDomain(user: user, authorizationBox: authenticationBox).singleOutput()
} else {
response = try await blockDomain(user: user, authorizationBox: authenticationBox).singleOutput()
}
return response
}
func blockDomain(
user: MastodonUser,
authorizationBox: MastodonAuthenticationBox