fix(swift-ios): keep thread pin controls available
This commit is contained in:
4 files changed
+23
-3
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user