From 76f410b2b7b6fe9034d938d6d7c3e6b75b572b16 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 14 Jan 2019 09:09:33 -0500 Subject: [PATCH 1/3] Update protos to reflect link previews. --- SignalServiceKit/protobuf/SignalService.proto | 7 + .../src/Protos/Generated/SSKProto.swift | 149 +++++++++++++++++- .../Protos/Generated/SignalService.pb.swift | 133 ++++++++++++++++ 3 files changed, 287 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/protobuf/SignalService.proto b/SignalServiceKit/protobuf/SignalService.proto index c03cc861b..8dd3cc5c9 100644 --- a/SignalServiceKit/protobuf/SignalService.proto +++ b/SignalServiceKit/protobuf/SignalService.proto @@ -206,6 +206,12 @@ message DataMessage { optional string organization = 7; } + message Preview { + optional string url = 1; + optional string title = 2; + optional AttachmentPointer image = 3; + } + optional string body = 1; repeated AttachmentPointer attachments = 2; optional GroupContext group = 3; @@ -215,6 +221,7 @@ message DataMessage { optional uint64 timestamp = 7; optional Quote quote = 8; repeated Contact contact = 9; + optional Preview preview = 10; } message NullMessage { diff --git a/SignalServiceKit/src/Protos/Generated/SSKProto.swift b/SignalServiceKit/src/Protos/Generated/SSKProto.swift index 7ceac4485..511b12ada 100644 --- a/SignalServiceKit/src/Protos/Generated/SSKProto.swift +++ b/SignalServiceKit/src/Protos/Generated/SSKProto.swift @@ -2673,6 +2673,134 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { #endif +// MARK: - SSKProtoDataMessagePreview + +@objc public class SSKProtoDataMessagePreview: NSObject { + + // MARK: - SSKProtoDataMessagePreviewBuilder + + @objc public class func builder() -> SSKProtoDataMessagePreviewBuilder { + return SSKProtoDataMessagePreviewBuilder() + } + + // asBuilder() constructs a builder that reflects the proto's contents. + @objc public func asBuilder() -> SSKProtoDataMessagePreviewBuilder { + let builder = SSKProtoDataMessagePreviewBuilder() + if let _value = url { + builder.setUrl(_value) + } + if let _value = title { + builder.setTitle(_value) + } + if let _value = image { + builder.setImage(_value) + } + return builder + } + + @objc public class SSKProtoDataMessagePreviewBuilder: NSObject { + + private var proto = SignalServiceProtos_DataMessage.Preview() + + @objc fileprivate override init() {} + + @objc public func setUrl(_ valueParam: String) { + proto.url = valueParam + } + + @objc public func setTitle(_ valueParam: String) { + proto.title = valueParam + } + + @objc public func setImage(_ valueParam: SSKProtoAttachmentPointer) { + proto.image = valueParam.proto + } + + @objc public func build() throws -> SSKProtoDataMessagePreview { + return try SSKProtoDataMessagePreview.parseProto(proto) + } + + @objc public func buildSerializedData() throws -> Data { + return try SSKProtoDataMessagePreview.parseProto(proto).serializedData() + } + } + + fileprivate let proto: SignalServiceProtos_DataMessage.Preview + + @objc public let image: SSKProtoAttachmentPointer? + + @objc public var url: String? { + guard proto.hasUrl else { + return nil + } + return proto.url + } + @objc public var hasUrl: Bool { + return proto.hasUrl + } + + @objc public var title: String? { + guard proto.hasTitle else { + return nil + } + return proto.title + } + @objc public var hasTitle: Bool { + return proto.hasTitle + } + + private init(proto: SignalServiceProtos_DataMessage.Preview, + image: SSKProtoAttachmentPointer?) { + self.proto = proto + self.image = image + } + + @objc + public func serializedData() throws -> Data { + return try self.proto.serializedData() + } + + @objc public class func parseData(_ serializedData: Data) throws -> SSKProtoDataMessagePreview { + let proto = try SignalServiceProtos_DataMessage.Preview(serializedData: serializedData) + return try parseProto(proto) + } + + fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Preview) throws -> SSKProtoDataMessagePreview { + var image: SSKProtoAttachmentPointer? = nil + if proto.hasImage { + image = try SSKProtoAttachmentPointer.parseProto(proto.image) + } + + // MARK: - Begin Validation Logic for SSKProtoDataMessagePreview - + + // MARK: - End Validation Logic for SSKProtoDataMessagePreview - + + let result = SSKProtoDataMessagePreview(proto: proto, + image: image) + return result + } + + @objc public override var debugDescription: String { + return "\(proto)" + } +} + +#if DEBUG + +extension SSKProtoDataMessagePreview { + @objc public func serializedDataIgnoringErrors() -> Data? { + return try! self.serializedData() + } +} + +extension SSKProtoDataMessagePreview.SSKProtoDataMessagePreviewBuilder { + @objc public func buildIgnoringErrors() -> SSKProtoDataMessagePreview? { + return try! self.build() + } +} + +#endif + // MARK: - SSKProtoDataMessage @objc public class SSKProtoDataMessage: NSObject { @@ -2733,6 +2861,9 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { builder.setQuote(_value) } builder.setContact(contact) + if let _value = preview { + builder.setPreview(_value) + } return builder } @@ -2790,6 +2921,10 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { proto.contact = wrappedItems.map { $0.proto } } + @objc public func setPreview(_ valueParam: SSKProtoDataMessagePreview) { + proto.preview = valueParam.proto + } + @objc public func build() throws -> SSKProtoDataMessage { return try SSKProtoDataMessage.parseProto(proto) } @@ -2809,6 +2944,8 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { @objc public let contact: [SSKProtoDataMessageContact] + @objc public let preview: SSKProtoDataMessagePreview? + @objc public var body: String? { guard proto.hasBody else { return nil @@ -2854,12 +2991,14 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { attachments: [SSKProtoAttachmentPointer], group: SSKProtoGroupContext?, quote: SSKProtoDataMessageQuote?, - contact: [SSKProtoDataMessageContact]) { + contact: [SSKProtoDataMessageContact], + preview: SSKProtoDataMessagePreview?) { self.proto = proto self.attachments = attachments self.group = group self.quote = quote self.contact = contact + self.preview = preview } @objc @@ -2889,6 +3028,11 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { var contact: [SSKProtoDataMessageContact] = [] contact = try proto.contact.map { try SSKProtoDataMessageContact.parseProto($0) } + var preview: SSKProtoDataMessagePreview? = nil + if proto.hasPreview { + preview = try SSKProtoDataMessagePreview.parseProto(proto.preview) + } + // MARK: - Begin Validation Logic for SSKProtoDataMessage - // MARK: - End Validation Logic for SSKProtoDataMessage - @@ -2897,7 +3041,8 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { attachments: attachments, group: group, quote: quote, - contact: contact) + contact: contact, + preview: preview) return result } diff --git a/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift b/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift index 7b8e5e894..cb3b17a34 100644 --- a/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift @@ -634,6 +634,15 @@ struct SignalServiceProtos_DataMessage { set {_uniqueStorage()._contact = newValue} } + var preview: SignalServiceProtos_DataMessage.Preview { + get {return _storage._preview ?? SignalServiceProtos_DataMessage.Preview()} + set {_uniqueStorage()._preview = newValue} + } + /// Returns true if `preview` has been explicitly set. + var hasPreview: Bool {return _storage._preview != nil} + /// Clears the value of `preview`. Subsequent reads from it will return its default value. + mutating func clearPreview() {_uniqueStorage()._preview = nil} + var unknownFields = SwiftProtobuf.UnknownStorage() enum Flags: SwiftProtobuf.Enum { @@ -1212,6 +1221,45 @@ struct SignalServiceProtos_DataMessage { fileprivate var _storage = _StorageClass.defaultInstance } + struct Preview { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + var url: String { + get {return _storage._url ?? String()} + set {_uniqueStorage()._url = newValue} + } + /// Returns true if `url` has been explicitly set. + var hasURL: Bool {return _storage._url != nil} + /// Clears the value of `url`. Subsequent reads from it will return its default value. + mutating func clearURL() {_uniqueStorage()._url = nil} + + var title: String { + get {return _storage._title ?? String()} + set {_uniqueStorage()._title = newValue} + } + /// Returns true if `title` has been explicitly set. + var hasTitle: Bool {return _storage._title != nil} + /// Clears the value of `title`. Subsequent reads from it will return its default value. + mutating func clearTitle() {_uniqueStorage()._title = nil} + + var image: SignalServiceProtos_AttachmentPointer { + get {return _storage._image ?? SignalServiceProtos_AttachmentPointer()} + set {_uniqueStorage()._image = newValue} + } + /// Returns true if `image` has been explicitly set. + var hasImage: Bool {return _storage._image != nil} + /// Clears the value of `image`. Subsequent reads from it will return its default value. + mutating func clearImage() {_uniqueStorage()._image = nil} + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} + + fileprivate var _storage = _StorageClass.defaultInstance + } + init() {} fileprivate var _storage = _StorageClass.defaultInstance @@ -2772,6 +2820,7 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. 7: .same(proto: "timestamp"), 8: .same(proto: "quote"), 9: .same(proto: "contact"), + 10: .same(proto: "preview"), ] fileprivate class _StorageClass { @@ -2784,6 +2833,7 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. var _timestamp: UInt64? = nil var _quote: SignalServiceProtos_DataMessage.Quote? = nil var _contact: [SignalServiceProtos_DataMessage.Contact] = [] + var _preview: SignalServiceProtos_DataMessage.Preview? = nil static let defaultInstance = _StorageClass() @@ -2799,6 +2849,7 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. _timestamp = source._timestamp _quote = source._quote _contact = source._contact + _preview = source._preview } } @@ -2823,6 +2874,7 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. case 7: try decoder.decodeSingularUInt64Field(value: &_storage._timestamp) case 8: try decoder.decodeSingularMessageField(value: &_storage._quote) case 9: try decoder.decodeRepeatedMessageField(value: &_storage._contact) + case 10: try decoder.decodeSingularMessageField(value: &_storage._preview) default: break } } @@ -2858,6 +2910,9 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. if !_storage._contact.isEmpty { try visitor.visitRepeatedMessageField(value: _storage._contact, fieldNumber: 9) } + if let v = _storage._preview { + try visitor.visitSingularMessageField(value: v, fieldNumber: 10) + } } try unknownFields.traverse(visitor: &visitor) } @@ -2876,6 +2931,7 @@ extension SignalServiceProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf. if _storage._timestamp != rhs_storage._timestamp {return false} if _storage._quote != rhs_storage._quote {return false} if _storage._contact != rhs_storage._contact {return false} + if _storage._preview != rhs_storage._preview {return false} return true } if !storagesAreEqual {return false} @@ -3445,6 +3501,83 @@ extension SignalServiceProtos_DataMessage.Contact.Avatar: SwiftProtobuf.Message, } } +extension SignalServiceProtos_DataMessage.Preview: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = SignalServiceProtos_DataMessage.protoMessageName + ".Preview" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "url"), + 2: .same(proto: "title"), + 3: .same(proto: "image"), + ] + + fileprivate class _StorageClass { + var _url: String? = nil + var _title: String? = nil + var _image: SignalServiceProtos_AttachmentPointer? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _url = source._url + _title = source._title + _image = source._image + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._url) + case 2: try decoder.decodeSingularStringField(value: &_storage._title) + case 3: try decoder.decodeSingularMessageField(value: &_storage._image) + default: break + } + } + } + } + + func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if let v = _storage._url { + try visitor.visitSingularStringField(value: v, fieldNumber: 1) + } + if let v = _storage._title { + try visitor.visitSingularStringField(value: v, fieldNumber: 2) + } + if let v = _storage._image { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: SignalServiceProtos_DataMessage.Preview, rhs: SignalServiceProtos_DataMessage.Preview) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._url != rhs_storage._url {return false} + if _storage._title != rhs_storage._title {return false} + if _storage._image != rhs_storage._image {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + extension SignalServiceProtos_NullMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = _protobuf_package + ".NullMessage" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ From 5a529567aa80bcacd364883e9c39b496bd54dd5e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 14 Jan 2019 09:23:49 -0500 Subject: [PATCH 2/3] Update protos to reflect link previews. --- SignalServiceKit/protobuf/SignalService.proto | 1 + .../src/Protos/Generated/SSKProto.swift | 35 ++++++++++--------- .../Protos/Generated/SignalService.pb.swift | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/SignalServiceKit/protobuf/SignalService.proto b/SignalServiceKit/protobuf/SignalService.proto index 8dd3cc5c9..4e3b7ccf4 100644 --- a/SignalServiceKit/protobuf/SignalService.proto +++ b/SignalServiceKit/protobuf/SignalService.proto @@ -207,6 +207,7 @@ message DataMessage { } message Preview { + // @required optional string url = 1; optional string title = 2; optional AttachmentPointer image = 3; diff --git a/SignalServiceKit/src/Protos/Generated/SSKProto.swift b/SignalServiceKit/src/Protos/Generated/SSKProto.swift index 511b12ada..966bd22e3 100644 --- a/SignalServiceKit/src/Protos/Generated/SSKProto.swift +++ b/SignalServiceKit/src/Protos/Generated/SSKProto.swift @@ -2679,16 +2679,13 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { // MARK: - SSKProtoDataMessagePreviewBuilder - @objc public class func builder() -> SSKProtoDataMessagePreviewBuilder { - return SSKProtoDataMessagePreviewBuilder() + @objc public class func builder(url: String) -> SSKProtoDataMessagePreviewBuilder { + return SSKProtoDataMessagePreviewBuilder(url: url) } // asBuilder() constructs a builder that reflects the proto's contents. @objc public func asBuilder() -> SSKProtoDataMessagePreviewBuilder { - let builder = SSKProtoDataMessagePreviewBuilder() - if let _value = url { - builder.setUrl(_value) - } + let builder = SSKProtoDataMessagePreviewBuilder(url: url) if let _value = title { builder.setTitle(_value) } @@ -2704,6 +2701,12 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { @objc fileprivate override init() {} + @objc fileprivate init(url: String) { + super.init() + + setUrl(url) + } + @objc public func setUrl(_ valueParam: String) { proto.url = valueParam } @@ -2727,17 +2730,9 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { fileprivate let proto: SignalServiceProtos_DataMessage.Preview - @objc public let image: SSKProtoAttachmentPointer? + @objc public let url: String - @objc public var url: String? { - guard proto.hasUrl else { - return nil - } - return proto.url - } - @objc public var hasUrl: Bool { - return proto.hasUrl - } + @objc public let image: SSKProtoAttachmentPointer? @objc public var title: String? { guard proto.hasTitle else { @@ -2750,8 +2745,10 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { } private init(proto: SignalServiceProtos_DataMessage.Preview, + url: String, image: SSKProtoAttachmentPointer?) { self.proto = proto + self.url = url self.image = image } @@ -2766,6 +2763,11 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { } fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Preview) throws -> SSKProtoDataMessagePreview { + guard proto.hasUrl else { + throw SSKProtoError.invalidProtobuf(description: "\(logTag) missing required field: url") + } + let url = proto.url + var image: SSKProtoAttachmentPointer? = nil if proto.hasImage { image = try SSKProtoAttachmentPointer.parseProto(proto.image) @@ -2776,6 +2778,7 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { // MARK: - End Validation Logic for SSKProtoDataMessagePreview - let result = SSKProtoDataMessagePreview(proto: proto, + url: url, image: image) return result } diff --git a/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift b/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift index cb3b17a34..713b635da 100644 --- a/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift +++ b/SignalServiceKit/src/Protos/Generated/SignalService.pb.swift @@ -1226,6 +1226,7 @@ struct SignalServiceProtos_DataMessage { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// @required var url: String { get {return _storage._url ?? String()} set {_uniqueStorage()._url = newValue} From aa916965d0605f640dc99207c3e2124c18585f89 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 14 Jan 2019 09:34:40 -0500 Subject: [PATCH 3/3] Update protos to reflect link previews. --- Scripts/ProtoWrappers.py | 4 ++++ SignalServiceKit/src/Protos/Generated/SSKProto.swift | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Scripts/ProtoWrappers.py b/Scripts/ProtoWrappers.py index c35bbbe30..b2838cba9 100755 --- a/Scripts/ProtoWrappers.py +++ b/Scripts/ProtoWrappers.py @@ -356,6 +356,10 @@ class MessageField: # TODO: I'm not sure why "Apple Swift Proto" code formats the # the name in this way. name = 'hasID' + elif name == 'hasUrl': + # TODO: I'm not sure why "Apple Swift Proto" code formats the + # the name in this way. + name = 'hasURL' return name class MessageContext(BaseContext): diff --git a/SignalServiceKit/src/Protos/Generated/SSKProto.swift b/SignalServiceKit/src/Protos/Generated/SSKProto.swift index 966bd22e3..9af1d765f 100644 --- a/SignalServiceKit/src/Protos/Generated/SSKProto.swift +++ b/SignalServiceKit/src/Protos/Generated/SSKProto.swift @@ -2763,7 +2763,7 @@ extension SSKProtoDataMessageContact.SSKProtoDataMessageContactBuilder { } fileprivate class func parseProto(_ proto: SignalServiceProtos_DataMessage.Preview) throws -> SSKProtoDataMessagePreview { - guard proto.hasUrl else { + guard proto.hasURL else { throw SSKProtoError.invalidProtobuf(description: "\(logTag) missing required field: url") } let url = proto.url