diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Bookmark.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Bookmark.swift index 4f31c91bc..75953c17f 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Bookmark.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Bookmark.swift @@ -22,29 +22,16 @@ extension APIService { record: MastodonStatus, authenticationBox: MastodonAuthenticationBox ) async throws -> Mastodon.Response.Content { - - let managedObjectContext = backgroundManagedObjectContext // update bookmark state and retrieve bookmark context - let bookmarkContext: MastodonBookmarkContext = try await managedObjectContext.performChanges { - let authentication = authenticationBox.authentication - - guard - let me = authentication.user(in: managedObjectContext) - else { - throw APIError.implicit(.badRequest) - } - - let _status = record.entity - let status = _status.reblog ?? _status - let isBookmarked = status.bookmarked == true + let _status = record.entity + let status = _status.reblog ?? _status + let isBookmarked = status.bookmarked == true - let context = MastodonBookmarkContext( - statusID: status.id, - isBookmarked: isBookmarked - ) - return context - } + let bookmarkContext = MastodonBookmarkContext( + statusID: status.id, + isBookmarked: isBookmarked + ) // request bookmark or undo bookmark let result: Result, Error> diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Favorite.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Favorite.swift index a1e8371b6..182ffea6f 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Favorite.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Favorite.swift @@ -23,30 +23,17 @@ extension APIService { status: MastodonStatus, authenticationBox: MastodonAuthenticationBox ) async throws -> Mastodon.Response.Content { - - let managedObjectContext = backgroundManagedObjectContext // update like state and retrieve like context - let favoriteContext: MastodonFavoriteContext = try await managedObjectContext.performChanges { - let authentication = authenticationBox.authentication - - guard - let me = authentication.user(in: managedObjectContext) - else { - throw APIError.implicit(.badRequest) - } + let _status = status.reblog ?? status + let isFavorited = _status.entity.favourited == true + let favoritedCount = Int64(_status.entity.favouritesCount) - let _status = status.reblog ?? status - let isFavorited = _status.entity.favourited == true - let favoritedCount = Int64(_status.entity.favouritesCount) - - let context = MastodonFavoriteContext( - statusID: _status.id, - isFavorited: isFavorited, - favoritedCount: favoritedCount - ) - return context - } + let favoriteContext = MastodonFavoriteContext( + statusID: _status.id, + isFavorited: isFavorited, + favoritedCount: favoritedCount + ) // request like or undo like let result: Result, Error> diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Reblog.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Reblog.swift index eea8b7fbf..09ca59a16 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Reblog.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Reblog.swift @@ -23,30 +23,17 @@ extension APIService { status: MastodonStatus, authenticationBox: MastodonAuthenticationBox ) async throws -> Mastodon.Response.Content { - let managedObjectContext = backgroundManagedObjectContext - + // update repost state and retrieve repost context - let _reblogContext: MastodonReblogContext? = try await managedObjectContext.performChanges { - let authentication = authenticationBox.authentication - - guard - let me = authentication.user(in: managedObjectContext) - else { return nil } - - let _status = status.reblog ?? status - let isReblogged = _status.entity.reblogged == true - let rebloggedCount = Int64(_status.entity.reblogsCount) + let _status = status.reblog ?? status + let isReblogged = _status.entity.reblogged == true + let rebloggedCount = Int64(_status.entity.reblogsCount) - let reblogContext = MastodonReblogContext( - statusID: _status.id, - isReblogged: isReblogged, - rebloggedCount: rebloggedCount - ) - return reblogContext - } - guard let reblogContext = _reblogContext else { - throw APIError.implicit(.badRequest) - } + let reblogContext = MastodonReblogContext( + statusID: _status.id, + isReblogged: isReblogged, + rebloggedCount: rebloggedCount + ) // request repost or undo repost let result: Result, Error> @@ -86,7 +73,6 @@ extension APIService { authorization: authenticationBox.userAuthorization ).singleOutput() - #warning("Is this still required?") try await managedObjectContext.performChanges { for entity in response.value { _ = Persistence.MastodonUser.createOrMerge(