session-ios/SessionMessagingKit/Utilities/SNProtoEnvelope+Conversion....

16 lines
513 B
Swift
Raw Normal View History

2020-11-11 00:58:56 +01:00
2020-11-16 00:34:47 +01:00
public extension SNProtoEnvelope {
2020-11-11 00:58:56 +01:00
2020-11-16 00:34:47 +01:00
static func from(_ json: JSON) -> SNProtoEnvelope? {
2020-11-11 00:58:56 +01:00
guard let base64EncodedData = json["data"] as? String, let data = Data(base64Encoded: base64EncodedData) else {
2020-11-20 00:14:35 +01:00
SNLog("Failed to decode data for message: \(json).")
2020-11-11 00:58:56 +01:00
return nil
}
guard let result = try? MessageWrapper.unwrap(data: data) else {
2020-11-20 00:14:35 +01:00
SNLog("Failed to unwrap data for message: \(json).")
2020-11-11 00:58:56 +01:00
return nil
}
return result
}
}