mirror of
https://github.com/metabolist/metatext.git
synced 2024-05-31 22:58:04 +00:00
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import Mastodon
|
|
|
|
extension Timeline {
|
|
func save(_ db: Database) throws {
|
|
try TimelineRecord(timeline: self).save(db)
|
|
}
|
|
|
|
init?(record: TimelineRecord) {
|
|
switch (record.id,
|
|
record.listId,
|
|
record.listTitle,
|
|
record.tag,
|
|
record.accountId,
|
|
record.profileCollection) {
|
|
case (Timeline.home.id, _, _, _, _, _):
|
|
self = .home
|
|
case (Timeline.local.id, _, _, _, _, _):
|
|
self = .local
|
|
case (Timeline.federated.id, _, _, _, _, _):
|
|
self = .federated
|
|
case (_, .some(let listId), .some(let listTitle), _, _, _):
|
|
self = .list(List(id: listId, title: listTitle))
|
|
case (_, _, _, .some(let tag), _, _):
|
|
self = .tag(tag)
|
|
case (_, _, _, _, .some(let accountId), .some(let profileCollection)):
|
|
self = .profile(accountId: accountId, profileCollection: profileCollection)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
}
|