Files
yattee/Yattee/Services/Subscriptions/SubscriptionProvider.swift
Arkadiusz Fal 4770bbe3b9 Remove dead code found by Periphery on all platforms
Delete declarations that Periphery reports unused on every platform that
compiles them (iOS, macOS, tvOS), including nine views used only by their
own previews. Platform-gated code still used on another platform, device-
only MPV render paths, migration models, CloudKit record names, App
Intents metadata and unused parameters are kept.
2026-10-08 23:57:56 +02:00

85 lines
3.0 KiB
Swift

//
// SubscriptionProvider.swift
// Yattee
//
// Protocol defining subscription management operations.
// Implementations handle different subscription sources (local, Invidious, Piped).
//
import Foundation
/// Protocol for subscription management providers.
/// Each provider implementation handles a specific subscription source.
@MainActor
protocol SubscriptionProvider: Sendable {
/// Fetches all subscriptions from the provider.
/// - Returns: Array of channels the user is subscribed to.
func fetchSubscriptions() async throws -> [Channel]
/// Subscribes to a channel.
/// - Parameter channel: The channel to subscribe to.
func subscribe(to channel: Channel) async throws
/// Unsubscribes from a channel.
/// - Parameter channelID: The channel ID to unsubscribe from.
func unsubscribe(from channelID: String) async throws
/// Checks if subscribed to a channel.
/// - Parameter channelID: The channel ID to check.
/// - Returns: `true` if subscribed, `false` otherwise.
func isSubscribed(to channelID: String) async -> Bool
/// The subscription count known without a network fetch.
/// Returns nil when the provider hasn't populated its cache yet.
var cachedSubscriptionCount: Int? { get }
/// The subscribed channels known without a network fetch.
/// Returns nil when the provider hasn't populated its cache yet.
var cachedSubscriptions: [Channel]? { get }
/// Refreshes the local cache of subscriptions from the remote source.
/// For local provider, this is a no-op.
func refreshCache() async throws
}
// MARK: - Default Implementations
extension SubscriptionProvider {
/// Default implementation for providers that don't need cache refresh.
func refreshCache() async throws {
// No-op by default
}
}
// MARK: - Subscription Provider Error
/// Errors that can occur during subscription provider operations.
enum SubscriptionProviderError: Error, LocalizedError, Equatable, Sendable {
case notAuthenticated
case networkError(String)
case channelNotFound
case alreadySubscribed
case notSubscribed
case instanceNotConfigured
case operationFailed(String)
var errorDescription: String? {
switch self {
case .notAuthenticated:
return String(localized: "subscription.error.notAuthenticated")
case .networkError(let message):
return String(localized: "subscription.error.network \(message)")
case .channelNotFound:
return String(localized: "subscription.error.channelNotFound")
case .alreadySubscribed:
return String(localized: "subscription.error.alreadySubscribed")
case .notSubscribed:
return String(localized: "subscription.error.notSubscribed")
case .instanceNotConfigured:
return String(localized: "subscription.error.instanceNotConfigured")
case .operationFailed(let message):
return String(localized: "subscription.error.operationFailed \(message)")
}
}
}