2020-11-05 04:16:45 +01:00
|
|
|
|
|
|
|
/// Abstract base class for `VisibleMessage` and `ControlMessage`.
|
|
|
|
@objc(SNMessage)
|
|
|
|
public class Message : NSObject, NSCoding { // Not a protocol for YapDatabase compatibility
|
|
|
|
public var id: String?
|
|
|
|
public var threadID: String?
|
|
|
|
public var sentTimestamp: UInt64?
|
|
|
|
public var receivedTimestamp: UInt64?
|
|
|
|
|
2020-11-05 06:10:49 +01:00
|
|
|
public override init() { }
|
|
|
|
|
2020-11-06 00:43:34 +01:00
|
|
|
// MARK: Coding
|
2020-11-05 04:16:45 +01:00
|
|
|
public required init?(coder: NSCoder) {
|
2020-11-06 00:59:04 +01:00
|
|
|
if let id = coder.decodeObject(forKey: "id") as! String? { self.id = id }
|
|
|
|
if let threadID = coder.decodeObject(forKey: "threadID") as! String? { self.threadID = threadID }
|
|
|
|
if let sentTimestamp = coder.decodeObject(forKey: "sentTimestamp") as! UInt64? { self.sentTimestamp = sentTimestamp }
|
|
|
|
if let receivedTimestamp = coder.decodeObject(forKey: "receivedTimestamp") as! UInt64? { self.receivedTimestamp = receivedTimestamp }
|
2020-11-05 04:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func encode(with coder: NSCoder) {
|
2020-11-06 00:43:34 +01:00
|
|
|
coder.encode(id, forKey: "id")
|
|
|
|
coder.encode(threadID, forKey: "threadID")
|
|
|
|
coder.encode(sentTimestamp, forKey: "sentTimestamp")
|
|
|
|
coder.encode(receivedTimestamp, forKey: "receivedTimestamp")
|
2020-11-05 04:16:45 +01:00
|
|
|
}
|
2020-11-05 06:10:49 +01:00
|
|
|
|
2020-11-06 00:43:34 +01:00
|
|
|
// MARK: Proto Conversion
|
|
|
|
public class func fromProto(_ proto: SNProtoContent) -> Self? {
|
|
|
|
preconditionFailure("fromProto(_:) is abstract and must be overridden.")
|
2020-11-05 06:10:49 +01:00
|
|
|
}
|
|
|
|
|
2020-11-06 00:43:34 +01:00
|
|
|
public func toProto() -> SNProtoContent? {
|
|
|
|
preconditionFailure("toProto() is abstract and must be overridden.")
|
2020-11-05 06:10:49 +01:00
|
|
|
}
|
2020-11-05 04:16:45 +01:00
|
|
|
}
|