Implement link preview

This commit is contained in:
nielsandriesse 2020-11-06 15:37:11 +11:00
parent 9dc942772c
commit 39a1a4b3ab
5 changed files with 42 additions and 9 deletions

View file

@ -4,12 +4,8 @@ public extension VisibleMessage {
@objc(SNContact)
class Contact : NSObject, NSCoding {
public required init?(coder: NSCoder) {
fatalError("Not implemented.")
}
public required init?(coder: NSCoder) { }
public func encode(with coder: NSCoder) {
fatalError("Not implemented.")
}
public func encode(with coder: NSCoder) { }
}
}

View file

@ -1,15 +1,46 @@
import SessionUtilities
public extension VisibleMessage {
@objc(SNLinkPreview)
class LinkPreview : NSObject, NSCoding {
public var title: String?
public var url: String?
internal init(title: String, url: String) {
self.title = title
self.url = url
}
public required init?(coder: NSCoder) {
fatalError("Not implemented.")
if let title = coder.decodeObject(forKey: "title") as! String? { self.title = title }
if let url = coder.decodeObject(forKey: "url") as! String? { self.url = url }
}
public func encode(with coder: NSCoder) {
fatalError("Not implemented.")
coder.encode(title, forKey: "title")
coder.encode(url, forKey: "url")
}
public static func fromProto(_ proto: SNProtoDataMessagePreview) -> LinkPreview? {
guard let title = proto.title else { return nil }
let url = proto.url
return LinkPreview(title: title, url: url)
}
public func toProto() -> SNProtoDataMessagePreview? {
guard let title = title, let url = url else {
SNLog("Couldn't construct link preview proto from: \(self).")
return nil
}
let linkPreviewProto = SNProtoDataMessagePreview.builder(url: url)
linkPreviewProto.setTitle(title)
do {
return try linkPreviewProto.build()
} catch {
SNLog("Couldn't construct link preview proto from: \(self).")
return nil
}
}
}
}

View file

@ -3,7 +3,8 @@ import SessionUtilities
public enum ReceivingPipeline {
public static func parse(_ data: Data) -> Message? {
// TODO: Decrypt
// TODO: Decryption
// TODO: Validation
let proto: SNProtoContent
do {
proto = try SNProtoContent.parseData(data)

View file

@ -34,6 +34,7 @@ public enum SendingPipeline {
return Promise(error: Error.protoSerializationFailed)
}
// TODO: Encryption
// TODO: Validation
let recipient = ""
let base64EncodedData = data.base64EncodedString()
let ttl: UInt64 = 2 * 24 * 60 * 60 * 1000

View file

@ -6,10 +6,14 @@
<dict>
<key>CarthageVersion</key>
<string>0.36.0</string>
<key>DateTime</key>
<string>Fri Nov 6 03:20:05 UTC 2020</string>
<key>OSXVersion</key>
<string>10.15.6</string>
<key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
<key>XCodeVersion</key>
<string>1200.1210</string>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>