Skip to content

fix: Hide role folder in menuDrawer tree #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Mail/Views/Menu Drawer/Folders/FolderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ struct FolderCell: View {
}
}

if folder.frozenContent.isExpanded || cellType == .move {
if (folder.frozenContent.isExpanded && folder.frozenContent.hasSubFolders) || cellType == .move {
ForEach(folder.children) { child in
FolderCell(
folder: child,
level: level + 1,
currentFolderId: currentFolderId,
canCollapseSubFolders: canCollapseSubFolders,
customCompletion: customCompletion
)
if child.frozenContent.role == nil || child.frozenContent.hasSubFolders {
FolderCell(
folder: child,
level: level + 1,
currentFolderId: currentFolderId,
canCollapseSubFolders: canCollapseSubFolders,
customCompletion: customCompletion
)
}
}
}
}
Expand Down Expand Up @@ -152,12 +154,15 @@ struct FolderCellContent: View {
canCollapseSubFolders && cellType == .menuDrawer
}

private var shouldHaveChevron: Bool

init(frozenFolder: Folder, level: Int, isCurrentFolder: Bool, canCollapseSubFolders: Bool = false) {
assert(frozenFolder.isFrozen, "expecting frozenFolder to be frozen")
self.frozenFolder = frozenFolder
self.level = min(level, Self.maximumSubFolderLevel)
self.isCurrentFolder = isCurrentFolder
self.canCollapseSubFolders = canCollapseSubFolders
shouldHaveChevron = frozenFolder.hasSubFolders && level == 0
}

var body: some View {
Expand All @@ -169,7 +174,7 @@ struct FolderCellContent: View {
}
.accessibilityLabel(MailResourcesStrings.Localizable
.contentDescriptionButtonExpandFolder(frozenFolder.name))
.opacity(level == 0 && !frozenFolder.children.isEmpty ? 1 : 0)
.opacity(shouldHaveChevron ? 1 : 0)
}

HStack(spacing: IKPadding.menuDrawerCellSpacing) {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Menu Drawer/Folders/FoldersListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct FoldersListView: View {
private let hasSubFolders: Bool
init(folders: [NestableFolder]) {
self.folders = folders
hasSubFolders = folders.contains { !$0.children.isEmpty }
hasSubFolders = folders.contains { $0.frozenContent.hasSubFolders }
}

var body: some View {
Expand Down
17 changes: 17 additions & 0 deletions MailCore/Cache/MailboxManager/MailboxManager+Folders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import RealmSwift
// MARK: - Folders

public extension MailboxManager {
func hasSubFolders(folder: Folder) -> Bool {
let filteredChild = folder.children.filter { $0.role == nil }
if !filteredChild.isEmpty {
return true
}
for child in folder.children {
if hasSubFolders(folder: child) {
return true
}
}
return false
}

/// Get all remote folders in DB
func refreshAllFolders() async throws {
guard ReachabilityListener.instance.currentStatus != .offline else {
Expand All @@ -32,7 +45,11 @@ public extension MailboxManager {

let folderResult = try await apiFetcher.folders(mailbox: mailbox)
let filteredFolderResult = filterOutUnknownFolders(folderResult)

let newFolders = getSubFolders(from: filteredFolderResult)
for folder in newFolders {
folder.hasSubFolders = hasSubFolders(folder: folder)
}

try? writeTransaction { writableRealm in
let foldersByRole = Dictionary(grouping: newFolders, by: \.role)
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Cache/MailboxManager/MailboxManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public final class MailboxManager: ObservableObject, MailboxManageable {
let realmName = "\(mailbox.userId)-\(mailbox.mailboxId).realm"
realmConfiguration = Realm.Configuration(
fileURL: MailboxManager.constants.rootDocumentsURL.appendingPathComponent(realmName),
schemaVersion: 41,
schemaVersion: 42,
migrationBlock: { migration, oldSchemaVersion in
// No migration needed from 0 to 16
if oldSchemaVersion < 17 {
Expand Down
1 change: 1 addition & 0 deletions MailCore/Models/Folder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public class Folder: Object, Codable, Comparable, Identifiable {
@Persisted public var threadsSource: Folder?
@Persisted public var associatedFolders: RealmSwift.List<Folder>

@Persisted public var hasSubFolders = false
@Persisted public var isAcceptingMove = true

public var listChildren: AnyRealmCollection<Folder>? {
Expand Down
Loading