minor refactor on context menu actions

pull/1023/head
Ryan ZHAO 1 year ago
parent a7b8a120e3
commit 87efc38a04

@ -16,12 +16,17 @@ extension ContextMenuVC {
let title: String let title: String
let expirationInfo: ExpirationInfo? let expirationInfo: ExpirationInfo?
let themeColor: ThemeValue let themeColor: ThemeValue
let isEmojiAction: Bool let actionType: ActionType
let isEmojiPlus: Bool
let isDismissAction: Bool
let accessibilityLabel: String? let accessibilityLabel: String?
let work: () -> Void let work: () -> Void
enum ActionType {
case emoji
case emojiPlus
case dismiss
case generic
}
// MARK: - Initialization // MARK: - Initialization
init( init(
@ -29,9 +34,7 @@ extension ContextMenuVC {
title: String = "", title: String = "",
expirationInfo: ExpirationInfo? = nil, expirationInfo: ExpirationInfo? = nil,
themeColor: ThemeValue = .textPrimary, themeColor: ThemeValue = .textPrimary,
isEmojiAction: Bool = false, actionType: ActionType = .generic,
isEmojiPlus: Bool = false,
isDismissAction: Bool = false,
accessibilityLabel: String? = nil, accessibilityLabel: String? = nil,
work: @escaping () -> Void work: @escaping () -> Void
) { ) {
@ -39,9 +42,7 @@ extension ContextMenuVC {
self.title = title self.title = title
self.expirationInfo = expirationInfo self.expirationInfo = expirationInfo
self.themeColor = themeColor self.themeColor = themeColor
self.isEmojiAction = isEmojiAction self.actionType = actionType
self.isEmojiPlus = isEmojiPlus
self.isDismissAction = isDismissAction
self.accessibilityLabel = accessibilityLabel self.accessibilityLabel = accessibilityLabel
self.work = work self.work = work
} }
@ -134,20 +135,20 @@ extension ContextMenuVC {
static func react(_ cellViewModel: MessageViewModel, _ emoji: EmojiWithSkinTones, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action { static func react(_ cellViewModel: MessageViewModel, _ emoji: EmojiWithSkinTones, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action {
return Action( return Action(
title: emoji.rawValue, title: emoji.rawValue,
isEmojiAction: true actionType: .emoji
) { delegate?.react(cellViewModel, with: emoji, using: dependencies) } ) { delegate?.react(cellViewModel, with: emoji, using: dependencies) }
} }
static func emojiPlusButton(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action { static func emojiPlusButton(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action {
return Action( return Action(
isEmojiPlus: true, actionType: .emojiPlus,
accessibilityLabel: "Add emoji" accessibilityLabel: "Add emoji"
) { delegate?.showFullEmojiKeyboard(cellViewModel, using: dependencies) } ) { delegate?.showFullEmojiKeyboard(cellViewModel, using: dependencies) }
} }
static func dismiss(_ delegate: ContextMenuActionDelegate?) -> Action { static func dismiss(_ delegate: ContextMenuActionDelegate?) -> Action {
return Action( return Action(
isDismissAction: true actionType: .dismiss
) { delegate?.contextMenuDismissed() } ) { delegate?.contextMenuDismissed() }
} }
} }

@ -37,7 +37,7 @@ final class ContextMenuVC: UIViewController {
private lazy var emojiPlusButton: EmojiPlusButton = { private lazy var emojiPlusButton: EmojiPlusButton = {
let result: EmojiPlusButton = EmojiPlusButton( let result: EmojiPlusButton = EmojiPlusButton(
action: self.actions.first(where: { $0.isEmojiPlus }), action: self.actions.first(where: { $0.actionType == .emojiPlus }),
dismiss: snDismiss dismiss: snDismiss
) )
result.clipsToBounds = true result.clipsToBounds = true
@ -140,7 +140,7 @@ final class ContextMenuVC: UIViewController {
let emojiBarStackView = UIStackView( let emojiBarStackView = UIStackView(
arrangedSubviews: actions arrangedSubviews: actions
.filter { $0.isEmojiAction } .filter { $0.actionType == .emoji }
.map { action -> EmojiReactsView in EmojiReactsView(for: action, dismiss: snDismiss) } .map { action -> EmojiReactsView in EmojiReactsView(for: action, dismiss: snDismiss) }
) )
emojiBarStackView.axis = .horizontal emojiBarStackView.axis = .horizontal
@ -165,7 +165,7 @@ final class ContextMenuVC: UIViewController {
let menuStackView = UIStackView( let menuStackView = UIStackView(
arrangedSubviews: actions arrangedSubviews: actions
.filter { !$0.isEmojiAction && !$0.isEmojiPlus && !$0.isDismissAction } .filter { $0.actionType == .generic }
.map { action -> ActionView in .map { action -> ActionView in
ActionView(for: action, dismiss: snDismiss) ActionView(for: action, dismiss: snDismiss)
} }
@ -406,7 +406,7 @@ final class ContextMenuVC: UIViewController {
}, },
completion: { [weak self] _ in completion: { [weak self] _ in
self?.dismiss() self?.dismiss()
self?.actions.first(where: { $0.isDismissAction })?.work() self?.actions.first(where: { $0.actionType == .dismiss })?.work()
} }
) )
} }

@ -528,6 +528,8 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
object: nil object: nil
) )
self.viewModel.navigatableState.setupBindings(viewController: self, disposables: &self.viewModel.disposables)
// The first time the view loads we should mark the thread as read (in case it was manually // The first time the view loads we should mark the thread as read (in case it was manually
// marked as unread) - doing this here means if we add a "mark as unread" action within the // marked as unread) - doing this here means if we add a "mark as unread" action within the
// conversation settings then we don't need to worry about the conversation getting marked as // conversation settings then we don't need to worry about the conversation getting marked as

@ -47,6 +47,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHold
public static let pageSize: Int = 50 public static let pageSize: Int = 50
public let navigatableState: NavigatableState = NavigatableState() public let navigatableState: NavigatableState = NavigatableState()
public var disposables: Set<AnyCancellable> = Set()
private var threadId: String private var threadId: String
public let initialThreadVariant: SessionThread.Variant public let initialThreadVariant: SessionThread.Variant

Loading…
Cancel
Save