Skip to content

Commit 6a4b5a5

Browse files
committed
chore: Removed unnecessary convenience property.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 83ce74c commit 6a4b5a5

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

Sources/NextcloudFileProviderKit/Enumeration/RemoteChangeObserver.swift

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import NextcloudKit
99

1010
public let NotifyPushAuthenticatedNotificationName = Notification.Name("NotifyPushAuthenticated")
1111

12-
public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSessionWebSocketDelegate {
12+
public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSessionWebSocketDelegate, @unchecked Sendable {
1313
public let remoteInterface: RemoteInterface
1414
public let changeNotificationInterface: ChangeNotificationInterface
1515
public let domain: NSFileProviderDomain?
1616
public let dbManager: FilesDatabaseManager
1717
public var account: Account
18-
public var accountId: String { account.ncKitAccount }
1918

2019
public var webSocketPingIntervalNanoseconds: UInt64 = 3 * 1_000_000_000
2120
public var webSocketReconfigureIntervalNanoseconds: UInt64 = 1 * 1_000_000_000
@@ -121,7 +120,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
121120
return
122121
}
123122
guard webSocketAuthenticationFailCount < webSocketAuthenticationFailLimit else {
124-
logger.error("Exceeded authentication failures for notify push websocket \(accountId), will poll instead.", [.account: accountId])
123+
logger.error("Exceeded authentication failures for notify push websocket \(account.ncKitAccount), will poll instead.", [.account: account.ncKitAccount])
125124
startPollingTimer()
126125
return
127126
}
@@ -159,15 +158,15 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
159158
)
160159

161160
guard error == .success else {
162-
logger.error("Could not get capabilities: \(error.errorCode) \(error.errorDescription)", [.account: accountId])
161+
logger.error("Could not get capabilities: \(error.errorCode) \(error.errorDescription)", [.account: account.ncKitAccount])
163162
reconnectWebSocket()
164163
return
165164
}
166165

167166
guard let capabilities,
168167
let websocketEndpoint = capabilities.notifyPush?.endpoints?.websocket
169168
else {
170-
logger.error("Could not get notifyPush websocket \(accountId), polling.", [.account: accountId])
169+
logger.error("Could not get notifyPush websocket \(account.ncKitAccount), polling.", [.account: account.ncKitAccount])
171170
startPollingTimer()
172171
return
173172
}
@@ -185,7 +184,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
185184
)
186185
webSocketTask = webSocketUrlSession?.webSocketTask(with: websocketEndpointUrl)
187186
webSocketTask?.resume()
188-
logger.info("Successfully configured push notifications for \(accountId)", [.account: accountId])
187+
logger.info("Successfully configured push notifications for \(account.ncKitAccount)", [.account: account.ncKitAccount])
189188
}
190189

191190
public func authenticationChallenge(
@@ -225,7 +224,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
225224
didOpenWithProtocol _: String?
226225
) {
227226
guard !invalidated else { return }
228-
logger.debug("Websocket connected \(accountId) sending auth details", [.account: accountId])
227+
logger.debug("Websocket connected \(account.ncKitAccount) sending auth details", [.account: account.ncKitAccount])
229228
Task { await authenticateWebSocket() }
230229
}
231230

@@ -243,13 +242,13 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
243242
return
244243
}
245244

246-
logger.debug("Socket connection closed for \(accountId).", [.account: accountId])
245+
logger.debug("Socket connection closed for \(account.ncKitAccount).", [.account: account.ncKitAccount])
247246

248247
if let reason {
249248
logger.debug("Reason: \(String(data: reason, encoding: .utf8) ?? "")")
250249
}
251250

252-
logger.debug("Retrying websocket connection for \(accountId).", [.account: accountId])
251+
logger.debug("Retrying websocket connection for \(account.ncKitAccount).", [.account: account.ncKitAccount])
253252
reconnectWebSocket()
254253
}
255254

@@ -262,7 +261,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
262261
try await webSocketTask?.send(.string(account.username))
263262
try await webSocketTask?.send(.string(account.password))
264263
} catch {
265-
logger.error("Error authenticating websocket.", [.account: accountId, .error: error])
264+
logger.error("Error authenticating websocket.", [.account: account.ncKitAccount, .error: error])
266265
}
267266

