Skip to content

Added toasts when tapping attachment/voice message buttons in a message request #439

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions Session/Conversations/ConversationVC+Interaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,40 @@ extension ConversationVC:

self.showBlockedModalIfNeeded()
}

func handleDisabledAttachmentButtonTapped() {
/// This logic was added because an Apple reviewer rejected an emergency update as they thought these buttons were
/// unresponsive (even though there is copy on the screen communicating that they are intentionally disabled) - in order
/// to prevent this happening in the future we've added this toast when pressing on the disabled button
guard viewModel.threadData.threadIsMessageRequest == true else { return }

let toastController: ToastController = ToastController(
text: "messageRequestDisabledToastAttachments".localized(),
background: .backgroundSecondary
)
toastController.presentToastView(
fromBottomOfView: self.view,
inset: (snInputView.bounds.height + Values.largeSpacing),
duration: .milliseconds(2500)
)
}

func handleDisabledVoiceMessageButtonTapped() {
/// This logic was added because an Apple reviewer rejected an emergency update as they thought these buttons were
/// unresponsive (even though there is copy on the screen communicating that they are intentionally disabled) - in order
/// to prevent this happening in the future we've added this toast when pressing on the disabled button
guard viewModel.threadData.threadIsMessageRequest == true else { return }

let toastController: ToastController = ToastController(
text: "messageRequestDisabledToastVoiceMessages".localized(),
background: .backgroundSecondary
)
toastController.presentToastView(
fromBottomOfView: self.view,
inset: (snInputView.bounds.height + Values.largeSpacing),
duration: .milliseconds(2500)
)
}

// MARK: --Message Sending

Expand Down
16 changes: 16 additions & 0 deletions Session/Conversations/Input View/ExpandingAttachmentsButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ final class ExpandingAttachmentsButton: UIView, InputViewButtonDelegate {
private weak var delegate: ExpandingAttachmentsButtonDelegate?
private var isExpanded = false { didSet { expandOrCollapse() } }

public var isSoftDisabled = false {
didSet {
gifButton.isSoftDisabled = isSoftDisabled
documentButton.isSoftDisabled = isSoftDisabled
libraryButton.isSoftDisabled = isSoftDisabled
cameraButton.isSoftDisabled = isSoftDisabled
mainButton.isSoftDisabled = isSoftDisabled
}
}

override var isUserInteractionEnabled: Bool {
didSet {
gifButton.isUserInteractionEnabled = isUserInteractionEnabled
Expand Down Expand Up @@ -141,6 +151,11 @@ final class ExpandingAttachmentsButton: UIView, InputViewButtonDelegate {

// MARK: Interaction
func handleInputViewButtonTapped(_ inputViewButton: InputViewButton) {
guard !isSoftDisabled else {
delegate?.handleDisabledAttachmentButtonTapped()
return
}

if inputViewButton == gifButton { delegate?.handleGIFButtonTapped(); isExpanded = false }
if inputViewButton == documentButton { delegate?.handleDocumentButtonTapped(); isExpanded = false }
if inputViewButton == libraryButton { delegate?.handleLibraryButtonTapped(); isExpanded = false }
Expand All @@ -167,6 +182,7 @@ final class ExpandingAttachmentsButton: UIView, InputViewButtonDelegate {
// MARK: - Delegate

protocol ExpandingAttachmentsButtonDelegate: AnyObject {
func handleDisabledAttachmentButtonTapped()

func handleGIFButtonTapped()
func handleDocumentButtonTapped()
Expand Down
11 changes: 8 additions & 3 deletions Session/Conversations/Input View/InputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
disabledInputLabel.text = (updatedInputState.message ?? "")
disabledInputLabel.accessibilityIdentifier = updatedInputState.messageAccessibility?.identifier
disabledInputLabel.accessibilityLabel = updatedInputState.messageAccessibility?.label

attachmentsButton.isUserInteractionEnabled = (updatedInputState.allowedInputTypes == .all)
voiceMessageButton.isUserInteractionEnabled = (updatedInputState.allowedInputTypes == .all)
attachmentsButton.isSoftDisabled = (updatedInputState.allowedInputTypes != .all)
voiceMessageButton.isSoftDisabled = (updatedInputState.allowedInputTypes != .all)

UIView.animate(withDuration: 0.3) { [weak self] in
self?.bottomStackView?.alpha = (updatedInputState.allowedInputTypes != .none ? 1 : 0)
Expand Down Expand Up @@ -443,10 +443,14 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M

func handleInputViewButtonTapped(_ inputViewButton: InputViewButton) {
if inputViewButton == sendButton { delegate?.handleSendButtonTapped() }
if inputViewButton == voiceMessageButton && inputState.allowedInputTypes != .all {
delegate?.handleDisabledVoiceMessageButtonTapped()
}
}

func handleInputViewButtonLongPressBegan(_ inputViewButton: InputViewButton?) {
guard inputViewButton == voiceMessageButton else { return }
guard inputState.allowedInputTypes == .all else { return }

// Note: The 'showVoiceMessageUI' call MUST come before triggering 'startVoiceMessageRecording'
// because if something goes wrong it'll trigger `hideVoiceMessageUI` and we don't want it to
Expand Down Expand Up @@ -584,6 +588,7 @@ protocol InputViewDelegate: ExpandingAttachmentsButtonDelegate, VoiceMessageReco
func showLinkPreviewSuggestionModal()
func handleSendButtonTapped()
func handleDisabledInputTapped()
func handleDisabledVoiceMessageButtonTapped()
func inputTextViewDidChangeContent(_ inputTextView: InputTextView)
func handleMentionSelected(_ mentionInfo: MentionInfo, from view: MentionSelectionView)
func didPasteImageFromPasteboard(_ image: UIImage)
Expand Down
10 changes: 8 additions & 2 deletions Session/Conversations/Input View/InputViewButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class InputViewButton: UIView {
private lazy var heightConstraint = set(.height, to: InputViewButton.size)
private var longPressTimer: Timer?
private var isLongPress = false
public var isSoftDisabled = false

// MARK: - UI Components

Expand Down Expand Up @@ -145,7 +146,7 @@ final class InputViewButton: UIView {
// We want to detect both taps and long presses

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard isUserInteractionEnabled else { return }
guard !isSoftDisabled && isUserInteractionEnabled else { return }

UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
expand()
Expand All @@ -157,7 +158,7 @@ final class InputViewButton: UIView {
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard isUserInteractionEnabled else { return }
guard !isSoftDisabled && isUserInteractionEnabled else { return }

if isLongPress {
delegate?.handleInputViewButtonLongPressMoved(self, with: touches.first)
Expand All @@ -166,6 +167,11 @@ final class InputViewButton: UIView {

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
guard isUserInteractionEnabled else { return }
guard !isSoftDisabled else {
delegate?.handleInputViewButtonTapped(self)
onTap?()
return
}

collapse()
if !isLongPress {
Expand Down