diff --git a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift index c611d2589..36d91ad5a 100644 --- a/Session/Conversations/Context Menu/ContextMenuVC+Action.swift +++ b/Session/Conversations/Context Menu/ContextMenuVC+Action.swift @@ -16,12 +16,17 @@ extension ContextMenuVC { let title: String let expirationInfo: ExpirationInfo? let themeColor: ThemeValue - let isEmojiAction: Bool - let isEmojiPlus: Bool - let isDismissAction: Bool + let actionType: ActionType let accessibilityLabel: String? let work: () -> Void + enum ActionType { + case emoji + case emojiPlus + case dismiss + case generic + } + // MARK: - Initialization init( @@ -29,9 +34,7 @@ extension ContextMenuVC { title: String = "", expirationInfo: ExpirationInfo? = nil, themeColor: ThemeValue = .textPrimary, - isEmojiAction: Bool = false, - isEmojiPlus: Bool = false, - isDismissAction: Bool = false, + actionType: ActionType = .generic, accessibilityLabel: String? = nil, work: @escaping () -> Void ) { @@ -39,9 +42,7 @@ extension ContextMenuVC { self.title = title self.expirationInfo = expirationInfo self.themeColor = themeColor - self.isEmojiAction = isEmojiAction - self.isEmojiPlus = isEmojiPlus - self.isDismissAction = isDismissAction + self.actionType = actionType self.accessibilityLabel = accessibilityLabel self.work = work } @@ -134,20 +135,20 @@ extension ContextMenuVC { static func react(_ cellViewModel: MessageViewModel, _ emoji: EmojiWithSkinTones, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action { return Action( title: emoji.rawValue, - isEmojiAction: true + actionType: .emoji ) { delegate?.react(cellViewModel, with: emoji, using: dependencies) } } static func emojiPlusButton(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?, using dependencies: Dependencies) -> Action { return Action( - isEmojiPlus: true, + actionType: .emojiPlus, accessibilityLabel: "Add emoji" ) { delegate?.showFullEmojiKeyboard(cellViewModel, using: dependencies) } } static func dismiss(_ delegate: ContextMenuActionDelegate?) -> Action { return Action( - isDismissAction: true + actionType: .dismiss ) { delegate?.contextMenuDismissed() } } } diff --git a/Session/Conversations/Context Menu/ContextMenuVC.swift b/Session/Conversations/Context Menu/ContextMenuVC.swift index 8bd65da55..b3a506018 100644 --- a/Session/Conversations/Context Menu/ContextMenuVC.swift +++ b/Session/Conversations/Context Menu/ContextMenuVC.swift @@ -37,7 +37,7 @@ final class ContextMenuVC: UIViewController { private lazy var emojiPlusButton: EmojiPlusButton = { let result: EmojiPlusButton = EmojiPlusButton( - action: self.actions.first(where: { $0.isEmojiPlus }), + action: self.actions.first(where: { $0.actionType == .emojiPlus }), dismiss: snDismiss ) result.clipsToBounds = true @@ -140,7 +140,7 @@ final class ContextMenuVC: UIViewController { let emojiBarStackView = UIStackView( arrangedSubviews: actions - .filter { $0.isEmojiAction } + .filter { $0.actionType == .emoji } .map { action -> EmojiReactsView in EmojiReactsView(for: action, dismiss: snDismiss) } ) emojiBarStackView.axis = .horizontal @@ -165,7 +165,7 @@ final class ContextMenuVC: UIViewController { let menuStackView = UIStackView( arrangedSubviews: actions - .filter { !$0.isEmojiAction && !$0.isEmojiPlus && !$0.isDismissAction } + .filter { $0.actionType == .generic } .map { action -> ActionView in ActionView(for: action, dismiss: snDismiss) } @@ -406,7 +406,7 @@ final class ContextMenuVC: UIViewController { }, completion: { [weak self] _ in self?.dismiss() - self?.actions.first(where: { $0.isDismissAction })?.work() + self?.actions.first(where: { $0.actionType == .dismiss })?.work() } ) } diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 58bfe9fc9..0d24e52ef 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -528,6 +528,8 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers 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 // 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 diff --git a/Session/Conversations/ConversationViewModel.swift b/Session/Conversations/ConversationViewModel.swift index a25c8693c..e8395824e 100644 --- a/Session/Conversations/ConversationViewModel.swift +++ b/Session/Conversations/ConversationViewModel.swift @@ -47,6 +47,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHold public static let pageSize: Int = 50 public let navigatableState: NavigatableState = NavigatableState() + public var disposables: Set = Set() private var threadId: String public let initialThreadVariant: SessionThread.Variant