Skip to content

Commit

Permalink
Merge pull request #1219 from Infomaniak/same-core
Browse files Browse the repository at this point in the history
refactor: Use same ios-core
  • Loading branch information
PhilippeWeidmann authored Jul 12, 2024
2 parents fb87245 + 301f488 commit 45f30ef
Show file tree
Hide file tree
Showing 28 changed files with 113 additions and 254 deletions.
4 changes: 2 additions & 2 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "33ce7bc356d9938078a4ec596a535390e25d8650",
"version" : "10.0.3"
"branch" : "mail",
"revision" : "8178fa508021e1d34deed765f545d4333d695a8e"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-algorithms", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.2.2")),
.package(url: "https://github.com/Infomaniak/ios-core", .upToNextMajor(from: "10.0.3")),
.package(url: "https://github.com/Infomaniak/ios-core", branch: "mail"),
.package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "8.0.0")),
.package(url: "https://github.com/Infomaniak/ios-login", .upToNextMajor(from: "6.0.1")),
.package(url: "https://github.com/Infomaniak/ios-dependency-injection", .upToNextMajor(from: "2.0.0")),
Expand Down
34 changes: 26 additions & 8 deletions kDriveCore/Data/Cache/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,38 @@ public class AccountManager: RefreshTokenDelegate, AccountManageable {
}

public func loadAccounts() -> [Account] {
var accounts = [Account]()
if let groupDirectoryURL = FileManager.default
guard let groupDirectoryURL = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: AccountManager.appGroup)?
.appendingPathComponent("preferences", isDirectory: true) {
.appendingPathComponent("preferences", isDirectory: true) else { return [] }
let data: Data
do {
data = try Data(contentsOf: groupDirectoryURL.appendingPathComponent("accounts.json"))
} catch {
DDLogError("Error loading accounts \(error)")
return []
}

do {
let decoder = JSONDecoder()
let savedAccounts = try decoder.decode([Account].self, from: data)

return savedAccounts
} catch is DecodingError {
do {
let data = try Data(contentsOf: groupDirectoryURL.appendingPathComponent("accounts.json"))
let savedAccounts = try decoder.decode([Account].self, from: data)
accounts = savedAccounts
let migrationDecoder = JSONDecoder()
migrationDecoder.keyDecodingStrategy = .convertFromSnakeCase

let savedAccounts = try migrationDecoder.decode([Account].self, from: data)

return savedAccounts
} catch {
DDLogError("Error loading accounts \(error)")
DDLogError("Error migrating accounts \(error)")
return []
}
} catch {
DDLogError("Error loading accounts \(error)")
return []
}
return accounts
}

