Stabilize beta release with warning cleanup and edge-case fixes
This commit is contained in:
@@ -19,6 +19,7 @@ final class PollDetailViewModel {
|
||||
var error: PollError?
|
||||
|
||||
private let pollService = PollService.shared
|
||||
private var subscribedPollId: UUID?
|
||||
|
||||
var results: PollResults? {
|
||||
guard let poll else { return nil }
|
||||
@@ -65,7 +66,7 @@ final class PollDetailViewModel {
|
||||
self.myVote = fetchedMyVote
|
||||
|
||||
// Subscribe to vote updates
|
||||
try? await pollService.subscribeToVoteUpdates(forPollId: pollId)
|
||||
await subscribeToVoteUpdates(for: pollId)
|
||||
} catch let pollError as PollError {
|
||||
error = pollError
|
||||
} catch {
|
||||
@@ -92,7 +93,7 @@ final class PollDetailViewModel {
|
||||
self.myVote = fetchedMyVote
|
||||
|
||||
// Subscribe to vote updates
|
||||
try? await pollService.subscribeToVoteUpdates(forPollId: fetchedPoll.id)
|
||||
await subscribeToVoteUpdates(for: fetchedPoll.id)
|
||||
} catch let pollError as PollError {
|
||||
error = pollError
|
||||
} catch {
|
||||
@@ -119,7 +120,7 @@ final class PollDetailViewModel {
|
||||
self.myVote = fetchedMyVote
|
||||
|
||||
// Subscribe to vote updates
|
||||
try? await pollService.subscribeToVoteUpdates(forPollId: existingPoll.id)
|
||||
await subscribeToVoteUpdates(for: existingPoll.id)
|
||||
} catch {
|
||||
// Votes fetch failed, but we have the poll - non-critical error
|
||||
self.votes = []
|
||||
@@ -155,7 +156,8 @@ final class PollDetailViewModel {
|
||||
|
||||
do {
|
||||
try await pollService.deletePoll(poll.id)
|
||||
try? await pollService.unsubscribeFromVoteUpdates()
|
||||
try? await pollService.unsubscribeFromVoteUpdates(forPollId: poll.id)
|
||||
subscribedPollId = nil
|
||||
self.poll = nil
|
||||
return true
|
||||
} catch let pollError as PollError {
|
||||
@@ -169,6 +171,17 @@ final class PollDetailViewModel {
|
||||
}
|
||||
|
||||
func cleanup() async {
|
||||
try? await pollService.unsubscribeFromVoteUpdates()
|
||||
guard let subscribedPollId else { return }
|
||||
try? await pollService.unsubscribeFromVoteUpdates(forPollId: subscribedPollId)
|
||||
self.subscribedPollId = nil
|
||||
}
|
||||
|
||||
private func subscribeToVoteUpdates(for pollId: UUID) async {
|
||||
if let existingPollId = subscribedPollId, existingPollId != pollId {
|
||||
try? await pollService.unsubscribeFromVoteUpdates(forPollId: existingPollId)
|
||||
}
|
||||
|
||||
try? await pollService.subscribeToVoteUpdates(forPollId: pollId)
|
||||
subscribedPollId = pollId
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user