Before

…lines 1–18 unchanged (18 lines)
19 var bannerToken: Int = 0
20 var currentUploadTask: Task<(account: String, file: NKFile?, error: NKError), Never>?
21 var request: UploadRequest?
22
23 @discardableResult
24 @MainActor
25 func upload(metadata: tableMetadata, session: NCSession.Session? = nil, controller: UIViewController? = nil, scene: UIWindowScene? = nil) async -> NKError {
26 var finalError: NKError = .success
27 var session = session
28 let ocId = metadata.ocIdTransfer
29
30 if session == nil {
31 session = NCSession.shared.getSession(account: metadata.account)
32 }
33 guard let session,
34 !session.account.isEmpty else {
35 return NKError(errorCode: NCGlobal.shared.errorNCSessionNotFound, errorDescription: NSLocalizedString("_e2e_error_", comment: ""))
36 }
37
38 // BANNER ENCRYPTION
39 //
40 bannerToken = showUploadBanner(scene: scene,
41 title: NSLocalizedString("_wait_file_encryption_", comment: ""),
42 subtitle: NSLocalizedString("_e2ee_upload_tip_", comment: ""),
43 systemImage: "lock.circle.fill",
44 vPosition: .bottom,
45 verticalMargin: 55) { _, _ in
46 if let currentUploadTask = self.currentUploadTask {
47 currentUploadTask.cancel()
48 }
49 if let request = self.request {
50 request.cancel()
51 }
52 LucidBanner.shared.dismiss()
53 }
54
55 defer {
56 if finalError != .success {
57 Task {
58 await self.database.deleteMetadataAsync(id: ocId)
59 }
…lines 60–149 unchanged (90 lines)
150 resultsLock.error == .success
151 else {
152 await self.database.deleteMetadataAsync(predicate: NSPredicate(format: "ocIdTransfer == %@", metadata.ocIdTransfer))
153 finalError = NKError(errorCode: NCGlobal.shared.errorE2EELock, errorDescription: NSLocalizedString("_e2e_error_", comment: ""))
154 return finalError
155 }
156
157 // SEND NEW METADATA
158 //
159 let sendE2eeError = await sendE2ee(e2eToken: e2eToken, fileId: fileId)
160 guard sendE2eeError == .success else {
161 await self.database.deleteMetadataAsync(predicate: NSPredicate(format: "ocIdTransfer == %@", metadata.ocIdTransfer))
162 await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)
…lines 163–298 unchanged (136 lines)

After

…lines 1–18 unchanged (18 lines)
19 var bannerToken: Int = 0
20 var currentUploadTask: Task<(account: String, file: NKFile?, error: NKError), Never>?
21 var request: UploadRequest?
22
23 @discardableResult
24 @MainActor
25 func upload(metadata: tableMetadata, session: NCSession.Session? = nil, controller: UIViewController? = nil, scene: UIWindowScene? = nil, externalBannerToken: Int? = nil) async -> NKError {
26 var finalError: NKError = .success
27 var session = session
28 let ocId = metadata.ocIdTransfer
29
30 if session == nil {
31 session = NCSession.shared.getSession(account: metadata.account)
32 }
33 guard let session,
34 !session.account.isEmpty else {
35 return NKError(errorCode: NCGlobal.shared.errorNCSessionNotFound, errorDescription: NSLocalizedString("_e2e_error_", comment: ""))
36 }
37
38 defer {
39 if finalError != .success {
40 Task {
41 await self.database.deleteMetadataAsync(id: ocId)
42 }
43 }
…lines 44–133 unchanged (90 lines)
134 else {
135 await self.database.deleteMetadataAsync(predicate: NSPredicate(format: "ocIdTransfer == %@", metadata.ocIdTransfer))
136 finalError = NKError(errorCode: NCGlobal.shared.errorE2EELock, errorDescription: NSLocalizedString("_e2e_error_", comment: ""))
137 return finalError
138 }
139
140 // BANNER
141 //
142 if let externalBannerToken {
143 bannerToken = externalBannerToken
144 } else {
145 bannerToken = showUploadBanner(scene: scene,
146 vPosition: .bottom,
147 verticalMargin: 55,
148 onButtonTap: {
149 if let currentUploadTask = self.currentUploadTask {
150 currentUploadTask.cancel()
151 }
152 if let request = self.request {
153 request.cancel()
154 }
155 LucidBanner.shared.dismiss()
156 })
157 }
158
159 LucidBanner.shared.update(title: NSLocalizedString("_wait_file_encryption_", comment: ""),
160 subtitle: NSLocalizedString("_e2ee_upload_tip_", comment: ""),
161 systemImage: "lock.circle.fill",
162 for: bannerToken)
163
164 // SEND NEW METADATA
165 //
166 let sendE2eeError = await sendE2ee(e2eToken: e2eToken, fileId: fileId)
167 guard sendE2eeError == .success else {
168 await self.database.deleteMetadataAsync(predicate: NSPredicate(format: "ocIdTransfer == %@", metadata.ocIdTransfer))
…lines 169–305 unchanged (137 lines)

Before

source_file
comment "// SPDX-FileCopyrightText: Nextcloud GmbH"
comment "// SPDX-FileCopyrightText: 2022 Marino Faggiana"
comment "// SPDX-License-Identifier: GPL-3.0-or-later"
import_declaration
import "import"
identifier
simple_identifier "UIKit"
import_declaration
import "import"
identifier
simple_identifier "NextcloudKit"
import_declaration
import "import"
identifier
simple_identifier "CFNetwork"
import_declaration
import "import"
identifier
simple_identifier "Alamofire"
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "LucidBanner"
class_declaration
class "class"
type_identifier "NCNetworkingE2EEUpload"
: ":"
inheritance_specifier
user_type
type_identifier "NSObject"
class_body
{ "{"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "networkingE2EE"
= "="
call_expression
simple_identifier "NCNetworkingE2EE"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "utilityFileSystem"
= "="
call_expression
simple_identifier "NCUtilityFileSystem"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "global"
= "="
navigation_expression
simple_identifier "NCGlobal"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "utility"
= "="
call_expression
simple_identifier "NCUtility"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "database"
= "="
navigation_expression
simple_identifier "NCManageDatabase"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "numChunks"
type_annotation
: ":"
user_type
type_identifier "Int"
= "="
integer_literal "0"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "bannerToken"
type_annotation
: ":"
user_type
type_identifier "Int"
= "="
integer_literal "0"
property_declaration (+41 nodes collapsed)
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "request"
type_annotation
: ":"
optional_type
user_type
type_identifier "UploadRequest"
?
? "?"
function_declaration
modifiers
attribute
@ "@"
user_type
type_identifier "discardableResult"
attribute
@ "@"
user_type
type_identifier "MainActor"
func "func"
simple_identifier "upload"
( "("
parameter
simple_identifier "metadata"
: ":"
user_type
type_identifier "tableMetadata"
, ","
parameter
simple_identifier "session"
: ":"
optional_type
user_type
type_identifier "NCSession"
. "."
type_identifier "Session"
?
? "?"
= "="
nil "nil"
, ","
parameter
simple_identifier "controller"
: ":"
optional_type
user_type
type_identifier "UIViewController"
?
? "?"
= "="
nil "nil"
, ","
parameter
simple_identifier "scene"
: ":"
optional_type
user_type
type_identifier "UIWindowScene"
?
? "?"
= "="
nil "nil"
) ")"
async "async"
-> "->"
user_type
type_identifier "NKError"
function_body
{ "{"
statements
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "finalError"
type_annotation
: ":"
user_type
type_identifier "NKError"
= "="
prefix_expression
. "."
simple_identifier "success"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "session"
= "="
simple_identifier "session"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "ocId"
= "="
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "ocIdTransfer"
if_statement (+36 nodes collapsed)
guard_statement (+66 nodes collapsed)
comment "// BANNER ENCRYPTION"
comment "//"
assignment
directly_assignable_expression
simple_identifier "bannerToken"
= "="
call_expression
simple_identifier "showUploadBanner"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "scene"
: ":"
simple_identifier "scene"
, ","
value_argument (+23 nodes collapsed)
, ","
value_argument (+23 nodes collapsed)
, ","
value_argument
value_argument_label
simple_identifier "systemImage"
: ":"
line_string_literal
" "\""
line_str_text "lock.circle.fill"
" "\""
, ","
value_argument
value_argument_label
simple_identifier "vPosition"
: ":"
prefix_expression
. "."
simple_identifier "bottom"
, ","
value_argument
value_argument_label
simple_identifier "verticalMargin"
: ":"
integer_literal "55"
) ")"
lambda_literal
{ "{"
lambda_function_type
lambda_function_type_parameters
lambda_parameter
simple_identifier "_"
, ","
lambda_parameter
simple_identifier "_"
in "in"
statements (+65 nodes collapsed)
} "}"
call_expression (+61 nodes collapsed)
if_statement (+100 nodes collapsed)
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "session"
= "="
navigation_expression
navigation_expression
simple_identifier "NCNetworking"
navigation_suffix
. "."
simple_identifier "shared"
navigation_suffix
. "."
simple_identifier "sessionUpload"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "status"
= "="
navigation_expression
simple_identifier "global"
navigation_suffix
. "."
simple_identifier "metadataStatusUploading"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "sessionError"
= "="
line_string_literal
" "\""
" "\""
assignment (+37 nodes collapsed)
guard_statement (+34 nodes collapsed)
guard_statement (+109 nodes collapsed)
function_declaration (+868 nodes collapsed)
comment "// LOCK"
comment "//"
property_declaration (+37 nodes collapsed)
guard_statement (+128 nodes collapsed)
comment "// SEND NEW METADATA"
comment "//"
property_declaration (+25 nodes collapsed)
guard_statement (+93 nodes collapsed)
comment "// UPLOAD"
comment "//"
property_declaration (+31 nodes collapsed)
comment "// UNLOCK"
comment "//"
await_expression (+31 nodes collapsed)
if_statement (+475 nodes collapsed)
assignment
directly_assignable_expression
simple_identifier "finalError"
= "="
navigation_expression
simple_identifier "resultsSendFile"
navigation_suffix
. "."
simple_identifier "error"
control_transfer_statement
return "return"
simple_identifier "finalError"
} "}"
function_declaration (+1048 nodes collapsed)
} "}"

After

source_file
comment "// SPDX-FileCopyrightText: Nextcloud GmbH"
comment "// SPDX-FileCopyrightText: 2022 Marino Faggiana"
comment "// SPDX-License-Identifier: GPL-3.0-or-later"
import_declaration
import "import"
identifier
simple_identifier "UIKit"
import_declaration
import "import"
identifier
simple_identifier "NextcloudKit"
import_declaration
import "import"
identifier
simple_identifier "CFNetwork"
import_declaration
import "import"
identifier
simple_identifier "Alamofire"
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "LucidBanner"
class_declaration
class "class"
type_identifier "NCNetworkingE2EEUpload"
: ":"
inheritance_specifier
user_type
type_identifier "NSObject"
class_body
{ "{"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "networkingE2EE"
= "="
call_expression
simple_identifier "NCNetworkingE2EE"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "utilityFileSystem"
= "="
call_expression
simple_identifier "NCUtilityFileSystem"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "global"
= "="
navigation_expression
simple_identifier "NCGlobal"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "utility"
= "="
call_expression
simple_identifier "NCUtility"
call_suffix
value_arguments
( "("
) ")"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "database"
= "="
navigation_expression
simple_identifier "NCManageDatabase"
navigation_suffix
. "."
simple_identifier "shared"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "numChunks"
type_annotation
: ":"
user_type
type_identifier "Int"
= "="
integer_literal "0"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "bannerToken"
type_annotation
: ":"
user_type
type_identifier "Int"
= "="
integer_literal "0"
property_declaration (+41 nodes collapsed)
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "request"
type_annotation
: ":"
optional_type
user_type
type_identifier "UploadRequest"
?
? "?"
function_declaration
modifiers
attribute
@ "@"
user_type
type_identifier "discardableResult"
attribute
@ "@"
user_type
type_identifier "MainActor"
func "func"
simple_identifier "upload"
( "("
parameter
simple_identifier "metadata"
: ":"
user_type
type_identifier "tableMetadata"
, ","
parameter
simple_identifier "session"
: ":"
optional_type
user_type
type_identifier "NCSession"
. "."
type_identifier "Session"
?
? "?"
= "="
nil "nil"
, ","
parameter
simple_identifier "controller"
: ":"
optional_type
user_type
type_identifier "UIViewController"
?
? "?"
= "="
nil "nil"
, ","
parameter
simple_identifier "scene"
: ":"
optional_type
user_type
type_identifier "UIWindowScene"
?
? "?"
= "="
nil "nil"
, ","
parameter
simple_identifier "externalBannerToken"
: ":"
optional_type
user_type
type_identifier "Int"
?
? "?"
= "="
nil "nil"
) ")"
async "async"
-> "->"
user_type
type_identifier "NKError"
function_body
{ "{"
statements
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "finalError"
type_annotation
: ":"
user_type
type_identifier "NKError"
= "="
prefix_expression
. "."
simple_identifier "success"
property_declaration
value_binding_pattern
var "var"
pattern
simple_identifier "session"
= "="
simple_identifier "session"
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "ocId"
= "="
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "ocIdTransfer"
if_statement (+36 nodes collapsed)
guard_statement (+66 nodes collapsed)
call_expression (+61 nodes collapsed)
if_statement (+100 nodes collapsed)
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "session"
= "="
navigation_expression
navigation_expression
simple_identifier "NCNetworking"
navigation_suffix
. "."
simple_identifier "shared"
navigation_suffix
. "."
simple_identifier "sessionUpload"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "status"
= "="
navigation_expression
simple_identifier "global"
navigation_suffix
. "."
simple_identifier "metadataStatusUploading"
assignment
directly_assignable_expression
navigation_expression
simple_identifier "metadata"
navigation_suffix
. "."
simple_identifier "sessionError"
= "="
line_string_literal
" "\""
" "\""
assignment (+37 nodes collapsed)
guard_statement (+34 nodes collapsed)
guard_statement (+109 nodes collapsed)
function_declaration (+868 nodes collapsed)
comment "// LOCK"
comment "//"
property_declaration (+37 nodes collapsed)
guard_statement (+128 nodes collapsed)
comment "// BANNER"
comment "//"
if_statement
if "if"
value_binding_pattern
let "let"
simple_identifier "externalBannerToken"
{ "{"
statements
assignment
directly_assignable_expression
simple_identifier "bannerToken"
= "="
simple_identifier "externalBannerToken"
} "}"
else "else"
{ "{"
statements
assignment
directly_assignable_expression
simple_identifier "bannerToken"
= "="
call_expression
simple_identifier "showUploadBanner"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "scene"
: ":"
simple_identifier "scene"
, ","
value_argument
value_argument_label
simple_identifier "vPosition"
: ":"
prefix_expression
. "."
simple_identifier "bottom"
, ","
value_argument
value_argument_label
simple_identifier "verticalMargin"
: ":"
integer_literal "55"
, ","
value_argument
value_argument_label
simple_identifier "onButtonTap"
: ":"
lambda_literal
{ "{"
statements (+65 nodes collapsed)
} "}"
) ")"
} "}"
call_expression
navigation_expression
navigation_expression
simple_identifier "LucidBanner"
navigation_suffix
. "."
simple_identifier "shared"
navigation_suffix
. "."
simple_identifier "update"
call_suffix
value_arguments
( "("
value_argument (+23 nodes collapsed)
, ","
value_argument (+23 nodes collapsed)
, ","
value_argument
value_argument_label
simple_identifier "systemImage"
: ":"
line_string_literal
" "\""
line_str_text "lock.circle.fill"
" "\""
, ","
value_argument
value_argument_label
simple_identifier "for"
: ":"
simple_identifier "bannerToken"
) ")"
comment "// SEND NEW METADATA"
comment "//"
property_declaration (+25 nodes collapsed)
guard_statement (+93 nodes collapsed)
comment "// UPLOAD"
comment "//"
property_declaration (+31 nodes collapsed)
comment "// UNLOCK"
comment "//"
await_expression (+31 nodes collapsed)
if_statement (+475 nodes collapsed)
assignment
directly_assignable_expression
simple_identifier "finalError"
= "="
navigation_expression
simple_identifier "resultsSendFile"
navigation_suffix
. "."
simple_identifier "error"
control_transfer_statement
return "return"
simple_identifier "finalError"
} "}"
function_declaration (+1048 nodes collapsed)
} "}"