Update protobuf for data extraction notifications

This commit is contained in:
Niels Andriesse 2021-03-02 13:57:55 +11:00
parent 82690259b2
commit defb3a751b
3 changed files with 297 additions and 2 deletions

View file

@ -363,6 +363,9 @@ extension SNProtoTypingMessage.SNProtoTypingMessageBuilder {
if let _value = configurationMessage {
builder.setConfigurationMessage(_value)
}
if let _value = infoMessage {
builder.setInfoMessage(_value)
}
return builder
}
@ -388,6 +391,10 @@ extension SNProtoTypingMessage.SNProtoTypingMessageBuilder {
proto.configurationMessage = valueParam.proto
}
@objc public func setInfoMessage(_ valueParam: SNProtoInfoMessage) {
proto.infoMessage = valueParam.proto
}
@objc public func build() throws -> SNProtoContent {
return try SNProtoContent.parseProto(proto)
}
@ -407,16 +414,20 @@ extension SNProtoTypingMessage.SNProtoTypingMessageBuilder {
@objc public let configurationMessage: SNProtoConfigurationMessage?
@objc public let infoMessage: SNProtoInfoMessage?
private init(proto: SessionProtos_Content,
dataMessage: SNProtoDataMessage?,
receiptMessage: SNProtoReceiptMessage?,
typingMessage: SNProtoTypingMessage?,
configurationMessage: SNProtoConfigurationMessage?) {
configurationMessage: SNProtoConfigurationMessage?,
infoMessage: SNProtoInfoMessage?) {
self.proto = proto
self.dataMessage = dataMessage
self.receiptMessage = receiptMessage
self.typingMessage = typingMessage
self.configurationMessage = configurationMessage
self.infoMessage = infoMessage
}
@objc
@ -450,6 +461,11 @@ extension SNProtoTypingMessage.SNProtoTypingMessageBuilder {
configurationMessage = try SNProtoConfigurationMessage.parseProto(proto.configurationMessage)
}
var infoMessage: SNProtoInfoMessage? = nil
if proto.hasInfoMessage {
infoMessage = try SNProtoInfoMessage.parseProto(proto.infoMessage)
}
// MARK: - Begin Validation Logic for SNProtoContent -
// MARK: - End Validation Logic for SNProtoContent -
@ -458,7 +474,8 @@ extension SNProtoTypingMessage.SNProtoTypingMessageBuilder {
dataMessage: dataMessage,
receiptMessage: receiptMessage,
typingMessage: typingMessage,
configurationMessage: configurationMessage)
configurationMessage: configurationMessage,
infoMessage: infoMessage)
return result
}
@ -595,6 +612,138 @@ extension SNProtoKeyPair.SNProtoKeyPairBuilder {
#endif
// MARK: - SNProtoInfoMessage
@objc public class SNProtoInfoMessage: NSObject {
// MARK: - SNProtoInfoMessageType
@objc public enum SNProtoInfoMessageType: Int32 {
case screenshot = 1
case mediaSaved = 2
}
private class func SNProtoInfoMessageTypeWrap(_ value: SessionProtos_InfoMessage.TypeEnum) -> SNProtoInfoMessageType {
switch value {
case .screenshot: return .screenshot
case .mediaSaved: return .mediaSaved
}
}
private class func SNProtoInfoMessageTypeUnwrap(_ value: SNProtoInfoMessageType) -> SessionProtos_InfoMessage.TypeEnum {
switch value {
case .screenshot: return .screenshot
case .mediaSaved: return .mediaSaved
}
}
// MARK: - SNProtoInfoMessageBuilder
@objc public class func builder(type: SNProtoInfoMessageType) -> SNProtoInfoMessageBuilder {
return SNProtoInfoMessageBuilder(type: type)
}
// asBuilder() constructs a builder that reflects the proto's contents.
@objc public func asBuilder() -> SNProtoInfoMessageBuilder {
let builder = SNProtoInfoMessageBuilder(type: type)
if hasTimestamp {
builder.setTimestamp(timestamp)
}
return builder
}
@objc public class SNProtoInfoMessageBuilder: NSObject {
private var proto = SessionProtos_InfoMessage()
@objc fileprivate override init() {}
@objc fileprivate init(type: SNProtoInfoMessageType) {
super.init()
setType(type)
}
@objc public func setType(_ valueParam: SNProtoInfoMessageType) {
proto.type = SNProtoInfoMessageTypeUnwrap(valueParam)
}
@objc public func setTimestamp(_ valueParam: UInt64) {
proto.timestamp = valueParam
}
@objc public func build() throws -> SNProtoInfoMessage {
return try SNProtoInfoMessage.parseProto(proto)
}
@objc public func buildSerializedData() throws -> Data {
return try SNProtoInfoMessage.parseProto(proto).serializedData()
}
}
fileprivate let proto: SessionProtos_InfoMessage
@objc public let type: SNProtoInfoMessageType
@objc public var timestamp: UInt64 {
return proto.timestamp
}
@objc public var hasTimestamp: Bool {
return proto.hasTimestamp
}
private init(proto: SessionProtos_InfoMessage,
type: SNProtoInfoMessageType) {
self.proto = proto
self.type = type
}
@objc
public func serializedData() throws -> Data {
return try self.proto.serializedData()
}
@objc public class func parseData(_ serializedData: Data) throws -> SNProtoInfoMessage {
let proto = try SessionProtos_InfoMessage(serializedData: serializedData)
return try parseProto(proto)
}
fileprivate class func parseProto(_ proto: SessionProtos_InfoMessage) throws -> SNProtoInfoMessage {
guard proto.hasType else {
throw SNProtoError.invalidProtobuf(description: "\(logTag) missing required field: type")
}
let type = SNProtoInfoMessageTypeWrap(proto.type)
// MARK: - Begin Validation Logic for SNProtoInfoMessage -
// MARK: - End Validation Logic for SNProtoInfoMessage -
let result = SNProtoInfoMessage(proto: proto,
type: type)
return result
}
@objc public override var debugDescription: String {
return "\(proto)"
}
}
#if DEBUG
extension SNProtoInfoMessage {
@objc public func serializedDataIgnoringErrors() -> Data? {
return try! self.serializedData()
}
}
extension SNProtoInfoMessage.SNProtoInfoMessageBuilder {
@objc public func buildIgnoringErrors() -> SNProtoInfoMessage? {
return try! self.build()
}
}
#endif
// MARK: - SNProtoDataMessageQuoteQuotedAttachment
@objc public class SNProtoDataMessageQuoteQuotedAttachment: NSObject {

View file

@ -236,6 +236,15 @@ struct SessionProtos_Content {
/// Clears the value of `configurationMessage`. Subsequent reads from it will return its default value.
mutating func clearConfigurationMessage() {_uniqueStorage()._configurationMessage = nil}
var infoMessage: SessionProtos_InfoMessage {
get {return _storage._infoMessage ?? SessionProtos_InfoMessage()}
set {_uniqueStorage()._infoMessage = newValue}
}
/// Returns true if `infoMessage` has been explicitly set.
var hasInfoMessage: Bool {return _storage._infoMessage != nil}
/// Clears the value of `infoMessage`. Subsequent reads from it will return its default value.
mutating func clearInfoMessage() {_uniqueStorage()._infoMessage = nil}
var unknownFields = SwiftProtobuf.UnknownStorage()
init() {}
@ -276,6 +285,74 @@ struct SessionProtos_KeyPair {
fileprivate var _privateKey: Data? = nil
}
struct SessionProtos_InfoMessage {
// 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.
/// @required
var type: SessionProtos_InfoMessage.TypeEnum {
get {return _type ?? .screenshot}
set {_type = newValue}
}
/// Returns true if `type` has been explicitly set.
var hasType: Bool {return self._type != nil}
/// Clears the value of `type`. Subsequent reads from it will return its default value.
mutating func clearType() {self._type = nil}
var timestamp: UInt64 {
get {return _timestamp ?? 0}
set {_timestamp = newValue}
}
/// Returns true if `timestamp` has been explicitly set.
var hasTimestamp: Bool {return self._timestamp != nil}
/// Clears the value of `timestamp`. Subsequent reads from it will return its default value.
mutating func clearTimestamp() {self._timestamp = nil}
var unknownFields = SwiftProtobuf.UnknownStorage()
enum TypeEnum: SwiftProtobuf.Enum {
typealias RawValue = Int
case screenshot // = 1
/// timestamp
case mediaSaved // = 2
init() {
self = .screenshot
}
init?(rawValue: Int) {
switch rawValue {
case 1: self = .screenshot
case 2: self = .mediaSaved
default: return nil
}
}
var rawValue: Int {
switch self {
case .screenshot: return 1
case .mediaSaved: return 2
}
}
}
init() {}
fileprivate var _type: SessionProtos_InfoMessage.TypeEnum? = nil
fileprivate var _timestamp: UInt64? = nil
}
#if swift(>=4.2)
extension SessionProtos_InfoMessage.TypeEnum: CaseIterable {
// Support synthesized by the compiler.
}
#endif // swift(>=4.2)
struct SessionProtos_DataMessage {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@ -1358,6 +1435,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
5: .same(proto: "receiptMessage"),
6: .same(proto: "typingMessage"),
7: .same(proto: "configurationMessage"),
82: .same(proto: "infoMessage"),
]
fileprivate class _StorageClass {
@ -1365,6 +1443,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
var _receiptMessage: SessionProtos_ReceiptMessage? = nil
var _typingMessage: SessionProtos_TypingMessage? = nil
var _configurationMessage: SessionProtos_ConfigurationMessage? = nil
var _infoMessage: SessionProtos_InfoMessage? = nil
static let defaultInstance = _StorageClass()
@ -1375,6 +1454,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
_receiptMessage = source._receiptMessage
_typingMessage = source._typingMessage
_configurationMessage = source._configurationMessage
_infoMessage = source._infoMessage
}
}
@ -1391,6 +1471,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
if let v = _storage._receiptMessage, !v.isInitialized {return false}
if let v = _storage._typingMessage, !v.isInitialized {return false}
if let v = _storage._configurationMessage, !v.isInitialized {return false}
if let v = _storage._infoMessage, !v.isInitialized {return false}
return true
}
}
@ -1404,6 +1485,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
case 5: try decoder.decodeSingularMessageField(value: &_storage._receiptMessage)
case 6: try decoder.decodeSingularMessageField(value: &_storage._typingMessage)
case 7: try decoder.decodeSingularMessageField(value: &_storage._configurationMessage)
case 82: try decoder.decodeSingularMessageField(value: &_storage._infoMessage)
default: break
}
}
@ -1424,6 +1506,9 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
if let v = _storage._configurationMessage {
try visitor.visitSingularMessageField(value: v, fieldNumber: 7)
}
if let v = _storage._infoMessage {
try visitor.visitSingularMessageField(value: v, fieldNumber: 82)
}
}
try unknownFields.traverse(visitor: &visitor)
}
@ -1437,6 +1522,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
if _storage._receiptMessage != rhs_storage._receiptMessage {return false}
if _storage._typingMessage != rhs_storage._typingMessage {return false}
if _storage._configurationMessage != rhs_storage._configurationMessage {return false}
if _storage._infoMessage != rhs_storage._infoMessage {return false}
return true
}
if !storagesAreEqual {return false}
@ -1487,6 +1573,53 @@ extension SessionProtos_KeyPair: SwiftProtobuf.Message, SwiftProtobuf._MessageIm
}
}
extension SessionProtos_InfoMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".InfoMessage"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "type"),
2: .same(proto: "timestamp"),
]
public var isInitialized: Bool {
if self._type == nil {return false}
return true
}
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
while let fieldNumber = try decoder.nextFieldNumber() {
switch fieldNumber {
case 1: try decoder.decodeSingularEnumField(value: &self._type)
case 2: try decoder.decodeSingularUInt64Field(value: &self._timestamp)
default: break
}
}
}
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
if let v = self._type {
try visitor.visitSingularEnumField(value: v, fieldNumber: 1)
}
if let v = self._timestamp {
try visitor.visitSingularUInt64Field(value: v, fieldNumber: 2)
}
try unknownFields.traverse(visitor: &visitor)
}
static func ==(lhs: SessionProtos_InfoMessage, rhs: SessionProtos_InfoMessage) -> Bool {
if lhs._type != rhs._type {return false}
if lhs._timestamp != rhs._timestamp {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
}
}
extension SessionProtos_InfoMessage.TypeEnum: SwiftProtobuf._ProtoNameProviding {
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1: .same(proto: "SCREENSHOT"),
2: .same(proto: "MEDIA_SAVED"),
]
}
extension SessionProtos_DataMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".DataMessage"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [

View file

@ -39,6 +39,7 @@ message Content {
optional ReceiptMessage receiptMessage = 5;
optional TypingMessage typingMessage = 6;
optional ConfigurationMessage configurationMessage = 7;
optional InfoMessage infoMessage = 82;
}
message KeyPair {
@ -48,6 +49,18 @@ message KeyPair {
required bytes privateKey = 2;
}
message InfoMessage {
enum Type {
SCREENSHOT = 1;
MEDIA_SAVED = 2; // timestamp
}
// @required
required Type type = 1;
optional uint64 timestamp = 2;
}
message DataMessage {
enum Flags {