Before

1// SPDX-FileCopyrightText: Nextcloud GmbH
2// SPDX-FileCopyrightText: 2025 Marino Faggiana
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5import Foundation
6import UIKit
7import NextcloudKit
8import Alamofire
9
10extension NCNetworking: NextcloudKitDelegate {
11
12 // MARK: - Download NextcloudKitDelegate
13
14 func downloadComplete(fileName: String,
15 serverUrl: String,
16 etag: String?,
17 date: Date?,
18 dateLastModified: Date?,
19 length: Int64,
20 task: URLSessionTask,
21 error: NKError) {
22 Task {
23 await progressQuantizer.clear(serverUrlFileName: serverUrl + "/" + fileName)
24
25#if EXTENSION_FILE_PROVIDER_EXTENSION || EXTENSION_FILE_PROVIDER_EXTENSION_UI
26 await FileProviderData.shared.downloadComplete(fileName: fileName,
27 serverUrl: serverUrl,
28 etag: etag,
29 date: date,
30 dateLastModified: dateLastModified,
31 length: length,
…lines 32–128 unchanged (97 lines)
129 if isInBackground() {
130 await self.uploadSuccess(withMetadata: metadata,
131 ocId: ocId,
132 etag: etag,
133 date: date)
134 } else {
135 await NCNetworking.shared.metadataTranfersSuccess.append(metadata: metadata,
136 ocId: ocId,
137 date: date,
138 etag: etag)
139 }
140 } else {
141 await NCManageDatabase.shared.deleteMetadataAsync(predicate: NSPredicate(format: "fileName == %@ AND serverUrl == %@", fileName, serverUrl))
142 }
143 } else {
144 await uploadError(withMetadata: metadata, error: error)
145 }
…lines 146–172 unchanged (27 lines)

After

1// SPDX-FileCopyrightText: Nextcloud GmbH
2// SPDX-FileCopyrightText: 2025 Marino Faggiana
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5import Foundation
6import UIKit
7import NextcloudKit
8import Alamofire
9
10extension NCNetworking {
11
12#if !EXTENSION_FILE_PROVIDER_EXTENSION
13 func networkReachabilityObserver(_ typeReachability: NKTypeReachability) {
14 if typeReachability == NKTypeReachability.reachableCellular || typeReachability == NKTypeReachability.reachableEthernetOrWiFi {
15 lastReachability = true
16 } else {
17 if lastReachability {
18 let error = NKError(errorCode: global.errorNetworkNotAvailable, errorDescription: "")
19 NCContentPresenter().messageNotification("_network_not_available_", error: error, delay: global.dismissAfterSecond, type: NCContentPresenter.messageType.info)
20 }
21 lastReachability = false
22 }
23 networkReachability = typeReachability
24 NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterNetworkReachability, userInfo: nil)
25 }
26#endif
27
28 // MARK: - Download NextcloudKitDelegate
29
30 func downloadComplete(fileName: String,
31 serverUrl: String,
32 etag: String?,
33 date: Date?,
34 dateLastModified: Date?,
35 length: Int64,
36 task: URLSessionTask,
37 error: NKError) {
38 Task {
39 await progressQuantizer.clear(serverUrlFileName: serverUrl + "/" + fileName)
40
41#if EXTENSION_FILE_PROVIDER_EXTENSION
42 await FileProviderData.shared.downloadComplete(fileName: fileName,
43 serverUrl: serverUrl,
44 etag: etag,
45 date: date,
46 dateLastModified: dateLastModified,
47 length: length,
48 task: task,
…lines 49–144 unchanged (96 lines)
145 if isInBackground() {
146 await self.uploadSuccess(withMetadata: metadata,
147 ocId: ocId,
148 etag: etag,
149 date: date)
150 } else {
151#if !EXTENSION
152 await NCNetworking.shared.metadataTranfersSuccess.append(metadata: metadata,
153 ocId: ocId,
154 date: date,
155 etag: etag)
156#endif
157 }
158 } else {
159 await NCManageDatabase.shared.deleteMetadataAsync(predicate: NSPredicate(format: "fileName == %@ AND serverUrl == %@", fileName, serverUrl))
160 }
161 } else {
162 await uploadError(withMetadata: metadata, error: error)
…lines 163–190 unchanged (28 lines)

Before

source_file
comment "// SPDX-FileCopyrightText: Nextcloud GmbH"
comment "// SPDX-FileCopyrightText: 2025 Marino Faggiana"
comment "// SPDX-License-Identifier: GPL-3.0-or-later"
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "UIKit"
import_declaration
import "import"
identifier
simple_identifier "NextcloudKit"
import_declaration
import "import"
identifier
simple_identifier "Alamofire"
class_declaration
extension "extension"
user_type
type_identifier "NCNetworking"
: ":"
inheritance_specifier
user_type
type_identifier "NextcloudKitDelegate"
class_body
{ "{"
comment "// MARK: - Download NextcloudKitDelegate"
function_declaration
func "func"
simple_identifier "downloadComplete"
( "("
parameter
simple_identifier "fileName"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "serverUrl"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "etag"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "date"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "dateLastModified"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "length"
: ":"
user_type
type_identifier "Int64"
, ","
parameter
simple_identifier "task"
: ":"
user_type
type_identifier "URLSessionTask"
, ","
parameter
simple_identifier "error"
: ":"
user_type
type_identifier "NKError"
) ")"
function_body
{ "{"
statements
call_expression
simple_identifier "Task"
call_suffix
lambda_literal
{ "{"
statements
await_expression (+26 nodes collapsed)
directive
#if "#if"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION"
|| "||"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION_UI"
await_expression (+63 nodes collapsed)
directive
#else "#else"
guard_statement (+52 nodes collapsed)
if_statement (+53 nodes collapsed)
directive
#endif "#endif"
} "}"
} "}"
function_declaration (+433 nodes collapsed)
function_declaration (+167 nodes collapsed)
comment "// MARK: - Upload NextcloudKitDelegate"
function_declaration
func "func"
simple_identifier "uploadComplete"
( "("
parameter
simple_identifier "fileName"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "serverUrl"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "ocId"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "etag"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "date"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "size"
: ":"
user_type
type_identifier "Int64"
, ","
parameter
simple_identifier "task"
: ":"
user_type
type_identifier "URLSessionTask"
, ","
parameter
simple_identifier "error"
: ":"
user_type
type_identifier "NKError"
) ")"
function_body
{ "{"
statements
call_expression
simple_identifier "Task"
call_suffix
lambda_literal
{ "{"
statements
await_expression (+26 nodes collapsed)
directive
#if "#if"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION"
await_expression (+63 nodes collapsed)
directive
#else "#else"
guard_statement (+99 nodes collapsed)
if_statement
if "if"
equality_expression
simple_identifier "error"
== "=="
prefix_expression
. "."
simple_identifier "success"
{ "{"
statements
if_statement
if "if"
value_binding_pattern
let "let"
simple_identifier "ocId"
{ "{"
statements
if_statement
if "if"
call_expression
simple_identifier "isInBackground"
call_suffix
value_arguments
( "("
) ")"
{ "{"
statements (+37 nodes collapsed)
} "}"
else "else"
{ "{"
statements
await_expression (+43 nodes collapsed)
} "}"
} "}"
else "else"
{ "{"
statements (+41 nodes collapsed)
} "}"
} "}"
else "else"
{ "{"
statements
await_expression
await "await"
call_expression
simple_identifier "uploadError"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "withMetadata"
: ":"
simple_identifier "metadata"
, ","
value_argument
value_argument_label
simple_identifier "error"
: ":"
simple_identifier "error"
) ")"
} "}"
directive
#endif "#endif"
} "}"
} "}"
function_declaration (+167 nodes collapsed)
} "}"

After

source_file
comment "// SPDX-FileCopyrightText: Nextcloud GmbH"
comment "// SPDX-FileCopyrightText: 2025 Marino Faggiana"
comment "// SPDX-License-Identifier: GPL-3.0-or-later"
import_declaration
import "import"
identifier
simple_identifier "Foundation"
import_declaration
import "import"
identifier
simple_identifier "UIKit"
import_declaration
import "import"
identifier
simple_identifier "NextcloudKit"
import_declaration
import "import"
identifier
simple_identifier "Alamofire"
class_declaration
extension "extension"
user_type
type_identifier "NCNetworking"
class_body
{ "{"
ERROR ""
directive
#if "#if"
! "!"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION"
function_declaration
func "func"
simple_identifier "networkReachabilityObserver"
( "("
parameter
simple_identifier "_"
simple_identifier "typeReachability"
: ":"
user_type
type_identifier "NKTypeReachability"
) ")"
function_body
{ "{"
statements
if_statement
if "if"
equality_expression
simple_identifier "typeReachability"
== "=="
disjunction_expression
navigation_expression
simple_identifier "NKTypeReachability"
navigation_suffix
. "."
simple_identifier "reachableCellular"
|| "||"
equality_expression
simple_identifier "typeReachability"
== "=="
navigation_expression
simple_identifier "NKTypeReachability"
navigation_suffix
. "."
simple_identifier "reachableEthernetOrWiFi"
{ "{"
statements
assignment
directly_assignable_expression
simple_identifier "lastReachability"
= "="
boolean_literal
true "true"
} "}"
else "else"
{ "{"
statements
if_statement
if "if"
simple_identifier "lastReachability"
{ "{"
statements
property_declaration
value_binding_pattern
let "let"
pattern
simple_identifier "error"
= "="
call_expression
simple_identifier "NKError"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "errorCode"
: ":"
navigation_expression
simple_identifier "global"
navigation_suffix
. "."
simple_identifier "errorNetworkNotAvailable"
, ","
value_argument
value_argument_label
simple_identifier "errorDescription"
: ":"
line_string_literal
" "\""
" "\""
) ")"
call_expression
navigation_expression
call_expression
simple_identifier "NCContentPresenter"
call_suffix
value_arguments
( "("
) ")"
navigation_suffix
. "."
simple_identifier "messageNotification"
call_suffix
value_arguments
( "("
value_argument
line_string_literal
" "\""
line_str_text "_network_not_available_"
" "\""
, ","
value_argument
value_argument_label
simple_identifier "error"
: ":"
simple_identifier "error"
, ","
value_argument
value_argument_label
simple_identifier "delay"
: ":"
navigation_expression
simple_identifier "global"
navigation_suffix
. "."
simple_identifier "dismissAfterSecond"
, ","
value_argument
value_argument_label
simple_identifier "type"
: ":"
navigation_expression
navigation_expression
simple_identifier "NCContentPresenter"
navigation_suffix
. "."
simple_identifier "messageType"
navigation_suffix
. "."
simple_identifier "info"
) ")"
} "}"
assignment
directly_assignable_expression
simple_identifier "lastReachability"
= "="
boolean_literal
false "false"
} "}"
assignment
directly_assignable_expression
simple_identifier "networkReachability"
= "="
simple_identifier "typeReachability"
call_expression
navigation_expression
navigation_expression
simple_identifier "NotificationCenter"
navigation_suffix
. "."
simple_identifier "default"
navigation_suffix
. "."
simple_identifier "postOnMainThread"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "name"
: ":"
navigation_expression
navigation_expression
self_expression
self "self"
navigation_suffix
. "."
simple_identifier "global"
navigation_suffix
. "."
simple_identifier "notificationCenterNetworkReachability"
, ","
value_argument
value_argument_label
simple_identifier "userInfo"
: ":"
nil "nil"
) ")"
} "}"
directive
#endif "#endif"
comment "// MARK: - Download NextcloudKitDelegate"
function_declaration
func "func"
simple_identifier "downloadComplete"
( "("
parameter
simple_identifier "fileName"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "serverUrl"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "etag"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "date"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "dateLastModified"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "length"
: ":"
user_type
type_identifier "Int64"
, ","
parameter
simple_identifier "task"
: ":"
user_type
type_identifier "URLSessionTask"
, ","
parameter
simple_identifier "error"
: ":"
user_type
type_identifier "NKError"
) ")"
function_body
{ "{"
statements
call_expression
simple_identifier "Task"
call_suffix
lambda_literal
{ "{"
statements
await_expression (+26 nodes collapsed)
directive
#if "#if"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION"
await_expression (+63 nodes collapsed)
directive
#else "#else"
guard_statement (+52 nodes collapsed)
if_statement (+53 nodes collapsed)
directive
#endif "#endif"
} "}"
} "}"
function_declaration (+433 nodes collapsed)
function_declaration (+167 nodes collapsed)
comment "// MARK: - Upload NextcloudKitDelegate"
function_declaration
func "func"
simple_identifier "uploadComplete"
( "("
parameter
simple_identifier "fileName"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "serverUrl"
: ":"
user_type
type_identifier "String"
, ","
parameter
simple_identifier "ocId"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "etag"
: ":"
optional_type
user_type
type_identifier "String"
?
? "?"
, ","
parameter
simple_identifier "date"
: ":"
optional_type
user_type
type_identifier "Date"
?
? "?"
, ","
parameter
simple_identifier "size"
: ":"
user_type
type_identifier "Int64"
, ","
parameter
simple_identifier "task"
: ":"
user_type
type_identifier "URLSessionTask"
, ","
parameter
simple_identifier "error"
: ":"
user_type
type_identifier "NKError"
) ")"
function_body
{ "{"
statements
call_expression
simple_identifier "Task"
call_suffix
lambda_literal
{ "{"
statements
await_expression (+26 nodes collapsed)
directive
#if "#if"
simple_identifier "EXTENSION_FILE_PROVIDER_EXTENSION"
await_expression (+63 nodes collapsed)
directive
#else "#else"
guard_statement (+99 nodes collapsed)
if_statement
if "if"
equality_expression
simple_identifier "error"
== "=="
prefix_expression
. "."
simple_identifier "success"
{ "{"
statements
if_statement
if "if"
value_binding_pattern
let "let"
simple_identifier "ocId"
{ "{"
statements
if_statement
if "if"
call_expression
simple_identifier "isInBackground"
call_suffix
value_arguments
( "("
) ")"
{ "{"
statements (+37 nodes collapsed)
} "}"
else "else"
{ "{"
statements
directive
#if "#if"
! "!"
simple_identifier "EXTENSION"
await_expression (+43 nodes collapsed)
directive
#endif "#endif"
} "}"
} "}"
else "else"
{ "{"
statements (+41 nodes collapsed)
} "}"
} "}"
else "else"
{ "{"
statements
await_expression
await "await"
call_expression
simple_identifier "uploadError"
call_suffix
value_arguments
( "("
value_argument
value_argument_label
simple_identifier "withMetadata"
: ":"
simple_identifier "metadata"
, ","
value_argument
value_argument_label
simple_identifier "error"
: ":"
simple_identifier "error"
) ")"
} "}"
directive
#endif "#endif"
} "}"
} "}"
function_declaration (+167 nodes collapsed)
} "}"