Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Notifications/BadgeCountFetcher.swift
1 views
//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//

public struct BadgeCount {
    public let unreadChatCount: UInt
    public let unreadCallsCount: UInt

    public var unreadTotalCount: UInt {
        unreadChatCount + unreadCallsCount
    }
}

public protocol BadgeCountFetcher {
    func fetchBadgeCount(tx: DBReadTransaction) -> BadgeCount
}

class BadgeCountFetcherImpl: BadgeCountFetcher {
    func fetchBadgeCount(tx: DBReadTransaction) -> BadgeCount {
        let unreadInteractionCount = InteractionFinder.unreadCountInAllThreads(transaction: tx)
        let unreadMissedCallCount = DependenciesBridge.shared.callRecordMissedCallManager.countUnreadMissedCalls(tx: tx)

        return BadgeCount(
            unreadChatCount: unreadInteractionCount,
            unreadCallsCount: unreadMissedCallCount,
        )
    }
}