Avoid unnecessary conversation screen updates

This commit is contained in:
Niels Andriesse 2021-08-05 10:02:52 +10:00
parent 3db8231bde
commit b8c4e6aa93
3 changed files with 10 additions and 5 deletions

View File

@ -353,6 +353,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
case .delete:
self.messagesTableView.deleteRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade)
case .insert:
print("[Test] INSERT")
// Perform inserts before updates
self.messagesTableView.insertRows(at: [ IndexPath(row: Int(update.newIndex), section: 0) ], with: .fade)
if update.viewItem?.interaction is TSOutgoingMessage {

View File

@ -337,10 +337,12 @@ public final class MessageSender : NSObject {
let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction), thread.isClosedGroup {
recipients = thread.groupModel.groupMemberIds
}
recipients.forEach { recipient in
tsMessage.update(withSentRecipient: recipient, wasSentByUD: true, transaction: transaction)
if !tsMessage.wasSentToAnyRecipient {
recipients.forEach { recipient in
tsMessage.update(withSentRecipient: recipient, wasSentByUD: true, transaction: transaction)
}
MessageInvalidator.invalidate(tsMessage, with: transaction)
}
MessageInvalidator.invalidate(tsMessage, with: transaction)
// Start the disappearing messages timer if needed
OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction)
}
@ -359,6 +361,8 @@ public final class MessageSender : NSObject {
public static func handleFailedMessageSend(_ message: Message, with error: Swift.Error, using transaction: Any) {
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
tsMessage.update(sendingError: error, transaction: transaction as! YapDatabaseReadWriteTransaction)
let transaction = transaction as! YapDatabaseReadWriteTransaction
tsMessage.update(sendingError: error, transaction: transaction)
MessageInvalidator.invalidate(tsMessage, with: transaction)
}
}

View File

@ -11,7 +11,7 @@
private override init() { }
@objc public static func invalidate(_ message: TSMessage, with transaction: YapDatabaseReadWriteTransaction) {
guard let id = message.uniqueId else { return }
guard let id = message.uniqueId, !isInvalidated(message) else { return }
invalidatedMessages.insert(id)
message.touch(with: transaction)
}