Fix Polls not showing up (IOS-213)

This commit is contained in:
Marcus Kida 2023-12-14 16:33:50 +01:00
parent d759a4b69a
commit 22324f4c1e
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
6 changed files with 60 additions and 5 deletions

View File

@ -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 = {

View File

@ -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),

View File

@ -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
}

View File

@ -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.

View File

@ -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

View File

@ -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
}