Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 11
Feature/issue 783 unlimited attachment size#893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8b1c34b44343b82cb45aa14d27d6f020ca5763ac4bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -148,13 +148,17 @@ final class MessageViewController: TableNodeViewController { | ||
| } | ||
| // MARK: - Message | ||
| extension MessageViewController { | ||
| private func fetchDecryptAndRenderMsg() { | ||
| showSpinner("loading_title".localized, isUserInteractionEnabled: true) | ||
| handleFetchProgress(state: .fetch) | ||
| Task { | ||
| do { | ||
| processedMessage = try await serviceActor.fetchDecryptAndRenderMsg(message: input.objMessage, path: input.path) | ||
| processedMessage = try await serviceActor.fetchDecryptAndRenderMsg(message: input.objMessage, | ||
| path: input.path, | ||
| progressHandler: { [weak self] state in | ||
| self?.handleFetchProgress(state: state) | ||
| }) | ||
| handleReceivedMessage() | ||
| } catch { | ||
| handleError(error) | ||
| @@ -179,6 +183,17 @@ extension MessageViewController { | ||
| } | ||
| } | ||
| private func handleFetchProgress(state: MessageFetchState) { | ||
| switch state { | ||
| case .fetch: | ||
| showSpinner("loading_title".localized, isUserInteractionEnabled: true) | ||
| case .download(let progress): | ||
| updateSpinner(label: "downloading_title".localized, progress: progress) | ||
| case .decrypt: | ||
| updateSpinner(label: "decrypting_title".localized) | ||
| } | ||
| } | ||
| private func handleReceivedMessage() { | ||
| hideSpinner() | ||
| node.reloadData() | ||
| @@ -539,16 +554,20 @@ private actor ServiceActor { | ||
| self.messageProvider = messageProvider | ||
| } | ||
| func fetchDecryptAndRenderMsg(message: Message, path: String) async throws -> ProcessedMessage { | ||
| let rawMimeData = try awaitPromise(messageProvider.fetchMsg(message: message, folder: path)) | ||
| func fetchDecryptAndRenderMsg(message: Message, path: String, | ||
| progressHandler: ((MessageFetchState) -> Void)?) async throws -> ProcessedMessage { | ||
| let rawMimeData = try await messageProvider.fetchMsg(message: message, | ||
| folder: path, | ||
| progressHandler: progressHandler) | ||
| progressHandler?(.decrypt) | ||
| return try await messageService.decryptAndProcessMessage(mime: rawMimeData) | ||
| } | ||
| func checkAndPotentiallySaveEnteredPassPhrase(_ passPhrase: String) async throws -> Bool { | ||
| return try await messageService.checkAndPotentiallySaveEnteredPassPhrase(passPhrase) | ||
| try await messageService.checkAndPotentiallySaveEnteredPassPhrase(passPhrase) | ||
| } | ||
| func decryptAndProcessMessage(mime: Data) async throws -> ProcessedMessage { | ||
| return try await messageService.decryptAndProcessMessage(mime: mime) | ||
| try await messageService.decryptAndProcessMessage(mime: mime) | ||
| } | ||
Comment on lines
-570
to
-572
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like explicit returns for the clarity :-) but don't insist. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,7 +5,6 @@ | ||
| import AsyncDisplayKit | ||
| import ENSwiftSideMenu | ||
| import FlowCryptUI | ||
| import Promises | ||
| /** | ||
| * Menu view controller | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,7 +8,6 @@ | ||
| import FlowCryptCommon | ||
| import Foundation | ||
| import Promises | ||
| import RealmSwift | ||
| // swiftlint:disable force_try | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,35 +7,86 @@ | ||
| // | ||
| import GoogleAPIClientForREST_Gmail | ||
| import Promises | ||
| import GTMSessionFetcherCore | ||
| extension GmailService: MessageProvider { | ||
| func fetchMsg(message: Message, folder: String) -> Promise<Data> { | ||
| Promise { resolve, reject in | ||
| func fetchMsg(message: Message, | ||
| folder: String, | ||
| progressHandler: ((MessageFetchState) -> Void)?) async throws -> Data { | ||
| try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Data, Error>) in | ||
| guard let identifier = message.identifier.stringId else { | ||
| return reject(GmailServiceError.missedMessageInfo("id")) | ||
| continuation.resume(throwing: GmailServiceError.missedMessageInfo("id")) | ||
| return | ||
| } | ||
| let query = GTLRGmailQuery_UsersMessagesGet.query(withUserId: .me, identifier: identifier) | ||
| query.format = kGTLRGmailFormatRaw | ||
| Task { | ||
| let messageSize = try await self.fetchMessageSize(identifier: identifier) | ||
| let fetcher = self.createMessageFetcher(identifier: identifier) | ||
| fetcher.receivedProgressBlock = { _, received in | ||
| let progress = min(Float(received)/messageSize, 1) | ||
| progressHandler?(.download(progress)) | ||
| } | ||
| fetcher.beginFetch { data, error in | ||
| if let error = error { | ||
| continuation.resume(throwing: GmailServiceError.providerError(error)) | ||
| return | ||
| } | ||
| guard let data = data, | ||
| let dictionary = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], | ||
| let raw = dictionary["raw"] as? String | ||
| else { | ||
| continuation.resume(throwing: GmailServiceError.missedMessageInfo("raw")) | ||
| return | ||
| } | ||
| guard let data = GTLRDecodeWebSafeBase64(raw) else { | ||
| continuation.resume(throwing: GmailServiceError.missedMessageInfo("data")) | ||
| return | ||
| } | ||
| continuation.resume(returning: data) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| private func fetchMessageSize(identifier: String) async throws -> Float { | ||
| try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Float, Error>) in | ||
| let query = createMessageQuery(identifier: identifier, format: kGTLRGmailFormatMetadata) | ||
| self.gmailService.executeQuery(query) { _, data, error in | ||
| if let error = error { | ||
| reject(GmailServiceError.providerError(error)) | ||
| continuation.resume(throwing: GmailServiceError.providerError(error)) | ||
| return | ||
| } | ||
| guard let gmailMessage = data as? GTLRGmail_Message else { | ||
| return reject(AppErr.cast("GTLRGmail_Message")) | ||
| } | ||
| guard let raw = gmailMessage.raw else { | ||
| return reject(GmailServiceError.missedMessageInfo("raw")) | ||
| continuation.resume(throwing: AppErr.cast("GTLRGmail_Message")) | ||
| return | ||
| } | ||
| guard let data = GTLRDecodeWebSafeBase64(raw) else { | ||
| return reject(GmailServiceError.missedMessageInfo("data")) | ||
| guard let sizeEstimate = gmailMessage.sizeEstimate?.floatValue else { | ||
| continuation.resume(throwing: GmailServiceError.missedMessageInfo("sizeEstimate")) | ||
| return | ||
| } | ||
| resolve(data) | ||
| // google returns smaller estimated size | ||
| let totalSize = sizeEstimate * Float(1.3) | ||
tomholub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| continuation.resume(with: .success(totalSize)) | ||
| } | ||
| } | ||
| } | ||
| private func createMessageFetcher(identifier: String) -> GTMSessionFetcher { | ||
| let query = createMessageQuery(identifier: identifier, format: kGTLRGmailFormatRaw) | ||
| let request = gmailService.request(for: query) as URLRequest | ||
| return gmailService.fetcherService.fetcher(with: request) | ||
| } | ||
| private func createMessageQuery(identifier: String, format: String) -> GTLRGmailQuery_UsersMessagesGet { | ||
| let query = GTLRGmailQuery_UsersMessagesGet.query(withUserId: .me, identifier: identifier) | ||
| query.format = format | ||
| return query | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A detail - I'd prefer formatting like:
Else all of the inputs have no space due to large indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll use such formatting in the next commits