From f83622d1e0e907fb6163b79e78439df9ba9c6429 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Wed, 5 Aug 2026 04:51:48 -0700 Subject: [PATCH] fix(swift-ios): keep thread pin controls available --- .../swift-ios/Features/Chat/ThreadDetailView.swift | 2 +- apps/swift-ios/Features/Shared/FeatureModels.swift | 6 ++++++ .../Workspace/HomeThreadCollectionView.swift | 4 ++-- .../Tests/FeatureTests/DailyUXSidebarTests.swift | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/swift-ios/Features/Chat/ThreadDetailView.swift b/apps/swift-ios/Features/Chat/ThreadDetailView.swift index 23fd56c480..d4a2305e04 100644 --- a/apps/swift-ios/Features/Chat/ThreadDetailView.swift +++ b/apps/swift-ios/Features/Chat/ThreadDetailView.swift @@ -228,7 +228,7 @@ public struct ThreadDetailView: View { } } Section { - if currentThread.supportsPinning == true, !currentThread.isArchived { + if currentThread.canTogglePin, !currentThread.isArchived { Button { Task { await model.setPinned( diff --git a/apps/swift-ios/Features/Shared/FeatureModels.swift b/apps/swift-ios/Features/Shared/FeatureModels.swift index 3412d8d051..334c6ab804 100644 --- a/apps/swift-ios/Features/Shared/FeatureModels.swift +++ b/apps/swift-ios/Features/Shared/FeatureModels.swift @@ -215,6 +215,12 @@ public struct FeatureThread: Identifiable, Sendable, Equatable, Hashable, Codabl self.runtimeMode = runtimeMode self.interactionMode = interactionMode } + + /// Older cached environment descriptors may omit the optional capability even + /// when their server supports pinning. Always keep an existing pin reversible. + public var canTogglePin: Bool { + pinnedAt != nil || supportsPinning != false + } } public enum FeatureMessageRole: String, Sendable, Codable { diff --git a/apps/swift-ios/Features/Workspace/HomeThreadCollectionView.swift b/apps/swift-ios/Features/Workspace/HomeThreadCollectionView.swift index 15d48a7538..f15772a85e 100644 --- a/apps/swift-ios/Features/Workspace/HomeThreadCollectionView.swift +++ b/apps/swift-ios/Features/Workspace/HomeThreadCollectionView.swift @@ -204,7 +204,7 @@ struct HomeThreadCollectionView: UIViewRepresentable { } primaryAction.image = UIImage(systemName: "arrow.uturn.backward") primaryAction.backgroundColor = .systemBlue - } else if thread.pinnedAt != nil, thread.supportsPinning == true { + } else if thread.pinnedAt != nil, thread.canTogglePin { primaryAction = UIContextualAction(style: .normal, title: "Unpin") { [weak self] _, _, finish in self?.parent.onPin(thread, false) @@ -379,7 +379,7 @@ struct HomeThreadCollectionView: UIViewRepresentable { var actions: [UIMenuElement] = [rename, archive] if !isArchived { - if thread.supportsPinning == true { + if thread.canTogglePin { let isPinned = thread.pinnedAt != nil actions.append( UIAction( diff --git a/apps/swift-ios/Tests/FeatureTests/DailyUXSidebarTests.swift b/apps/swift-ios/Tests/FeatureTests/DailyUXSidebarTests.swift index 339ce1ba74..b25e7596e5 100644 --- a/apps/swift-ios/Tests/FeatureTests/DailyUXSidebarTests.swift +++ b/apps/swift-ios/Tests/FeatureTests/DailyUXSidebarTests.swift @@ -117,6 +117,20 @@ struct DailyUXSidebarTests { #expect(DailyUXSidebarRefresh.nextBoundary(for: [pinnedSettled], after: now) == nil) } + @Test + func pinActionsTolerateMissingCapabilitiesAndKeepPinsReversible() { + var legacyDescriptor = thread(id: "legacy", created: -20, updated: -10) + legacyDescriptor.supportsPinning = nil + #expect(legacyDescriptor.canTogglePin) + + var explicitlyUnsupported = thread(id: "unsupported", created: -20, updated: -10) + explicitlyUnsupported.supportsPinning = false + #expect(!explicitlyUnsupported.canTogglePin) + + explicitlyUnsupported.pinnedAt = now + #expect(explicitlyUnsupported.canTogglePin) + } + @Test func snoozedThreadsHaveAReachableReverseState() { var snoozed = thread(id: "snoozed", created: -20, updated: -10)