diff --git a/SessionMessagingKit/Messages/Control Message/ClosedGroupUpdate.swift b/SessionMessagingKit/Messages/Control Message/ClosedGroupUpdate.swift index 9f83cede2..27efebb41 100644 --- a/SessionMessagingKit/Messages/Control Message/ClosedGroupUpdate.swift +++ b/SessionMessagingKit/Messages/Control Message/ClosedGroupUpdate.swift @@ -14,7 +14,7 @@ public final class ClosedGroupUpdate : ControlMessage { } // MARK: Initialization - init(kind: Kind) { + internal init(kind: Kind) { super.init() self.kind = kind } diff --git a/SessionMessagingKit/Messages/Control Message/ExpirationTimerUpdate.swift b/SessionMessagingKit/Messages/Control Message/ExpirationTimerUpdate.swift index 2a648f622..d3bbba194 100644 --- a/SessionMessagingKit/Messages/Control Message/ExpirationTimerUpdate.swift +++ b/SessionMessagingKit/Messages/Control Message/ExpirationTimerUpdate.swift @@ -5,7 +5,7 @@ public final class ExpirationTimerUpdate : ControlMessage { public var duration: UInt32? // MARK: Initialization - init(duration: UInt32) { + internal init(duration: UInt32) { super.init() self.duration = duration } diff --git a/SessionMessagingKit/Messages/Control Message/ReadReceipt.swift b/SessionMessagingKit/Messages/Control Message/ReadReceipt.swift index a46bfd313..cebdf28c6 100644 --- a/SessionMessagingKit/Messages/Control Message/ReadReceipt.swift +++ b/SessionMessagingKit/Messages/Control Message/ReadReceipt.swift @@ -5,7 +5,7 @@ public final class ReadReceipt : ControlMessage { public var timestamps: [UInt64]? // MARK: Initialization - init(timestamps: [UInt64]) { + internal init(timestamps: [UInt64]) { super.init() self.timestamps = timestamps } diff --git a/SessionMessagingKit/Messages/Control Message/SessionRequest.swift b/SessionMessagingKit/Messages/Control Message/SessionRequest.swift index af66018ba..995881c0f 100644 --- a/SessionMessagingKit/Messages/Control Message/SessionRequest.swift +++ b/SessionMessagingKit/Messages/Control Message/SessionRequest.swift @@ -6,7 +6,7 @@ public final class SessionRequest : ControlMessage { private var preKeyBundle: PreKeyBundle? // MARK: Initialization - init(preKeyBundle: PreKeyBundle) { + internal init(preKeyBundle: PreKeyBundle) { super.init() self.preKeyBundle = preKeyBundle } diff --git a/SessionMessagingKit/Messages/Control Message/TypingIndicator.swift b/SessionMessagingKit/Messages/Control Message/TypingIndicator.swift index 51e2e2c23..be391c493 100644 --- a/SessionMessagingKit/Messages/Control Message/TypingIndicator.swift +++ b/SessionMessagingKit/Messages/Control Message/TypingIndicator.swift @@ -24,7 +24,7 @@ public final class TypingIndicator : ControlMessage { } // MARK: Initialization - init(kind: Kind) { + internal init(kind: Kind) { super.init() self.kind = kind } diff --git a/SessionMessagingKit/Messages/Visible Message/VisibleMessage+Quote.swift b/SessionMessagingKit/Messages/Visible Message/VisibleMessage+Quote.swift index e50eddd59..1724e2dc1 100644 --- a/SessionMessagingKit/Messages/Visible Message/VisibleMessage+Quote.swift +++ b/SessionMessagingKit/Messages/Visible Message/VisibleMessage+Quote.swift @@ -1,15 +1,51 @@ +import SessionUtilities public extension VisibleMessage { @objc(SNQuote) 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) { - 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) { - 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 + } } } } diff --git a/SessionMessagingKit/Messages/Visible Message/VisibleMessage.swift b/SessionMessagingKit/Messages/Visible Message/VisibleMessage.swift index 75a47f7ef..f667f00fd 100644 --- a/SessionMessagingKit/Messages/Visible Message/VisibleMessage.swift +++ b/SessionMessagingKit/Messages/Visible Message/VisibleMessage.swift @@ -7,4 +7,26 @@ public final class VisibleMessage : Message { public var linkPreview: LinkPreview? public var contact: Contact? public var profile: Profile? + + // MARK: Coding + public required init?(coder: NSCoder) { + super.init(coder: coder) + if let text = coder.decodeObject(forKey: "text") as! String? { self.text = text } + if let attachmentIDs = coder.decodeObject(forKey: "attachmentIDs") as! [String]? { self.attachmentIDs = attachmentIDs } + } + + public override func encode(with coder: NSCoder) { + super.encode(with: coder) + coder.encode(text, forKey: "text") + coder.encode(attachmentIDs, forKey: "attachmentIDs") + } + + // MARK: Proto Conversion + public override class func fromProto(_ proto: SNProtoContent) -> VisibleMessage? { + return nil + } + + public override func toProto() -> SNProtoContent? { + return nil + } }