public func saveAccounts() {
Expand Down
7 changes: 1 addition & 6 deletions kDriveCore/Data/MQService/IPSToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@

import Foundation

public class IPSToken: Codable {
@frozen public struct IPSToken: Codable {
let uuid: String
let validUntil: Int

enum CodingKeys: String, CodingKey {
case uuid
case validUntil = "valid_until"
}
}
5 changes: 3 additions & 2 deletions kDriveCore/Data/Models/CancelableResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Foundation
public class CancelableResponse: Codable {
public let id: String
public let validUntil: Int

public var offline: Bool {
return id.isEmpty
}
Expand All @@ -31,7 +32,7 @@ public class CancelableResponse: Codable {
}

enum CodingKeys: String, CodingKey {
case id = "cancel_id"
case validUntil = "valid_until"
case id = "cancelId"
case validUntil
}
}
8 changes: 4 additions & 4 deletions kDriveCore/Data/Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public class Category: EmbeddedObject, Codable {
enum CodingKeys: String, CodingKey {
case id
case name
case isPredefined = "is_predefined"
case isPredefined
case colorHex = "color"
case createdBy = "created_by"
case createdAt = "created_at"
case userUsageCount = "user_usage_count"
case createdBy
case createdAt
case userUsageCount
}
}

Expand Down
8 changes: 0 additions & 8 deletions kDriveCore/Data/Models/CategoryRights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,4 @@ public class CategoryRights: EmbeddedObject, Codable {
@Persisted public var canDelete: Bool
@Persisted public var canReadOnFile: Bool
@Persisted public var canPutOnFile: Bool

enum CodingKeys: String, CodingKey {
case canCreate = "can_create"
case canEdit = "can_edit"
case canDelete = "can_delete"
case canReadOnFile = "can_read_on_file"
case canPutOnFile = "can_put_on_file"
}
}
12 changes: 6 additions & 6 deletions kDriveCore/Data/Models/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class Comment: Codable {

enum CodingKeys: String, CodingKey {
case id
case parentId = "parent_id"
case parentId
case body
case isResolved = "is_resolved"
case createdAt = "created_at"
case updatedAt = "updated_at"
case isResolved
case createdAt
case updatedAt
case liked
case likesCount = "likes_count"
case responsesCount = "responses_count"
case likesCount
case responsesCount
case user
case responses
case likes
Expand Down
31 changes: 12 additions & 19 deletions kDriveCore/Data/Models/Drive/Drive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ import Foundation
import InfomaniakCore
import RealmSwift

public final class DriveResponse: Codable {
@frozen public struct DriveResponse: Codable {
public let drives: [Drive]
public let users: [DriveUser]
public let teams: [Team]
public let ips: IPSToken

enum CodingKeys: String, CodingKey {
case drives
case users
case teams
case ips
}
}

public final class DriveUsersCategories: EmbeddedObject, Codable {
Expand All @@ -54,9 +47,9 @@ public final class DriveTeamsCategories: EmbeddedObject, Codable {
}

public enum MaintenanceReason: String, PersistableEnum, Codable {
case notRenew = "not_renew"
case demoEnd = "demo_end"
case invoiceOverdue = "invoice_overdue"
case notRenew
case demoEnd
case invoiceOverdue
case technical
}

Expand Down Expand Up @@ -198,26 +191,26 @@ public final class Drive: Object, Codable {
}

enum CodingKeys: String, CodingKey {
case accountId = "account_id"
case accountId
case id
case name
case _pack = "pack"
case role
case _preferences = "preferences"
case size
case usedSize = "used_size"
case usedSize
case _users = "users"
case _teams = "teams"
case categories
case _categoryRights = "categories_permissions"
case _categoryRights = "categoriesPermissions"
case rights
case _capabilities = "capabilities"
case inMaintenance = "in_maintenance"
case maintenanceReason = "maintenance_reason"
case updatedAt = "updated_at"
case inMaintenance
case maintenanceReason
case updatedAt
case _account = "account"
case accountAdmin = "account_admin"
case isInAppSubscription = "is_in_app_subscription"
case accountAdmin
case isInAppSubscription
}

public static func == (lhs: Drive, rhs: Drive) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion kDriveCore/Data/Models/Drive/DriveAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public class DriveAccount: EmbeddedObject, Codable {
enum CodingKeys: String, CodingKey {
case id
case name
case _legalEntityType = "legal_entity_type"
case _legalEntityType = "legalEntityType"
}
}
10 changes: 0 additions & 10 deletions kDriveCore/Data/Models/Drive/DriveCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,4 @@ public class DriveCapabilities: EmbeddedObject, Codable {
@Persisted public var canSeeStats = false
@Persisted public var canUpgradeToKsuite = false
@Persisted public var canRewind = false

enum CodingKeys: String, CodingKey {
case useVersioning = "use_versioning"
case useUploadCompression = "use_upload_compression"
case useTeamSpace = "use_team_space"
case canAddUser = "can_add_user"
case canSeeStats = "can_see_stats"
case canUpgradeToKsuite = "can_upgrade_to_ksuite"
case canRewind = "can_rewind"
}
}
13 changes: 0 additions & 13 deletions kDriveCore/Data/Models/Drive/DrivePackCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,4 @@ public class DrivePackCapabilities: EmbeddedObject, Codable {
@Persisted public var canSetSharelinkPassword = false
@Persisted public var canSetSharelinkExpiration = false
@Persisted public var canSetSharelinkCustomUrl = false

enum CodingKeys: String, CodingKey {
case useVault = "use_vault"
case useManageRight = "use_manage_right"
case canSetTrashDuration = "can_set_trash_duration"
case useDropbox = "use_dropbox"
case canRewind = "can_rewind"
case useFolderCustomColor = "use_folder_custom_color"
case canAccessDashboard = "can_access_dashboard"
case canSetSharelinkPassword = "can_set_sharelink_password"
case canSetSharelinkExpiration = "can_set_sharelink_expiration"
case canSetSharelinkCustomUrl = "can_set_sharelink_custom_url"
}
}
4 changes: 2 additions & 2 deletions kDriveCore/Data/Models/DriveUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public final class DriveUser: Object, Codable, InfomaniakUser {
case id
case email
case _avatar = "avatar"
case _avatarUrl = "avatar_url"
case displayName = "display_name"
case _avatarUrl = "avatarUrl"
case displayName
case role
}

Expand Down
14 changes: 0 additions & 14 deletions kDriveCore/Data/Models/DropBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,11 @@ public class DropBoxCapabilities: EmbeddedObject, Codable {
@Persisted public var hasSizeLimit: Bool
@Persisted public var validity: DropBoxValidity!
@Persisted public var size: DropBoxSize!

enum CodingKeys: String, CodingKey {
case hasPassword = "has_password"
case hasNotification = "has_notification"
case hasValidity = "has_validity"
case hasSizeLimit = "has_size_limit"
case validity
case size
}
}

public class DropBoxValidity: EmbeddedObject, Codable {
@Persisted public var date: Date?
@Persisted public var hasExpired: Bool?

enum CodingKeys: String, CodingKey {
case date
case hasExpired = "has_expired"
}
}

public class DropBoxSize: EmbeddedObject, Codable {
Expand Down
Loading

0 comments on commit 45f30ef

Please sign in to comment.