Files
iOS/Sources/App/TestFlightCommunication/TestFlightCommunicationEngine.swift
Bruno Pantaleão Gonçalves 62f1a86adf Add TestFlight communication screen when app opens (#4711)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
<img width="1206" height="2622" alt="Simulator Screenshot - Daily tester
2 - 2026-06-08 at 11 49 31"
src="https://github.com/user-attachments/assets/f4e5e291-2377-46d5-8ac5-bc0c6279bba7"
/>

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2026-06-08 13:22:57 +02:00

43 lines
1.7 KiB
Swift

import Shared
final class TestFlightCommunicationEngine {
private let messages: [TestFlightMessage]
private let isTestFlight: () -> Bool
private let currentPlatform: () -> WhatsNewTargetPlatform
private let hasSeenMessage: (String) -> Bool
init(
messages: [TestFlightMessage] = TestFlightCommunicationCatalog.messages,
isTestFlight: @escaping () -> Bool = { Current.isTestFlight },
currentPlatform: @escaping () -> WhatsNewTargetPlatform = { .current },
hasSeenMessage: @escaping (String) -> Bool = {
Current.settingsStore.hasSeenTestFlightMessage(messageID: $0)
}
) {
self.messages = messages
self.isTestFlight = isTestFlight
self.currentPlatform = currentPlatform
self.hasSeenMessage = hasSeenMessage
}
/// Returns the first unseen message targeting the current platform, or nil if the user is not on TestFlight.
func messageToShow() -> TestFlightMessage? {
guard isTestFlight() else { return nil }
let platform = currentPlatform()
return messages.first(where: {
$0.targetPlatforms.contains(platform) && !hasSeenMessage($0.id.rawValue)
})
}
/// Returns the latest message for the current platform regardless of seen state, or nil if not on TestFlight.
func latestMessage() -> TestFlightMessage? {
guard isTestFlight() else { return nil }
let platform = currentPlatform()
return messages.last(where: { $0.targetPlatforms.contains(platform) })
}
func markSeen(_ message: TestFlightMessage) {
Current.settingsStore.markTestFlightMessageSeen(messageID: message.id.rawValue)
}
}