diff --git a/Mastodon/Diffable/Status/StatusSection.swift b/Mastodon/Diffable/Status/StatusSection.swift index d9c1b4725..12fce16d8 100644 --- a/Mastodon/Diffable/Status/StatusSection.swift +++ b/Mastodon/Diffable/Status/StatusSection.swift @@ -165,7 +165,7 @@ extension StatusSection { return } - cell.pollOptionView.configure(pollOption: option) + cell.pollOptionView.configure(pollOption: option, status: statusView.viewModel.originalStatus) // trigger update if needs let needsUpdatePoll: Bool = { diff --git a/Mastodon/Scene/Share/View/Content/PollOptionView+Configuration.swift b/Mastodon/Scene/Share/View/Content/PollOptionView+Configuration.swift index 631e5b337..c815190be 100644 --- a/Mastodon/Scene/Share/View/Content/PollOptionView+Configuration.swift +++ b/Mastodon/Scene/Share/View/Content/PollOptionView+Configuration.swift @@ -14,8 +14,8 @@ import MastodonUI import MastodonSDK extension PollOptionView { - public func configure(pollOption option: PollOption) { - guard let poll = option.poll, let status = poll.status else { + public func configure(pollOption option: PollOption, status: MastodonStatus?) { + guard let poll = option.poll else { assertionFailure("PollOption to be configured is expected to be part of Poll with Status") return } @@ -48,8 +48,8 @@ extension PollOptionView { viewModel.isMultiple = poll.multiple let optionIndex = option.index - let authorDomain = status.author.domain - let authorID = status.author.id + let authorDomain = status?.entity.account.domain ?? "" + let authorID = status?.entity.account.id ?? "" // isSelect, isPollVoted, isMyPoll Publishers.CombineLatest4( option.publisher(for: \.poll), diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HashtagTimeline.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HashtagTimeline.swift index 4edd34bf3..f1d7c0688 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HashtagTimeline.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HashtagTimeline.swift @@ -41,6 +41,20 @@ extension APIService { hashtag: hashtag, authorization: authorization ).singleOutput() + + #warning("TODO: Remove this with IOS-181, IOS-182") + let managedObjectContext = self.backgroundManagedObjectContext + try await managedObjectContext.performChanges { + let me = authenticationBox.authentication.user(in: managedObjectContext) + + for entity in response.value { + guard let poll = entity.poll else { continue } + _ = Persistence.Poll.createOrMerge( + in: managedObjectContext, + context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate) + ) + } + } return response } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift index 047fe1337..e6e3e9504 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+HomeTimeline.swift @@ -41,6 +41,20 @@ extension APIService { authorization: authorization ).singleOutput() + #warning("TODO: Remove this with IOS-181, IOS-182") + let managedObjectContext = self.backgroundManagedObjectContext + try await managedObjectContext.performChanges { + let me = authenticationBox.authentication.user(in: managedObjectContext) + + for entity in response.value { + guard let poll = entity.poll else { continue } + _ = Persistence.Poll.createOrMerge( + in: managedObjectContext, + context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate) + ) + } + } + // FIXME: This is a dirty hack to make the performance-stuff work. // Problem is, that we don't persist the user on disk anymore. So we have to fetch // it when we need it to display on the home timeline. diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+PublicTimeline.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+PublicTimeline.swift index 9617c5233..6fa686bf9 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+PublicTimeline.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+PublicTimeline.swift @@ -26,6 +26,20 @@ extension APIService { query: query, authorization: authorization ).singleOutput() + + #warning("TODO: Remove this with IOS-181, IOS-182") + let managedObjectContext = self.backgroundManagedObjectContext + try await managedObjectContext.performChanges { + let me = authenticationBox.authentication.user(in: managedObjectContext) + + for entity in response.value { + guard let poll = entity.poll else { continue } + _ = Persistence.Poll.createOrMerge( + in: managedObjectContext, + context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate) + ) + } + } return response } // end func diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status.swift index 22f4b0d81..a52d4506c 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status.swift @@ -26,6 +26,19 @@ extension APIService { statusID: statusID, authorization: authorization ).singleOutput() + + #warning("TODO: Remove this with IOS-181, IOS-182") + let managedObjectContext = self.backgroundManagedObjectContext + try await managedObjectContext.performChanges { + let me = authenticationBox.authentication.user(in: managedObjectContext) + + if let poll = response.value.poll { + _ = Persistence.Poll.createOrMerge( + in: managedObjectContext, + context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate) + ) + } + } return response }