Skip to content

Commit

Permalink
Update pending label mgmt (#3148)
Browse files Browse the repository at this point in the history
* Update pending label mgmt

* Check opt-in before resurfacing resend label

---------

Co-authored-by: crow <[email protected]>
  • Loading branch information
crow and crow authored Jul 1, 2024
1 parent c905369 commit 7850f5d
Showing 1 changed file with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ChannelListCellViewModel: ObservableObject {
let onRemove: () -> Void
let onDismiss: () -> Void

private let pendingLabelHideDelaySeconds: Double = 30
private var resendLabelHideDelaySeconds: Double { Double(pendingLabelModel?.intervalInSeconds ?? 15) }

private var hidePendingLabelTask:Task<Void, Never>?
Expand All @@ -42,33 +41,18 @@ class ChannelListCellViewModel: ObservableObject {
}

private func initializePendingLabel() {
temporarilyShowPendingLabel()
let isOptedIn = channel.isOptedIn

/// If we are initializing the cell as a pending cell, assume it's recent
/// hide the resend button for the interval set on the pending label model
if !channel.isRegistered {
temporarilyHideResend()
if isOptedIn {
withAnimation {
isPendingLabelShowing = false
isResendShowing = false
}
} else {
isResendShowing = true
}
}

func temporarilyShowPendingLabel() {
withAnimation {
isPendingLabelShowing = true
}

hidePendingLabelTask?.cancel()
hidePendingLabelTask = Task { @MainActor [weak self] in
guard let self = self, !Task.isCancelled else { return}

try? await Task.sleep(nanoseconds: UInt64(pendingLabelHideDelaySeconds * 1_000_000_000))

guard !Task.isCancelled else { return}

withAnimation {
self.isPendingLabelShowing = false
isPendingLabelShowing = true
}
temporarilyHideResend()
}
}

Expand All @@ -84,7 +68,7 @@ class ChannelListCellViewModel: ObservableObject {

try? await Task.sleep(nanoseconds: UInt64(resendLabelHideDelaySeconds * 1_000_000_000))

guard !Task.isCancelled else { return}
guard !Task.isCancelled, !channel.isOptedIn else { return}

withAnimation {
self.isResendShowing = true
Expand Down Expand Up @@ -177,7 +161,6 @@ struct ChannelListViewCell: View {
pendingLabelView
}
}

}

@ViewBuilder
Expand Down

0 comments on commit 7850f5d

Please sign in to comment.