mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-02-03 02:37:37 +01:00
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()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user