mirror of https://github.com/oxen-io/session-ios
Implement quote
parent
40098ac180
commit
9dc942772c
@ -1,15 +1,51 @@
|
|||||||
|
import SessionUtilities
|
||||||
|
|
||||||
public extension VisibleMessage {
|
public extension VisibleMessage {
|
||||||
|
|
||||||
@objc(SNQuote)
|
@objc(SNQuote)
|
||||||
class Quote : NSObject, NSCoding {
|
class Quote : NSObject, NSCoding {
|
||||||
|
public var timestamp: UInt64?
|
||||||
|
public var publicKey: String?
|
||||||
|
public var text: String?
|
||||||
|
|
||||||
|
internal init(timestamp: UInt64, publicKey: String, text: String) {
|
||||||
|
self.timestamp = timestamp
|
||||||
|
self.publicKey = publicKey
|
||||||
|
self.text = text
|
||||||
|
}
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
fatalError("Not implemented.")
|
if let timestamp = coder.decodeObject(forKey: "timestamp") as! UInt64? { self.timestamp = timestamp }
|
||||||
|
if let publicKey = coder.decodeObject(forKey: "publicKey") as! String? { self.publicKey = publicKey }
|
||||||
|
if let text = coder.decodeObject(forKey: "text") as! String? { self.text = text }
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(with coder: NSCoder) {
|
public func encode(with coder: NSCoder) {
|
||||||
fatalError("Not implemented.")
|
coder.encode(timestamp, forKey: "timestamp")
|
||||||
|
coder.encode(publicKey, forKey: "publicKey")
|
||||||
|
coder.encode(text, forKey: "text")
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func fromProto(_ proto: SNProtoDataMessageQuote) -> Quote? {
|
||||||
|
let timestamp = proto.id
|
||||||
|
let publicKey = proto.author
|
||||||
|
guard let text = proto.text else { return nil }
|
||||||
|
return Quote(timestamp: timestamp, publicKey: publicKey, text: text)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func toProto() -> SNProtoDataMessageQuote? {
|
||||||
|
guard let timestamp = timestamp, let publicKey = publicKey else {
|
||||||
|
SNLog("Couldn't construct quote proto from: \(self).")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let quoteProto = SNProtoDataMessageQuote.builder(id: timestamp, author: publicKey)
|
||||||
|
if let text = text { quoteProto.setText(text) }
|
||||||
|
do {
|
||||||
|
return try quoteProto.build()
|
||||||
|
} catch {
|
||||||
|
SNLog("Couldn't construct quote proto from: \(self).")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue