mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
cf66edb723
Added migrations for contacts and started working through thread migration (have contact and closed group threads migrating) Deprecated usage of ECKeyPair in the migrations (want to be able to remove Curve25519Kit in the future)
67 lines
2.2 KiB
Swift
67 lines
2.2 KiB
Swift
import SessionUtilitiesKit
|
|
|
|
@objc(SNReadReceipt)
|
|
public final class ReadReceipt : ControlMessage {
|
|
@objc public var timestamps: [UInt64]?
|
|
|
|
// MARK: Initialization
|
|
public override init() { super.init() }
|
|
|
|
internal init(timestamps: [UInt64]) {
|
|
super.init()
|
|
self.timestamps = timestamps
|
|
}
|
|
|
|
// MARK: Validation
|
|
public override var isValid: Bool {
|
|
guard super.isValid else { return false }
|
|
if let timestamps = timestamps, !timestamps.isEmpty { return true }
|
|
return false
|
|
}
|
|
|
|
// MARK: Coding
|
|
public required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
if let timestamps = coder.decodeObject(forKey: "messageTimestamps") as! [UInt64]? { self.timestamps = timestamps }
|
|
}
|
|
|
|
public override func encode(with coder: NSCoder) {
|
|
super.encode(with: coder)
|
|
coder.encode(timestamps, forKey: "messageTimestamps")
|
|
}
|
|
|
|
// MARK: Proto Conversion
|
|
public override class func fromProto(_ proto: SNProtoContent, sender: String) -> ReadReceipt? {
|
|
guard let receiptProto = proto.receiptMessage, receiptProto.type == .read else { return nil }
|
|
let timestamps = receiptProto.timestamp
|
|
guard !timestamps.isEmpty else { return nil }
|
|
return ReadReceipt(timestamps: timestamps)
|
|
}
|
|
|
|
public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
|
|
guard let timestamps = timestamps else {
|
|
SNLog("Couldn't construct read receipt proto from: \(self).")
|
|
return nil
|
|
}
|
|
let receiptProto = SNProtoReceiptMessage.builder(type: .read)
|
|
receiptProto.setTimestamp(timestamps)
|
|
let contentProto = SNProtoContent.builder()
|
|
do {
|
|
contentProto.setReceiptMessage(try receiptProto.build())
|
|
return try contentProto.build()
|
|
} catch {
|
|
SNLog("Couldn't construct read receipt proto from: \(self).")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// MARK: Description
|
|
public override var description: String {
|
|
"""
|
|
ReadReceipt(
|
|
timestamps: \(timestamps?.description ?? "null")
|
|
)
|
|
"""
|
|
}
|
|
}
|