fix: missing update the latest relationship into database after block/unblock action issue
This commit is contained in:
parent
4af2c0ca78
commit
d8be41fd33
|
@ -136,6 +136,7 @@ extension APIService {
|
||||||
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
||||||
let domain = mastodonAuthenticationBox.domain
|
let domain = mastodonAuthenticationBox.domain
|
||||||
let authorization = mastodonAuthenticationBox.userAuthorization
|
let authorization = mastodonAuthenticationBox.userAuthorization
|
||||||
|
let requestMastodonUserID = mastodonAuthenticationBox.userID
|
||||||
|
|
||||||
return Mastodon.API.Account.block(
|
return Mastodon.API.Account.block(
|
||||||
session: session,
|
session: session,
|
||||||
|
@ -144,11 +145,39 @@ extension APIService {
|
||||||
blockQueryType: blockQueryType,
|
blockQueryType: blockQueryType,
|
||||||
authorization: authorization
|
authorization: authorization
|
||||||
)
|
)
|
||||||
|
.flatMap { response -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> in
|
||||||
|
let managedObjectContext = self.backgroundManagedObjectContext
|
||||||
|
return managedObjectContext.performChanges {
|
||||||
|
let requestMastodonUserRequest = MastodonUser.sortedFetchRequest
|
||||||
|
requestMastodonUserRequest.predicate = MastodonUser.predicate(domain: domain, id: requestMastodonUserID)
|
||||||
|
requestMastodonUserRequest.fetchLimit = 1
|
||||||
|
guard let requestMastodonUser = managedObjectContext.safeFetch(requestMastodonUserRequest).first else { return }
|
||||||
|
|
||||||
|
let lookUpMastodonUserRequest = MastodonUser.sortedFetchRequest
|
||||||
|
lookUpMastodonUserRequest.predicate = MastodonUser.predicate(domain: domain, id: mastodonUserID)
|
||||||
|
lookUpMastodonUserRequest.fetchLimit = 1
|
||||||
|
let lookUpMastodonUser = managedObjectContext.safeFetch(lookUpMastodonUserRequest).first
|
||||||
|
|
||||||
|
if let lookUpMastodonUser = lookUpMastodonUser {
|
||||||
|
let entity = response.value
|
||||||
|
APIService.CoreData.update(user: lookUpMastodonUser, entity: entity, requestMastodonUser: requestMastodonUser, domain: domain, networkDate: response.networkDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.tryMap { result -> Mastodon.Response.Content<Mastodon.Entity.Relationship> in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
return response
|
||||||
|
case .failure(let error):
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
}
|
||||||
.handleEvents(receiveCompletion: { [weak self] completion in
|
.handleEvents(receiveCompletion: { [weak self] completion in
|
||||||
guard let _ = self else { return }
|
guard let _ = self else { return }
|
||||||
switch completion {
|
switch completion {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
// TODO: handle error
|
// TODO: handle error in banner
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: [Relationship] block update fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: [Relationship] block update fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
|
||||||
|
|
||||||
case .finished:
|
case .finished:
|
||||||
|
|
|
@ -196,11 +196,11 @@ extension APIService {
|
||||||
let lookUpMastodonUserRequest = MastodonUser.sortedFetchRequest
|
let lookUpMastodonUserRequest = MastodonUser.sortedFetchRequest
|
||||||
lookUpMastodonUserRequest.predicate = MastodonUser.predicate(domain: domain, id: mastodonUserID)
|
lookUpMastodonUserRequest.predicate = MastodonUser.predicate(domain: domain, id: mastodonUserID)
|
||||||
lookUpMastodonUserRequest.fetchLimit = 1
|
lookUpMastodonUserRequest.fetchLimit = 1
|
||||||
let lookUpMastodonuser = managedObjectContext.safeFetch(lookUpMastodonUserRequest).first
|
let lookUpMastodonUser = managedObjectContext.safeFetch(lookUpMastodonUserRequest).first
|
||||||
|
|
||||||
if let lookUpMastodonuser = lookUpMastodonuser {
|
if let lookUpMastodonUser = lookUpMastodonUser {
|
||||||
let entity = response.value
|
let entity = response.value
|
||||||
APIService.CoreData.update(user: lookUpMastodonuser, entity: entity, requestMastodonUser: requestMastodonUser, domain: domain, networkDate: response.networkDate)
|
APIService.CoreData.update(user: lookUpMastodonUser, entity: entity, requestMastodonUser: requestMastodonUser, domain: domain, networkDate: response.networkDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tryMap { result -> Mastodon.Response.Content<Mastodon.Entity.Relationship> in
|
.tryMap { result -> Mastodon.Response.Content<Mastodon.Entity.Relationship> in
|
||||||
|
|
Loading…
Reference in New Issue