2020-02-09 22:08:11 +01:00
|
|
|
//
|
|
|
|
// ShareDefaultContainer.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 2/11/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct ShareDefaultContainer {
|
|
|
|
|
2024-05-04 07:56:42 +02:00
|
|
|
@MainActor static func defaultContainer(containers: ExtensionContainers) -> ExtensionContainer? {
|
2020-02-09 22:08:11 +01:00
|
|
|
|
2024-02-26 08:12:21 +01:00
|
|
|
if let accountID = AppDefaults.shared.addFeedAccountID, let account = containers.accounts.first(where: { $0.accountID == accountID }) {
|
|
|
|
if let folderName = AppDefaults.shared.addFeedFolderName, let folder = account.folders.first(where: { $0.name == folderName }) {
|
2020-02-09 22:08:11 +01:00
|
|
|
return folder
|
|
|
|
} else {
|
|
|
|
return substituteContainerIfNeeded(account: account)
|
|
|
|
}
|
|
|
|
} else if let account = containers.accounts.first {
|
|
|
|
return substituteContainerIfNeeded(account: account)
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-05-04 07:56:42 +02:00
|
|
|
@MainActor static func saveDefaultContainer(_ container: ExtensionContainer) {
|
2024-02-26 08:12:21 +01:00
|
|
|
AppDefaults.shared.addFeedAccountID = container.accountID
|
2020-02-09 22:08:11 +01:00
|
|
|
if let folder = container as? ExtensionFolder {
|
2024-02-26 08:12:21 +01:00
|
|
|
AppDefaults.shared.addFeedFolderName = folder.name
|
2020-02-09 22:08:11 +01:00
|
|
|
} else {
|
2024-02-26 08:12:21 +01:00
|
|
|
AppDefaults.shared.addFeedFolderName = nil
|
2020-02-09 22:08:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static func substituteContainerIfNeeded(account: ExtensionAccount) -> ExtensionContainer? {
|
|
|
|
if !account.disallowFeedInRootFolder {
|
|
|
|
return account
|
|
|
|
} else {
|
|
|
|
if let folder = account.folders.first {
|
|
|
|
return folder
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|