Fix bookmarked state (IOS-176)

This commit is contained in:
Marcus Kida 2023-11-28 11:13:13 +01:00
parent 45accb29e6
commit 7ad0b15b32
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
3 changed files with 18 additions and 4 deletions

View File

@ -13,15 +13,17 @@ import MastodonSDK
extension DataSourceFacade {
public static func responseToStatusBookmarkAction(
provider: UIViewController & NeedsDependency & AuthContextProvider,
provider: UIViewController & NeedsDependency & AuthContextProvider & DataSourceProvider,
status: MastodonStatus
) async throws {
let selectionFeedbackGenerator = await UISelectionFeedbackGenerator()
await selectionFeedbackGenerator.selectionChanged()
_ = try await provider.context.apiService.bookmark(
let updatedStatus = try await provider.context.apiService.bookmark(
record: status,
authenticationBox: provider.authContext.mastodonAuthenticationBox
)
).value
provider.update(status: .fromEntity(updatedStatus))
}
}

View File

@ -52,12 +52,14 @@ final public class FeedFetchedResultsController {
case .some(true):
newRecords[i] = .fromStatus({
let stat = MastodonStatus.fromEntity(records[i].status!.entity)
stat.isSensitiveToggled = status.isSensitiveToggled
stat.reblog = .fromEntity(status.entity)
return stat
}(), kind: record.kind)
case .some(false), .none:
newRecords[i] = .fromStatus({
let stat = MastodonStatus.fromEntity(status.entity)
stat.isSensitiveToggled = status.isSensitiveToggled
return stat
}(), kind: record.kind)
}

View File

@ -27,7 +27,16 @@ extension StatusView {
public var context: AppContext?
public var authContext: AuthContext?
public var originalStatus: MastodonStatus?
public var originalStatus: MastodonStatus? {
didSet {
originalStatus?.$entity
.receive(on: DispatchQueue.main)
.sink(receiveValue: { status in
self.isBookmark = status.bookmarked == true
})
.store(in: &disposeBag)
}
}
// Header
@Published public var header: Header = .none
@ -148,6 +157,7 @@ extension StatusView {
isMediaSensitive = false
isSensitiveToggled = false
isCurrentlyTranslating = false
isBookmark = false
translation = nil
activeFilters = []