Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/Chats/Polls/Result/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 2 kB image not shown  

Quelle  ResultPollViewModel.swift   Sprache: JAVA

 

import SwiftUI
import ThreemaMacros

@MainActor
final class ResultPollViewModel: ObservableObject {
    
    // MARK: - State

    @Published var poll: Poll?
    @Published var isDeleted = false
    @Published var expandedStates: [NSManagedObjectID: Bool] = [:]
    
    // MARK: - Public properties
    
    let doneTitle = #localize("done")

    var navigationTitle: String {
        poll?.isClosed ?? false ? #localize("ballot_results") : #localize("ballot_intermediate_results")
    }
    
    var headerTitle: String {
        poll?.title ?? #localize("unknown")
    }
    
    var headerText: String? {
        guard let poll, !poll.isSummary else {
            return nil
        }
        
        return String(
            format: #localize("poll_participants_voted_count"),
            poll.voteCountInfo.countVotes,
            poll.voteCountInfo.countParticipants
        )
    }
    
    let choicesTitle = #localize("ballot_options")
    let noVotesTitle = #localize("poll_no_response")
    var pollVotesCount = #localize("poll_votes_count")
    
    // MARK: - Private properties
    
    private let pollID: NSManagedObjectID
    private var pollObserver: PollObserver?
    
    private lazy var entityManager = BusinessInjector.ui.entityManager
    private lazy var manager = BallotManager(entityManager: entityManager)
    
    // MARK: - Lifecycle
    
    init(pollID: NSManagedObjectID) {
        self.pollID = pollID
    }
    
    // MARK: - Public functions

    func load() {
        guard let entity = manager.getBallotEntity(for: pollID) else {
            return
        }
        
        poll = manager.getPoll(for: pollID)
        pollObserver = PollObserver(entity: entity, sortOrder: .votes)
        bind()
        expandMaxVotedChoices()
    }
    
    private func bind() {
        pollObserver?.onPollChange = { [weak self] updatedPoll in
            withAnimation {
                self?.poll = updatedPoll
            }
        }

        pollObserver?.onDeleted = { [weak self] in
            self?.isDeleted = true
        }
    }

    private func expandMaxVotedChoices() {
        guard let choices = poll?.choices, !choices.isEmpty else {
            return
        }

        let maxVotes = choices.map(\.votes).max() ?? 0
        for choice in choices where choice.votes == maxVotes && maxVotes > 0 {
            expandedStates[choice.id] = true
        }
    }
}

Messung
CHZG
879810095

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.