session-ios/SessionMessagingKit/Utilities/Promise+Utilities.swift
Morgan Pretty eeccfb47d5 Fixed all of the build errors from merge, migrated Call logic, started idBlinding migration and bug fixes
Fixed some broken file paths
Fixed a couple of bugs with closed groups
Fixed a few migration issues
Fixed a bug with the ProfilePictureView in open groups (was including the open parenthesis in the initials)
Migrated the Id Blinding changes to work with GRDB
Migrated the call logic to work with GRDB
Updated the code to work the with hard fork changes
2022-06-09 18:37:44 +10:00

30 lines
1.1 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import PromiseKit
import SessionSnodeKit
import SessionUtilitiesKit
extension Promise where T == Data {
func decoded<R: Decodable>(as type: R.Type, on queue: DispatchQueue? = nil, using dependencies: Dependencies = Dependencies()) -> Promise<R> {
self.map(on: queue) { data -> R in
try data.decoded(as: type, using: dependencies)
}
}
}
extension Promise where T == (OnionRequestResponseInfoType, Data?) {
func decoded<R: Decodable>(as type: R.Type, on queue: DispatchQueue? = nil, using dependencies: Dependencies = Dependencies()) -> Promise<(OnionRequestResponseInfoType, R)> {
self.map(on: queue) { responseInfo, maybeData -> (OnionRequestResponseInfoType, R) in
guard let data: Data = maybeData else { throw HTTP.Error.parsingFailed }
do {
return (responseInfo, try data.decoded(as: type, using: dependencies))
}
catch {
throw HTTP.Error.parsingFailed
}
}
}
}