From 8b6770f9d28d4d44bfd5bc6c6c1614a37b1b1503 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 16 Dec 2024 13:56:06 +0100 Subject: [PATCH] Improvements --- LeStorage/ApiCallCollection.swift | 2 +- LeStorage/Services.swift | 3 ++- LeStorage/StoreCenter.swift | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/LeStorage/ApiCallCollection.swift b/LeStorage/ApiCallCollection.swift index 989e41b..65bf79a 100644 --- a/LeStorage/ApiCallCollection.swift +++ b/LeStorage/ApiCallCollection.swift @@ -57,7 +57,7 @@ actor ApiCallCollection: SomeCallCollection { } } } - + /// Starts the JSON file decoding synchronously or asynchronously /// Reschedule Api calls if not empty func loadFromFile() throws { diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index e5e14ef..23e93ee 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -513,10 +513,11 @@ public class Services { public func login(username: String, password: String) async throws -> U { _ = try await requestToken(username: username, password: password) let postRequest = try self._baseRequest(call: getUserCall) + let loggingDate = Date() let user: U = try await self._runRequest(postRequest) // StoreCenter.main.setUserUUID(uuidString: user.id) // StoreCenter.main.setUserName(user.username) - StoreCenter.main.setUserInfo(user: user) + StoreCenter.main.userDidLog(user: user, date: loggingDate) return user } diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index 8884da3..e023251 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -162,10 +162,11 @@ public class StoreCenter { // MARK: - Settings /// Sets the user info given a user - func setUserInfo(user: UserBase) { + func userDidLog(user: UserBase, date: Date) { self._settingsStorage.update { settings in settings.userId = user.id settings.username = user.username + settings.lastSynchronization = date self._configureWebSocket() } } @@ -241,6 +242,7 @@ public class StoreCenter { Task { do { try await apiCallCollection.loadFromFile() + await apiCallCollection.rescheduleApiCallsIfNecessary() } catch { Logger.error(error) }