|
|
|
@ -7,7 +7,8 @@
|
|
|
|
|
final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversationSettingsViewDelegate, ConversationSearchControllerDelegate, UITableViewDataSource, UITableViewDelegate {
|
|
|
|
|
let isUnsendRequestsEnabled = true // Set to true once unsend requests are done on all platforms
|
|
|
|
|
let thread: TSThread
|
|
|
|
|
let focusedMessageID: String? // This isn't actually used ATM
|
|
|
|
|
let focusedMessageID: String? // This is used for global search
|
|
|
|
|
var focusedMessageIndexPath: IndexPath?
|
|
|
|
|
var unreadViewItems: [ConversationViewItem] = []
|
|
|
|
|
var scrollButtonConstraint: NSLayoutConstraint?
|
|
|
|
|
// Search
|
|
|
|
@ -236,6 +237,9 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|
|
|
|
// unreadIndicatorIndex is calculated during loading of the viewItems, so it's
|
|
|
|
|
// supposed to be accurate.
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
if let focusedMessageID = self.focusedMessageID {
|
|
|
|
|
self.scrollToInteraction(with: focusedMessageID, isAnimated: false, highlighted: true)
|
|
|
|
|
} else {
|
|
|
|
|
let firstUnreadMessageIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue
|
|
|
|
|
?? (self.viewItems.count - self.unreadViewItems.count)
|
|
|
|
|
if unreadCount > 0, let viewItem = self.viewItems[ifValid: firstUnreadMessageIndex], let interactionID = viewItem.interaction.uniqueId {
|
|
|
|
@ -244,6 +248,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|
|
|
|
} else {
|
|
|
|
|
self.scrollToBottom(isAnimated: false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.scrollButton.alpha = self.getScrollButtonOpacity()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -251,6 +256,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
highlightFocusedMessageIfNeeded()
|
|
|
|
|
didFinishInitialLayout = true
|
|
|
|
|
markAllAsRead()
|
|
|
|
|
}
|
|
|
|
@ -313,6 +319,13 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func highlightFocusedMessageIfNeeded() {
|
|
|
|
|
if let indexPath = focusedMessageIndexPath, let cell = messagesTableView.cellForRow(at: indexPath) as? VisibleMessageCell {
|
|
|
|
|
cell.highlithed()
|
|
|
|
|
focusedMessageIndexPath = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func handleKeyboardWillChangeFrameNotification(_ notification: Notification) {
|
|
|
|
|
guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return }
|
|
|
|
|
if (newHeight > 0 && baselineKeyboardHeight == 0) {
|
|
|
|
@ -617,8 +630,11 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|
|
|
|
scrollToInteraction(with: interactionID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func scrollToInteraction(with interactionID: String, position: UITableView.ScrollPosition = .middle, isAnimated: Bool = true) {
|
|
|
|
|
func scrollToInteraction(with interactionID: String, position: UITableView.ScrollPosition = .middle, isAnimated: Bool = true, highlighted: Bool = false) {
|
|
|
|
|
guard let indexPath = viewModel.ensureLoadWindowContainsInteractionId(interactionID) else { return }
|
|
|
|
|
messagesTableView.scrollToRow(at: indexPath, at: position, animated: isAnimated)
|
|
|
|
|
if highlighted, let _ = messagesTableView.cellForRow(at: indexPath) as? VisibleMessageCell {
|
|
|
|
|
focusedMessageIndexPath = indexPath
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|