mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
# Conflicts: # Session/Conversations/ConversationVC+Interaction.swift # Session/Conversations/ConversationVC.swift # Session/Conversations/Settings/ThreadSettingsViewModel.swift # Session/Home/GlobalSearch/GlobalSearchViewController.swift # Session/Meta/AppDelegate.swift # SessionMessagingKit/Open Groups/OpenGroupManager.swift # SessionMessagingKit/Sending & Receiving/MessageReceiver.swift # SessionMessagingKit/Utilities/MessageWrapper.swift
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
// stringlint:disable
|
|
|
|
import Foundation
|
|
import SessionNetworkingKit
|
|
import SessionUtilitiesKit
|
|
|
|
public enum MessageWrapperError: Error, CustomStringConvertible {
|
|
case failedToUnwrapData(Error, Network.SnodeAPI.Namespace)
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .failedToUnwrapData(let error, let namespace):
|
|
return "Failed to unwrap data from '\(namespace)' namespace due to error: \(error)."
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum MessageWrapper {
|
|
|
|
/// - Note: `data` shouldn't be base 64 encoded.
|
|
public static func unwrap(
|
|
data: Data,
|
|
namespace: Network.SnodeAPI.Namespace,
|
|
includesWebSocketMessage: Bool = true
|
|
) throws -> SNProtoEnvelope {
|
|
do {
|
|
let envelopeData: Data = try {
|
|
guard includesWebSocketMessage else { return data }
|
|
|
|
let webSocketMessage = try WebSocketProtoWebSocketMessage.parseData(data)
|
|
return webSocketMessage.request!.body!
|
|
}()
|
|
return try SNProtoEnvelope.parseData(envelopeData)
|
|
} catch let error {
|
|
throw MessageWrapperError.failedToUnwrapData(error, namespace)
|
|
}
|
|
}
|
|
}
|