mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Upload files in parallel
This commit is contained in:
parent
0773760c08
commit
64025fb65d
@ -5922,7 +5922,7 @@ Sorry for the inconvenience.";
|
||||
|
||||
"Conversation.AddMembers" = "Add Members";
|
||||
|
||||
"Conversation.ImportedMessageHint" = "The messages was imported from another app. We can't guarantee it's real.";
|
||||
"Conversation.ImportedMessageHint" = "This message was imported from another app. We can't guarantee it's real.";
|
||||
|
||||
"Conversation.GreetingText" = "Send a message or tap on the greeting below.";
|
||||
|
||||
@ -5933,7 +5933,7 @@ Sorry for the inconvenience.";
|
||||
"Conversation.AudioRateTooltipSpeedUp" = "The audio will now play 2 times faster.";
|
||||
"Conversation.AudioRateTooltipNormal" = "The audio will now play at normal speed.";
|
||||
|
||||
"ChatImport.Title" = "Import Chat";
|
||||
"ChatImport.Title" = "Select Chat";
|
||||
"ChatImport.SelectionErrorNotAdmin" = "You need to be an admin of the group to import messages into it.";
|
||||
"ChatImport.SelectionErrorGroupGeneric" = "You can't import history into this group.";
|
||||
"ChatImport.SelectionConfirmationGroupWithTitle" = "Are you sure you want to import messages from **%1$@** into **%2$@**?";
|
||||
@ -5956,5 +5956,6 @@ Sorry for the inconvenience.";
|
||||
"ChatImportActivity.InProgress" = "Please keep this window open\nduring the import.";
|
||||
"ChatImportActivity.ErrorNotAdmin" = "You need to be an admin.";
|
||||
"ChatImportActivity.ErrorInvalidChatType" = "You can't import this history in this type of chat.";
|
||||
"ChatImportActivity.ErrorUserBlocked" = "You need to be an admin.";
|
||||
"ChatImportActivity.ErrorGeneric" = "An error occurred.";
|
||||
"ChatImportActivity.Success" = "Chat imported\nsuccessfully.";
|
||||
|
@ -549,8 +549,8 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|> mapToSignal { session -> Signal<(String, Float), ImportError> in
|
||||
var importSignal: Signal<(String, Float), ImportError> = .single(("", 0.0))
|
||||
|> mapToSignal { session -> Signal<[(String, Float)], ImportError> in
|
||||
var mediaSignals: [Signal<(String, Float), ImportError>] = []
|
||||
|
||||
for (_, fileName, mediaType, fileData) in otherEntries {
|
||||
let unpackedFile: Signal<TempBoxFile, ImportError> = fileData.get()
|
||||
@ -588,27 +588,27 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
}
|
||||
}
|
||||
|
||||
importSignal = importSignal
|
||||
|> then(uploadedMedia)
|
||||
mediaSignals.append(Signal<(String, Float), ImportError>.single((fileName, 0.0))
|
||||
|> then(uploadedMedia))
|
||||
}
|
||||
|
||||
importSignal = importSignal
|
||||
return combineLatest(mediaSignals)
|
||||
|> then(ChatHistoryImport.startImport(account: context.account, session: session)
|
||||
|> mapError { _ -> ImportError in
|
||||
return .generic
|
||||
}
|
||||
|> map { _ -> (String, Float) in
|
||||
|> map { _ -> [(String, Float)] in
|
||||
})
|
||||
|
||||
return importSignal
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { [weak self] (fileName, progress) in
|
||||
|> deliverOnMainQueue).start(next: { [weak self] fileNameAndProgress in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
if let (fileSize, _) = strongSelf.pendingEntries[fileName] {
|
||||
strongSelf.pendingEntries[fileName] = (fileSize, progress)
|
||||
for (fileName, progress) in fileNameAndProgress {
|
||||
if let (fileSize, _) = strongSelf.pendingEntries[fileName] {
|
||||
strongSelf.pendingEntries[fileName] = (fileSize, progress)
|
||||
}
|
||||
}
|
||||
|
||||
var totalDoneBytes = strongSelf.mainEntrySize
|
||||
|
@ -104,7 +104,7 @@ public enum ChatHistoryImport {
|
||||
}
|
||||
|
||||
public static func uploadMedia(account: Account, session: Session, file: TempBoxFile, fileName: String, mimeType: String, type: MediaType) -> Signal<Float, UploadMediaError> {
|
||||
return multipartUpload(network: account.network, postbox: account.postbox, source: .tempFile(file), encrypt: false, tag: nil, hintFileSize: nil, hintFileIsLarge: false)
|
||||
return multipartUpload(network: account.network, postbox: account.postbox, source: .tempFile(file), encrypt: false, tag: nil, hintFileSize: nil, hintFileIsLarge: false, useLargerParts: true)
|
||||
|> mapError { _ -> UploadMediaError in
|
||||
return .generic
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ private final class MultipartUploadManager {
|
||||
|
||||
let state: MultipartUploadState
|
||||
|
||||
init(headerSize: Int32, data: Signal<MultipartUploadData, NoError>, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, hintFileIsLarge: Bool, uploadPart: @escaping (UploadPart) -> Signal<Void, UploadPartError>, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) {
|
||||
init(headerSize: Int32, data: Signal<MultipartUploadData, NoError>, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, hintFileIsLarge: Bool, useLargerParts: Bool, uploadPart: @escaping (UploadPart) -> Signal<Void, UploadPartError>, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) {
|
||||
self.dataSignal = data
|
||||
|
||||
var fileId: Int64 = 0
|
||||
@ -166,6 +166,10 @@ private final class MultipartUploadManager {
|
||||
self.defaultPartSize = 512 * 1024
|
||||
self.bigTotalParts = nil
|
||||
self.bigParts = true
|
||||
} else if useLargerParts {
|
||||
self.bigParts = false
|
||||
self.defaultPartSize = 64 * 1024
|
||||
self.bigTotalParts = nil
|
||||
} else {
|
||||
self.bigParts = false
|
||||
self.defaultPartSize = 16 * 1024
|
||||
@ -368,7 +372,7 @@ enum MultipartUploadError {
|
||||
case generic
|
||||
}
|
||||
|
||||
func multipartUpload(network: Network, postbox: Postbox, source: MultipartUploadSource, encrypt: Bool, tag: MediaResourceFetchTag?, hintFileSize: Int?, hintFileIsLarge: Bool) -> Signal<MultipartUploadResult, MultipartUploadError> {
|
||||
func multipartUpload(network: Network, postbox: Postbox, source: MultipartUploadSource, encrypt: Bool, tag: MediaResourceFetchTag?, hintFileSize: Int?, hintFileIsLarge: Bool, useLargerParts: Bool = false) -> Signal<MultipartUploadResult, MultipartUploadError> {
|
||||
return network.upload(tag: tag)
|
||||
|> mapToSignalPromotingError { download -> Signal<MultipartUploadResult, MultipartUploadError> in
|
||||
return Signal { subscriber in
|
||||
@ -419,7 +423,7 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload
|
||||
fetchedResource = .complete()
|
||||
}
|
||||
|
||||
let manager = MultipartUploadManager(headerSize: headerSize, data: dataSignal, encryptionKey: encryptionKey, hintFileSize: hintFileSize, hintFileIsLarge: hintFileIsLarge, uploadPart: { part in
|
||||
let manager = MultipartUploadManager(headerSize: headerSize, data: dataSignal, encryptionKey: encryptionKey, hintFileSize: hintFileSize, hintFileIsLarge: hintFileIsLarge, useLargerParts: useLargerParts, uploadPart: { part in
|
||||
return download.uploadPart(fileId: part.fileId, index: part.index, data: part.data, asBigPart: part.bigPart, bigTotalParts: part.bigTotalParts)
|
||||
}, progress: { progress in
|
||||
subscriber.putNext(.progress(progress))
|
||||
|
Loading…
x
Reference in New Issue
Block a user