session-ios/SignalUtilitiesKit/Messaging/SNProtoEnvelope+Conversion....

16 lines
527 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 {
print("[Loki] Failed to decode data for message: \(json).")
return nil
}
guard let result = try? MessageWrapper.unwrap(data: data) else {
print("[Loki] Failed to unwrap data for message: \(json).")
return nil
}
return result
}
}