Skip to content
Closed
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
53 changes: 52 additions & 1 deletion Session/Conversations/ConversationVC+Interaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ extension ConversationVC:
using: dependencies
)
sendMediaNavController.sendMediaNavDelegate = self
sendMediaNavController.sendMediaNavDataSource = self
sendMediaNavController.modalPresentationStyle = .fullScreen
self?.present(sendMediaNavController, animated: true, completion: nil)
}
Expand All @@ -466,6 +467,7 @@ extension ConversationVC:
using: self.viewModel.dependencies
)
sendMediaNavController.sendMediaNavDelegate = self
sendMediaNavController.sendMediaNavDataSource = self
sendMediaNavController.modalPresentationStyle = .fullScreen

present(sendMediaNavController, animated: true, completion: nil)
Expand All @@ -483,6 +485,7 @@ extension ConversationVC:
threadVariant: self.viewModel.threadData.threadVariant,
attachments: attachments,
approvalDelegate: self,
approvalDataSource: self,
disableLinkPreviewImageDownload: (self.viewModel.threadData.threadCanUpload != true),
using: self.viewModel.dependencies
) else { return }
Expand Down Expand Up @@ -718,6 +721,9 @@ extension ConversationVC:
return present(modal, animated: true, completion: nil)
}

// Preserve the quote before clearing input fields for message sending.
let quoteToUse: QuotedReplyModel? = quoteModel ?? snInputView.quoteDraftInfo?.model

// Clearing this out immediately to make this appear more snappy
DispatchQueue.main.async { [weak self] in
self?.snInputView.text = ""
Expand All @@ -735,7 +741,7 @@ extension ConversationVC:
sentTimestampMs: sentTimestampMs,
attachments: attachments,
linkPreviewDraft: linkPreviewDraft,
quoteModel: quoteModel
quoteModel: quoteToUse
)

// If this was a message request then approve it
Expand Down Expand Up @@ -956,6 +962,7 @@ extension ConversationVC:
threadVariant: self.viewModel.threadData.threadVariant,
attachments: [ attachment ],
approvalDelegate: self,
approvalDataSource: self,
disableLinkPreviewImageDownload: (self.viewModel.threadData.threadCanUpload != true),
using: self.viewModel.dependencies
) else { return }
Expand Down Expand Up @@ -3483,3 +3490,47 @@ extension ConversationVC: MediaPresentationContextProvider {
return self.navigationController?.navigationBar.generateSnapshot(in: coordinateSpace)
}
}

// MARK: - Qoute accessory handling
extension ConversationVC: InputViewDataSource, AttachmentApprovalViewControllerDataSource, SendMediaNavDataSource {
func generateQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView? {
guard let quoteDraftInfo = snInputView.quoteDraftInfo else {
return nil
}

let quoteView: QuoteView = QuoteView(
for: .draft,
authorId: quoteDraftInfo.model.authorId,
quotedText: quoteDraftInfo.model.body,
threadVariant: self.viewModel.threadData.threadVariant,
currentUserSessionIds: quoteDraftInfo.model.currentUserSessionIds,
direction: (quoteDraftInfo.isOutgoing ? .outgoing : .incoming),
attachment: quoteDraftInfo.model.attachment,
using: viewModel.dependencies
) {
deleteHandler()
}

return quoteView
}

// MARK: - InputViewDataSource
func shouldShowQuoteAccessoryView(withDeleteHandler handler: @escaping () -> Void) -> UIView? {
generateQouteAccessoryView(handler)
}

// MARK: - AttachmentApprovalViewControllerDataSource
func attachmentApprovalQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView? {
generateQouteAccessoryView { [weak self] in
self?.snInputView.quoteDraftInfo = nil
deleteHandler()
}
}

func sendMediaNavQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView? {
generateQouteAccessoryView { [weak self] in
self?.snInputView.quoteDraftInfo = nil
deleteHandler()
}
}
}
1 change: 1 addition & 0 deletions Session/Conversations/ConversationVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ final class ConversationVC: BaseVC, LibSessionRespondingViewController, Conversa
lazy var snInputView: InputView = InputView(
threadVariant: self.viewModel.initialThreadVariant,
delegate: self,
dataSource: self,
using: self.viewModel.dependencies
)

Expand Down
35 changes: 20 additions & 15 deletions Session/Conversations/Input View/InputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
private var disposables: Set<AnyCancellable> = Set()
private let dependencies: Dependencies
private let threadVariant: SessionThread.Variant

private weak var delegate: InputViewDelegate?
private weak var dataSource: InputViewDataSource?

private var sessionProState: SessionProManagerType?

var quoteDraftInfo: (model: QuotedReplyModel, isOutgoing: Bool)? { didSet { handleQuoteDraftChanged() } }
Expand Down Expand Up @@ -202,10 +205,16 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M

// MARK: - Initialization

