Skip to content

Commit

Permalink
fix: Explicit unknown case decoding
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Weidmann <[email protected]>
  • Loading branch information
PhilippeWeidmann committed Feb 4, 2025
1 parent 174ba71 commit 0140d08
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class FileDetailActivityTableViewCell: InsetTableViewCell {
localizedKey = "fileDetailsActivityFileColorUpdate"
case .fileColorDelete:
localizedKey = "fileDetailsActivityFileColorDelete"
case .none:
case .unknown:
localizedKey = "fileActivityUnknown"
}
detailLabel.text = localizedKey.localized
Expand Down
6 changes: 1 addition & 5 deletions kDriveCore/Data/Models/Drive/Drive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ public final class Drive: Object, Codable {
}

public var isFreePack: Bool {
guard let packId = pack.drivePackId else {
return false
}

return packId == .free
return pack.drivePackId == .free
}

public var isInTechnicalMaintenance: Bool {
Expand Down
8 changes: 6 additions & 2 deletions kDriveCore/Data/Models/Drive/DrivePack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public enum DrivePackId: String {
case myKSuite = "my_ksuite"
case myKSuitePlus = "my_ksuite_plus"
case unknown

public init(apiRawValue: String) {
self = .init(rawValue: apiRawValue) ?? .unknown
}
}

public class DrivePack: EmbeddedObject, Codable {
Expand All @@ -42,8 +46,8 @@ public class DrivePack: EmbeddedObject, Codable {
}

/// Convenience enum bridge
public var drivePackId: DrivePackId? {
DrivePackId(rawValue: name)
public var drivePackId: DrivePackId {
DrivePackId(apiRawValue: name)
}

enum CodingKeys: String, CodingKey {
Expand Down
6 changes: 5 additions & 1 deletion kDriveCore/Data/Models/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public enum ConvertedType: String, CaseIterable {
public static let ignoreThumbnailTypes = downloadableTypes
/// Documents that can be previewed by the OS but not necessarily handled by OnlyOffice (eg. .pages)
public static let documentTypes: Set<ConvertedType> = [.presentation, .spreadsheet, .text]

public init(apiRawValue: String) {
self = .init(rawValue: apiRawValue) ?? .unknown
}
}

/// Minimal data needed to query a PublicShare
Expand Down Expand Up @@ -688,7 +692,7 @@ public final class File: Object, Codable {
} else if isBookmark {
return .url
} else {
return ConvertedType(rawValue: extensionType ?? "") ?? .unknown
return ConvertedType(apiRawValue: extensionType ?? "")
}
}

Expand Down
9 changes: 7 additions & 2 deletions kDriveCore/Data/Models/FileActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum FileActivityType: String, Codable, CaseIterable {
case collaborativeUserDelete = "collaborative_user_delete"
case fileColorUpdate = "file_color_update"
case fileColorDelete = "file_color_delete"
case unknown

public static let displayedFileActivities: [FileActivityType] = [
.fileCreate,
Expand Down Expand Up @@ -85,6 +86,10 @@ public enum FileActivityType: String, Codable, CaseIterable {
.fileColorUpdate,
.fileColorDelete
]

public init(apiRawValue: String) {
self = .init(rawValue: apiRawValue) ?? .unknown
}
}

public class FileActivity: Object, Decodable {
Expand All @@ -109,8 +114,8 @@ public class FileActivity: Object, Decodable {
public var mergedFileActivities: [FileActivity] = []

/// Activity type
public var action: FileActivityType? {
return FileActivityType(rawValue: rawAction)
public var action: FileActivityType {
return FileActivityType(apiRawValue: rawAction)
}

public var user: DriveUser? {
Expand Down

0 comments on commit 0140d08

Please sign in to comment.