Add domain-block for MastodonUser (IOS-5)
This commit is contained in:
parent
195029fc15
commit
910e101538
|
@ -52,4 +52,17 @@ extension DataSourceFacade {
|
||||||
)
|
)
|
||||||
dependency.context.authenticationService.fetchFollowingAndBlockedAsync()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,30 @@ extension APIService {
|
||||||
}
|
}
|
||||||
.eraseToAnyPublisher()
|
.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(
|
func blockDomain(
|
||||||
user: MastodonUser,
|
user: MastodonUser,
|
||||||
authorizationBox: MastodonAuthenticationBox
|
authorizationBox: MastodonAuthenticationBox
|
||||||
|
|
Loading…
Reference in New Issue