init(threadVariant: SessionThread.Variant, delegate: InputViewDelegate, using dependencies: Dependencies) {
init(
threadVariant: SessionThread.Variant,
delegate: InputViewDelegate,
dataSource: InputViewDataSource?,
using dependencies: Dependencies
) {
self.dependencies = dependencies
self.threadVariant = threadVariant
self.delegate = delegate
self.dataSource = dataSource
self.sessionProState = dependencies[singleton: .sessionProState]

super.init(frame: CGRect.zero)
Expand Down Expand Up @@ -343,23 +352,14 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
linkPreviewInfo = nil

guard let quoteDraftInfo = quoteDraftInfo else { return }
let view = dataSource?.shouldShowQuoteAccessoryView {
self.quoteDraftInfo = nil
}

guard let quoteView = view else { return }

let hInset: CGFloat = 6 // Slight visual adjustment

let quoteView: QuoteView = QuoteView(
for: .draft,
authorId: quoteDraftInfo.model.authorId,
quotedText: quoteDraftInfo.model.body,
threadVariant: threadVariant,
currentUserSessionIds: quoteDraftInfo.model.currentUserSessionIds,
direction: (quoteDraftInfo.isOutgoing ? .outgoing : .incoming),
attachment: quoteDraftInfo.model.attachment,
using: dependencies
) { [weak self] in
self?.quoteDraftInfo = nil
}

additionalContentContainer.addSubview(quoteView)
quoteView.pin(.leading, to: .leading, of: additionalContentContainer, withInset: hInset)
quoteView.pin(.top, to: .top, of: additionalContentContainer, withInset: 12)
Expand Down Expand Up @@ -676,3 +676,8 @@ protocol InputViewDelegate: ExpandingAttachmentsButtonDelegate, VoiceMessageReco
@MainActor func handleMentionSelected(_ mentionInfo: MentionInfo, from view: MentionSelectionView)
@MainActor func didPasteImageFromPasteboard(_ image: UIImage)
}

public protocol InputViewDataSource: AnyObject {
@MainActor
func shouldShowQuoteAccessoryView(withDeleteHandler handler:@escaping () -> Void) -> UIView?
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SendMediaNavigationController: UINavigationController {
// MARK: -

public weak var sendMediaNavDelegate: SendMediaNavDelegate?
public weak var sendMediaNavDataSource: SendMediaNavDataSource?

public class func showingCameraFirst(threadId: String, threadVariant: SessionThread.Variant, using dependencies: Dependencies) -> SendMediaNavigationController {
let navController = SendMediaNavigationController(threadId: threadId, threadVariant: threadVariant, using: dependencies)
Expand Down Expand Up @@ -245,6 +246,7 @@ class SendMediaNavigationController: UINavigationController {
else { return false }

approvalViewController.approvalDelegate = self
approvalViewController.approvalDataSource = self
approvalViewController.messageText = sendMediaNavDelegate.sendMediaNavInitialMessageText(self)

pushViewController(approvalViewController, animated: true)
Expand Down Expand Up @@ -425,7 +427,8 @@ extension SendMediaNavigationController: ImagePickerGridControllerDelegate {
}
}

extension SendMediaNavigationController: AttachmentApprovalViewControllerDelegate {
extension SendMediaNavigationController: AttachmentApprovalViewControllerDelegate, AttachmentApprovalViewControllerDataSource {
// MARK: - AttachmentApprovalViewControllerDelegate
func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didChangeMessageText newMessageText: String?) {
sendMediaNavDelegate?.sendMediaNav(self, didChangeMessageText: newMessageText)
}
Expand Down Expand Up @@ -476,6 +479,11 @@ extension SendMediaNavigationController: AttachmentApprovalViewControllerDelegat

popViewController(animated: true)
}

// MARK: - AttachmentApprovalViewControllerDataSource
func attachmentApprovalQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView? {
sendMediaNavDataSource?.sendMediaNavQouteAccessoryView(deleteHandler)
}
}

private enum AttachmentDraft {
Expand Down Expand Up @@ -799,3 +807,7 @@ protocol SendMediaNavDelegate: AnyObject {
func sendMediaNavInitialMessageText(_ sendMediaNavigationController: SendMediaNavigationController) -> String?
func sendMediaNav(_ sendMediaNavigationController: SendMediaNavigationController, didChangeMessageText newMessageText: String?)
}

protocol SendMediaNavDataSource: AnyObject {
func sendMediaNavQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView?
}
1 change: 1 addition & 0 deletions SessionShareExtension/ThreadPickerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView
threadVariant: strongSelf.viewModel.viewData[indexPath.row].threadVariant,
attachments: attachments,
approvalDelegate: strongSelf,
approvalDataSource: nil,
disableLinkPreviewImageDownload: (
strongSelf.viewModel.viewData[indexPath.row].threadCanUpload != true
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,32 @@ protocol AttachmentApprovalInputAccessoryViewDelegate: AnyObject {
func attachmentApprovalInputUpdateMediaRail()
}

protocol AttachmentApprovalInputAccessoryViewDataSource: AnyObject {
func attachmentApprovalQouteAccessoryView(onDeleteHandler handler: @escaping () -> Void) -> UIView?
}

// MARK: -

class AttachmentApprovalInputAccessoryView: UIView {

weak var delegate: AttachmentApprovalInputAccessoryViewDelegate?
weak var dataSource: AttachmentApprovalInputAccessoryViewDataSource?

let attachmentTextToolbar: AttachmentTextToolbar
let galleryRailView: GalleryRailView
private lazy var additionalContentContainer = UIView()

var isEditingMediaMessage: Bool {
return attachmentTextToolbar.inputView?.isFirstResponder ?? false
}

private var currentAttachmentItem: SignalAttachmentItem?

let kGalleryRailViewHeight: CGFloat = 72

required init(delegate: AttachmentTextToolbarDelegate, using dependencies: Dependencies) {
required init(delegate: AttachmentTextToolbarDelegate, dataSource: AttachmentApprovalInputAccessoryViewDataSource?, using dependencies: Dependencies) {
attachmentTextToolbar = AttachmentTextToolbar(delegate: delegate, using: dependencies)
self.dataSource = dataSource

galleryRailView = GalleryRailView()
galleryRailView.scrollFocusMode = .keepWithinBounds
Expand Down Expand Up @@ -64,7 +71,11 @@ class AttachmentApprovalInputAccessoryView: UIView {
separator.pin(.leading, to: .leading, of: self)
separator.pin(.trailing, to: .trailing, of: self)

let stackView = UIStackView(arrangedSubviews: [galleryRailView, attachmentTextToolbar])
let stackView = UIStackView(arrangedSubviews: [
galleryRailView,
additionalContentContainer,
attachmentTextToolbar
])
stackView.axis = .vertical

addSubview(stackView)
Expand All @@ -83,6 +94,8 @@ class AttachmentApprovalInputAccessoryView: UIView {
galleryRailBlockingView.pin(.left, to: .left, of: stackView)
galleryRailBlockingView.pin(.right, to: .right, of: stackView)
galleryRailBlockingView.pin(.bottom, to: .bottom, of: stackView)

setupQuoteAccessoryViewIfAny()
}

// MARK:
Expand All @@ -101,6 +114,25 @@ class AttachmentApprovalInputAccessoryView: UIView {

updateFirstResponder()
}

// MARK: - Additional accessory view
private func setupQuoteAccessoryViewIfAny() {
additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }

let view = dataSource?.attachmentApprovalQouteAccessoryView { [weak self] in
self?.additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
}

guard let quoteView = view else { return }

let hInset: CGFloat = 6 // Slight visual adjustment

additionalContentContainer.addSubview(quoteView)
quoteView.pin(.leading, to: .leading, of: additionalContentContainer, withInset: hInset)
quoteView.pin(.top, to: .top, of: additionalContentContainer, withInset: 12)
quoteView.pin(.trailing, to: .trailing, of: additionalContentContainer, withInset: -hInset)
quoteView.pin(.bottom, to: .bottom, of: additionalContentContainer, withInset: -6)
}

// MARK:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public protocol AttachmentApprovalViewControllerDelegate: AnyObject {
func attachmentApprovalDidTapAddMore(_ attachmentApproval: AttachmentApprovalViewController)
}

public protocol AttachmentApprovalViewControllerDataSource: AnyObject {
func attachmentApprovalQouteAccessoryView(_ deleteHandler: @escaping () -> Void) -> UIView?
}

// MARK: -

@objc
Expand Down Expand Up @@ -77,6 +81,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
private let disableLinkPreviewImageDownload: Bool

public weak var approvalDelegate: AttachmentApprovalViewControllerDelegate?
public weak var approvalDataSource: AttachmentApprovalViewControllerDataSource?

let attachmentItemCollection: AttachmentItemCollection

Expand Down Expand Up @@ -183,6 +188,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
threadVariant: SessionThread.Variant,
attachments: [SignalAttachment],
approvalDelegate: AttachmentApprovalViewControllerDelegate,
approvalDataSource: AttachmentApprovalViewControllerDataSource?,
disableLinkPreviewImageDownload: Bool,
using dependencies: Dependencies
) -> UINavigationController? {
Expand All @@ -195,6 +201,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
using: dependencies
) else { return nil }
vc.approvalDelegate = approvalDelegate
vc.approvalDataSource = approvalDataSource

let navController = StyledNavigationController(rootViewController: vc)

Expand All @@ -206,7 +213,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
private let kSpacingBetweenItems: CGFloat = 20

private lazy var bottomToolView: AttachmentApprovalInputAccessoryView = {
let bottomToolView = AttachmentApprovalInputAccessoryView(delegate: self, using: dependencies)
let bottomToolView = AttachmentApprovalInputAccessoryView(delegate: self, dataSource: self, using: dependencies)
bottomToolView.delegate = self
bottomToolView.attachmentTextToolbar.delegate = self
bottomToolView.galleryRailView.delegate = self
Expand Down Expand Up @@ -857,3 +864,9 @@ extension AttachmentApprovalViewController: AttachmentApprovalInputAccessoryView
updateMediaRail()
}
}

extension AttachmentApprovalViewController: AttachmentApprovalInputAccessoryViewDataSource {
func attachmentApprovalQouteAccessoryView(onDeleteHandler handler: @escaping () -> Void) -> UIView? {
return approvalDataSource?.attachmentApprovalQouteAccessoryView(handler)
}
}