diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index cec77ffda..6077d5f68 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -205,6 +205,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat notificationCenter.addObserver(self, selector: #selector(addOrRemoveBlockedBanner), name: NSNotification.Name(rawValue: kNSNotificationName_BlockListDidChange), object: nil) notificationCenter.addObserver(self, selector: #selector(handleGroupUpdatedNotification), name: .groupThreadUpdated, object: nil) notificationCenter.addObserver(self, selector: #selector(sendScreenshotNotificationIfNeeded), name: UIApplication.userDidTakeScreenshotNotification, object: nil) + notificationCenter.addObserver(self, selector: #selector(handleMessageSentStatusChanged), name: .messageSentStatusDidChange, object: nil) // Mentions MentionsManager.populateUserPublicKeyCacheIfNeeded(for: thread.uniqueId!) // Draft @@ -319,7 +320,6 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat baselineKeyboardHeight = newHeight self.messagesTableView.keyboardHeight = newHeight } - let margin = (self.lastPageTop - self.messagesTableView.contentOffset.y) scrollButtonConstraint?.constant = -(newHeight + 16) let newContentOffsetY = max(self.messagesTableView.contentOffset.y + min(lastPageTop, 0) + newHeight - self.messagesTableView.keyboardHeight, 0.0) self.messagesTableView.contentOffset.y = newContentOffsetY @@ -353,7 +353,6 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat case .delete: self.messagesTableView.deleteRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .none) case .insert: - print("[Test] INSERT") // Perform inserts before updates self.messagesTableView.insertRows(at: [ IndexPath(row: Int(update.newIndex), section: 0) ], with: .none) if update.viewItem?.interaction is TSOutgoingMessage { @@ -362,7 +361,6 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat shouldScrollToBottom = self.isCloseToBottom } case .update: - print("[Test] UPDATE") self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .none) default: preconditionFailure() } @@ -411,6 +409,24 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat reloadInputViews() } + @objc private func handleMessageSentStatusChanged() { + DispatchQueue.main.async { + guard let indexPaths = self.messagesTableView.indexPathsForVisibleRows else { return } + var indexPathsToReload: [IndexPath] = [] + for indexPath in indexPaths { + guard let cell = self.messagesTableView.cellForRow(at: indexPath) as? VisibleMessageCell else { continue } + let isLast = (indexPath.item == (self.messagesTableView.numberOfRows(inSection: 0) - 1)) + guard !isLast else { continue } + if !cell.messageStatusImageView.isHidden { + indexPathsToReload.append(indexPath) + } + } + UIView.performWithoutAnimation { + self.messagesTableView.reloadRows(at: indexPathsToReload, with: .none) + } + } + } + // MARK: General @objc func addOrRemoveBlockedBanner() { func detach() { diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index 7b0725944..30cf15727 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -81,7 +81,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate { private lazy var snContentView = UIView() - private lazy var messageStatusImageView: UIImageView = { + internal lazy var messageStatusImageView: UIImageView = { let result = UIImageView() result.contentMode = .scaleAspectFit result.layer.cornerRadius = VisibleMessageCell.messageStatusImageViewSize / 2 diff --git a/SessionMessagingKit/Sending & Receiving/MessageSender.swift b/SessionMessagingKit/Sending & Receiving/MessageSender.swift index b9ef948c7..c001faaf1 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageSender.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageSender.swift @@ -340,6 +340,7 @@ public final class MessageSender : NSObject { tsMessage.update(withSentRecipient: recipient, wasSentByUD: true, transaction: transaction) } tsMessage.save(with: transaction) + NotificationCenter.default.post(name: .messageSentStatusDidChange, object: nil, userInfo: nil) // Start the disappearing messages timer if needed OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction) } diff --git a/SessionMessagingKit/Threads/Notification+Thread.swift b/SessionMessagingKit/Threads/Notification+Thread.swift index 77b74d0ef..4b61f8f1b 100644 --- a/SessionMessagingKit/Threads/Notification+Thread.swift +++ b/SessionMessagingKit/Threads/Notification+Thread.swift @@ -3,10 +3,12 @@ public extension Notification.Name { static let groupThreadUpdated = Notification.Name("groupThreadUpdated") static let muteSettingUpdated = Notification.Name("muteSettingUpdated") + static let messageSentStatusDidChange = Notification.Name("messageSentStatusDidChange") } @objc public extension NSNotification { @objc static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString @objc static let muteSettingUpdated = Notification.Name.muteSettingUpdated.rawValue as NSString + @objc static let messageSentStatusDidChange = Notification.Name.messageSentStatusDidChange.rawValue as NSString }