Skip to content

Commit

Permalink
Fixes crash occurring when trying to update undefined server instance
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyLB committed Nov 30, 2023
1 parent 24f9bb9 commit cd7a373
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 8 additions & 0 deletions piwigoKit/Data Cache/User Data/User+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ extension User {
if self.role != .normal { return false }
return self.uploadRights.components(separatedBy: ",").contains(String(categoryId))
}

public func setLastUsedToNow() {
let dateOfLogin = Date.timeIntervalSinceReferenceDate
self.lastUsed = dateOfLogin
if let server = self.server {
server.lastUsed = dateOfLogin
}
}
}
7 changes: 2 additions & 5 deletions piwigoKit/Network/NetworkUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public class NetworkUtilities: NSObject {
logger.notice("New token: \(NetworkVars.pwgToken, privacy: .private(mask: .hash))")
}
if username != NetworkVars.username || oldToken.isEmpty || NetworkVars.pwgToken != oldToken {
let dateOfLogin = Date.timeIntervalSinceReferenceDate
// Collect list of methods supplied by Piwigo server
// => Determine if Community extension 2.9a or later is installed and active
requestServerMethods {
Expand All @@ -111,8 +110,7 @@ public class NetworkUtilities: NSObject {
// Session now opened
getPiwigoConfig {
// Update date of accesss to the server by guest
user?.lastUsed = dateOfLogin
user?.server?.lastUsed = dateOfLogin
user?.setLastUsedToNow()
user?.status = NetworkVars.userStatus.rawValue
completion()
} failure: { error in
Expand All @@ -129,8 +127,7 @@ public class NetworkUtilities: NSObject {
// Session now opened
getPiwigoConfig {
// Update date of accesss to the server by user
user?.lastUsed = dateOfLogin
user?.server?.lastUsed = dateOfLogin
user?.setLastUsedToNow()
user?.status = NetworkVars.userStatus.rawValue
completion()
} failure: { error in
Expand Down

0 comments on commit cd7a373

Please sign in to comment.