Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import Foundation
6
import Shared
7
import SwiftyJSON
8
9
open class ClientPayload: CleartextPayloadJSON {
10
override open func isValid() -> Bool {
11
if !super.isValid() {
12
return false
13
}
14
15
if self["deleted"].bool ?? false {
16
return true
17
}
18
19
return self["name"].isString() &&
20
self["type"].isString()
21
}
22
23
var commands: [JSON] {
24
return self["commands"].array ?? [] // It might not be present at all.
25
}
26
27
var name: String {
28
return self["name"].stringValue
29
}
30
31
var clientType: String {
32
return self["type"].stringValue
33
}
34
35
override open func equalPayloads(_ obj: CleartextPayloadJSON) -> Bool {
36
if !(obj is ClientPayload) {
37
return false
38
}
39
40
if !super.equalPayloads(obj) {
41
return false
42
}
43
44
let p = obj as! ClientPayload
45
if p.name != self.name {
46
return false
47
}
48
49
if p.clientType != self.clientType {
50
return false
51
}
52
53
return true
54
}
55
56
// TODO: version, protocols.
57
}