268267
readWebSocket()
@@ -279,7 +278,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
279278
do {
280279
try await Task.sleep(nanoseconds: self.webSocketPingIntervalNanoseconds)
281280
} catch {
282-
self.logger.error("Could not sleep websocket ping.", [.account: self.accountId, .error: error])
281+
self.logger.error("Could not sleep websocket ping.", [.account: self.account.ncKitAccount, .error: error])
283282
}
284283
guard !Task.isCancelled else { return }
285284
self.pingWebSocket()
@@ -289,7 +288,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
289288
private func pingWebSocket() { // Keep the socket connection alive
290289
guard !invalidated else { return }
291290
guard networkReachability != .notReachable else {
292-
logger.error("Not pinging because network is unreachable.", [.account: accountId])
291+
logger.error("Not pinging because network is unreachable.", [.account: account.ncKitAccount])
293292
return
294293
}
295294

@@ -315,7 +314,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
315314
webSocketTask?.receive { result in
316315
switch result {
317316
case .failure:
318-
self.logger.debug("Failed to read websocket \(self.accountId)", [.account: self.accountId])
317+
self.logger.debug("Failed to read websocket \(self.account.ncKitAccount)", [.account: self.account.ncKitAccount])
319318
// Do not reconnect here, delegate methods will handle reconnecting
320319
case let .success(message):
321320
switch message {
@@ -334,7 +333,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
334333
private func processWebsocket(data: Data) {
335334
guard !invalidated else { return }
336335
guard let string = String(data: data, encoding: .utf8) else {
337-
logger.error("Could parse websocket data for id: \(accountId)", [.account: accountId])
336+
logger.error("Could parse websocket data for id: \(account.ncKitAccount)", [.account: account.ncKitAccount])
338337
return
339338
}
340339
processWebsocket(string: string)
@@ -343,29 +342,29 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
343342
private func processWebsocket(string: String) {
344343
logger.debug("Received websocket string: \(string)")
345344
if string == "notify_file" {
346-
logger.debug("Received file notification for \(accountId)", [.account: accountId])
345+
logger.debug("Received file notification for \(account.ncKitAccount)", [.account: account.ncKitAccount])
347346
startWorkingSetCheck()
348347
} else if string == "notify_activity" {
349-
logger.debug("Ignoring activity notification: \(accountId)", [.account: accountId])
348+
logger.debug("Ignoring activity notification: \(account.ncKitAccount)", [.account: account.ncKitAccount])
350349
} else if string == "notify_notification" {
351-
logger.debug("Ignoring notification: \(accountId)", [.account: accountId])
350+
logger.debug("Ignoring notification: \(account.ncKitAccount)", [.account: account.ncKitAccount])
352351
} else if string == "authenticated" {
353-
logger.debug("Correctly authed websocket \(accountId), pinging", [.account: accountId])
352+
logger.debug("Correctly authed websocket \(account.ncKitAccount), pinging", [.account: account.ncKitAccount])
354353
NotificationCenter.default.post(
355354
name: NotifyPushAuthenticatedNotificationName, object: self
356355
)
357356
startNewWebSocketPingTask()
358357
} else if string == "err: Invalid credentials" {
359358
logger.debug(
360359
"""
361-
Invalid creds for websocket for \(accountId),
360+
Invalid creds for websocket for \(account.ncKitAccount),
362361
reattempting auth.
363362
"""
364363
)
365364
webSocketAuthenticationFailCount += 1
366365
reconnectWebSocket()
367366
} else {
368-
logger.error("Received unknown string from websocket \(accountId): \(string)", [.account: accountId])
367+
logger.error("Received unknown string from websocket \(account.ncKitAccount): \(string)", [.account: account.ncKitAccount])
369368
}
370369
}
371370

@@ -455,7 +454,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
455454
// Visited folders and downloaded files. Sort in terms of their remote URLs.
456455
// This way we ensure we visit parent folders before their children.
457456
let materialisedItems = dbManager
458-
.materialisedItemMetadatas(account: accountId)
457+
.materialisedItemMetadatas(account: account.ncKitAccount)
459458
.sorted { $0.remotePath().count < $1.remotePath().count }
460459

461460
var allNewMetadatas = [SendableItemMetadata]()
@@ -502,7 +501,7 @@ public final class RemoteChangeObserver: NSObject, NextcloudKitDelegate, URLSess
502501
examinedItemIds.insert(item.ocId)
503502
}
504503
} else if let readError, readError != .success {
505-
logger.info("Finished change enumeration of working set for user \(accountId) with error.", [.account: accountId, .error: readError])
504+
logger.info("Finished change enumeration of working set for user \(account.ncKitAccount) with error.", [.account: account.ncKitAccount, .error: readError])
506505
return
507506
} else {
508507
allDeletedMetadatas += deletedMetadatas ?? []

0 commit comments

Comments
 (0)