mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Swift
		
	
| import SessionUtilities
 | |
| 
 | |
| @objc(SNReadReceipt)
 | |
| public final class ReadReceipt : ControlMessage {
 | |
|     public var timestamps: [UInt64]?
 | |
| 
 | |
|     // MARK: Initialization
 | |
|     internal init(timestamps: [UInt64]) {
 | |
|         super.init()
 | |
|         self.timestamps = timestamps
 | |
|     }
 | |
| 
 | |
|     // MARK: Coding
 | |
|     public required init?(coder: NSCoder) {
 | |
|         super.init(coder: coder)
 | |
|         if let timestamps = coder.decodeObject(forKey: "timestamps") as! [UInt64]? { self.timestamps = timestamps }
 | |
|     }
 | |
| 
 | |
|     public override func encode(with coder: NSCoder) {
 | |
|         super.encode(with: coder)
 | |
|         coder.encode(timestamps, forKey: "timestamps")
 | |
|     }
 | |
| 
 | |
|     // MARK: Proto Conversion
 | |
|     public override class func fromProto(_ proto: SNProtoContent) -> 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() -> 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
 | |
|         }
 | |
|     }
 | |
| }
 |