metatext/DB/Sources/DB/Entities/Timeline.swift

51 lines
1.2 KiB
Swift
Raw Normal View History

2020-08-18 05:13:37 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
2020-10-01 02:35:06 +00:00
import Mastodon
2020-08-18 05:13:37 +00:00
2020-08-30 23:33:11 +00:00
public enum Timeline: Hashable {
2020-08-18 05:13:37 +00:00
case home
case local
case federated
2020-09-26 03:28:50 +00:00
case list(List)
2020-08-30 19:50:34 +00:00
case tag(String)
2020-10-05 22:50:05 +00:00
case profile(accountId: Account.Id, profileCollection: ProfileCollection)
2020-08-18 05:13:37 +00:00
}
2020-08-30 23:33:11 +00:00
public extension Timeline {
2020-10-05 22:50:05 +00:00
typealias Id = String
2020-09-09 05:40:49 +00:00
static let unauthenticatedDefaults: [Timeline] = [.local, .federated]
static let authenticatedDefaults: [Timeline] = [.home, .local, .federated]
var filterContext: Filter.Context {
switch self {
case .home, .list:
return .home
case .local, .federated, .tag:
return .public
case .profile:
return .account
}
}
}
2020-08-29 03:50:58 +00:00
extension Timeline: Identifiable {
2020-10-05 22:50:05 +00:00
public var id: Id {
2020-08-18 05:13:37 +00:00
switch self {
case .home:
2020-08-29 03:50:58 +00:00
return "home"
2020-08-18 05:13:37 +00:00
case .local:
2020-08-29 03:50:58 +00:00
return "local"
2020-08-18 05:13:37 +00:00
case .federated:
2020-08-29 03:50:58 +00:00
return "federated"
2020-08-18 05:13:37 +00:00
case let .list(list):
2020-10-01 02:35:06 +00:00
return "list-".appending(list.id)
2020-08-30 19:50:34 +00:00
case let .tag(tag):
2020-10-01 02:35:06 +00:00
return "tag-".appending(tag).lowercased()
case let .profile(accountId, profileCollection):
return "profile-\(accountId)-\(profileCollection)"
2020-08-18 05:13:37 +00:00
}
}
}