-
Notifications
You must be signed in to change notification settings - Fork 25
/
Site.swift
70 lines (57 loc) · 1.85 KB
/
Site.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import UIKit
import Shared
public protocol Identifiable: Equatable {
var id: Int? { get set }
}
public func == <T>(lhs: T, rhs: T) -> Bool where T: Identifiable {
return lhs.id == rhs.id
}
open class Favicon: Identifiable {
open var id: Int?
public let url: String
public let date: Date
open var width: Int?
open var height: Int?
public init(url: String, date: Date = Date()) {
self.url = url
self.date = date
}
}
// TO DO: Site shouldn't have all of these optional decorators. Include those in the
// cursor results, perhaps as a tuple.
open class Site: Identifiable {
open var id: Int?
var guid: String?
open var tileURL: URL {
return URL(string: url)?.domainURL ?? URL(string: "about:blank")!
}
public let url: String
public let title: String
open var metadata: PageMetadata?
// Sites may have multiple favicons. We'll return the largest.
open var icon: Favicon?
open var latestVisit: Visit?
open fileprivate(set) var bookmarked: Bool?
public convenience init(url: String, title: String) {
self.init(url: url, title: title, bookmarked: false, guid: nil)
}
public init(url: String, title: String, bookmarked: Bool?, guid: String? = nil) {
self.url = url
self.title = title
self.bookmarked = bookmarked
self.guid = guid
}
open func setBookmarked(_ bookmarked: Bool) {
self.bookmarked = bookmarked
}
public func toDict() -> [String: Any] {
return [
"url": self.url,
"title": self.title,
"visitedAt": self.latestVisit?.date ?? 0,
]
}
}