fix: the Core Data thread-safe issue
This commit is contained in:
parent
ee5e2bde1f
commit
9768721247
@ -28,6 +28,7 @@ extension APIService {
|
|||||||
)
|
)
|
||||||
.flatMap { response -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Notification]>, Error> in
|
.flatMap { response -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Notification]>, Error> in
|
||||||
let log = OSLog.api
|
let log = OSLog.api
|
||||||
|
return self.backgroundManagedObjectContext.performChanges {
|
||||||
if query.maxID == nil {
|
if query.maxID == nil {
|
||||||
let requestMastodonNotificationRequest = MastodonNotification.sortedFetchRequest
|
let requestMastodonNotificationRequest = MastodonNotification.sortedFetchRequest
|
||||||
requestMastodonNotificationRequest.predicate = MastodonNotification.predicate(domain: domain, userID: userID)
|
requestMastodonNotificationRequest.predicate = MastodonNotification.predicate(domain: domain, userID: userID)
|
||||||
@ -36,7 +37,6 @@ extension APIService {
|
|||||||
self.backgroundManagedObjectContext.delete(notification)
|
self.backgroundManagedObjectContext.delete(notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self.backgroundManagedObjectContext.performChanges {
|
|
||||||
response.value.forEach { notification in
|
response.value.forEach { notification in
|
||||||
let (mastodonUser, _) = APIService.CoreData.createOrMergeMastodonUser(into: self.backgroundManagedObjectContext, for: nil, in: domain, entity: notification.account, userCache: nil, networkDate: Date(), log: log)
|
let (mastodonUser, _) = APIService.CoreData.createOrMergeMastodonUser(into: self.backgroundManagedObjectContext, for: nil, in: domain, entity: notification.account, userCache: nil, networkDate: Date(), log: log)
|
||||||
var status: Status?
|
var status: Status?
|
||||||
|
@ -11,13 +11,13 @@ import Combine
|
|||||||
// MARK: - Account credentials
|
// MARK: - Account credentials
|
||||||
extension Mastodon.API.Account {
|
extension Mastodon.API.Account {
|
||||||
|
|
||||||
static func acceptFollowRequestEndpointURL(domain: String, userID: String) -> URL {
|
static func acceptFollowRequestEndpointURL(domain: String, userID: Mastodon.Entity.Account.ID) -> URL {
|
||||||
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests")
|
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests")
|
||||||
.appendingPathComponent(userID)
|
.appendingPathComponent(userID)
|
||||||
.appendingPathComponent("authorize")
|
.appendingPathComponent("authorize")
|
||||||
}
|
}
|
||||||
|
|
||||||
static func rejectFollowRequestEndpointURL(domain: String, userID: String) -> URL {
|
static func rejectFollowRequestEndpointURL(domain: String, userID: Mastodon.Entity.Account.ID) -> URL {
|
||||||
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests")
|
return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests")
|
||||||
.appendingPathComponent(userID)
|
.appendingPathComponent(userID)
|
||||||
.appendingPathComponent("reject")
|
.appendingPathComponent("reject")
|
||||||
@ -34,12 +34,12 @@ extension Mastodon.API.Account {
|
|||||||
/// - session: `URLSession`
|
/// - session: `URLSession`
|
||||||
/// - domain: Mastodon instance domain. e.g. "example.com"
|
/// - domain: Mastodon instance domain. e.g. "example.com"
|
||||||
/// - userID: ID of the account in the database
|
/// - userID: ID of the account in the database
|
||||||
/// - authorization: App token
|
/// - authorization: User token
|
||||||
/// - Returns: `AnyPublisher` contains `Relationship` nested in the response
|
/// - Returns: `AnyPublisher` contains `Relationship` nested in the response
|
||||||
public static func acceptFollowRequest(
|
public static func acceptFollowRequest(
|
||||||
session: URLSession,
|
session: URLSession,
|
||||||
domain: String,
|
domain: String,
|
||||||
userID: String,
|
userID: Mastodon.Entity.Account.ID,
|
||||||
authorization: Mastodon.API.OAuth.Authorization
|
authorization: Mastodon.API.OAuth.Authorization
|
||||||
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
||||||
let request = Mastodon.API.post(
|
let request = Mastodon.API.post(
|
||||||
@ -66,12 +66,12 @@ extension Mastodon.API.Account {
|
|||||||
/// - session: `URLSession`
|
/// - session: `URLSession`
|
||||||
/// - domain: Mastodon instance domain. e.g. "example.com"
|
/// - domain: Mastodon instance domain. e.g. "example.com"
|
||||||
/// - userID: ID of the account in the database
|
/// - userID: ID of the account in the database
|
||||||
/// - authorization: App token
|
/// - authorization: User token
|
||||||
/// - Returns: `AnyPublisher` contains `Relationship` nested in the response
|
/// - Returns: `AnyPublisher` contains `Relationship` nested in the response
|
||||||
public static func rejectFollowRequest(
|
public static func rejectFollowRequest(
|
||||||
session: URLSession,
|
session: URLSession,
|
||||||
domain: String,
|
domain: String,
|
||||||
userID: String,
|
userID: Mastodon.Entity.Account.ID,
|
||||||
authorization: Mastodon.API.OAuth.Authorization
|
authorization: Mastodon.API.OAuth.Authorization
|
||||||
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
|
||||||
let request = Mastodon.API.post(
|
let request = Mastodon.API.post(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user