Inline some OWSRecoverablePlaceholder logic

This commit is contained in:
Sasha Weiss 2026-06-09 16:10:25 -07:00 committed by GitHub
parent f995e51b28
commit d12641a3a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 25 deletions

View File

@ -54,8 +54,11 @@ extension TSInteraction {
owsAssertDebug(self.sortId > 0)
}
/// Returns `true` if the receiver was inserted into the database by updating the placeholder
/// Returns `false` if the receiver needs to be inserted into the database.
// MARK: -
/// - Returns
/// `true` if this interaction replaced an existing placeholder inline; `false`
/// if this interaction should be freshly inserted into the database.
private func updatePlaceholder(
from sender: SignalServiceAddress,
transaction: DBWriteTransaction,
@ -85,8 +88,22 @@ extension TSInteraction {
Logger.info("Fetched placeholder with timestamp: \(timestamp) from sender: \(sender). Performing replacement...")
if placeholder.supportsReplacement {
placeholder.replaceWithInteraction(self, writeTx: transaction)
if
placeholder.expirationDate.isAfterNow,
!placeholder.wasRead
{
// We can replace if the placeholder isn't expired, and the user
// hasn't "read" it. We don't actually render placeholders, so
// "read" here is a proxy for "has viewed the spot in the chat where
// the placeholder lives"; we don't want to replace content inline
// that the user has already scrolled past.
Logger.info("Replacing placeholder with recovered interaction: \(timestamp)")
let placeholderRowId = placeholder.sqliteRowId!
replaceRowId(placeholderRowId, uniqueId: placeholder.uniqueId)
replaceSortId(UInt64(placeholderRowId))
anyOverwritingUpdate(transaction: transaction)
return true
} else {
Logger.info("Placeholder not eligible for replacement, deleting.")
@ -111,11 +128,8 @@ extension TSInteraction {
owsAssertDebug(sortId > 0)
}
}
}
// MARK: - shouldAppearInInbox
extension TSInteraction {
// MARK: - shouldAppearInInbox
/// Returns whether the given interaction should pull a conversation to the top of the list
///

View File

@ -5,19 +5,8 @@
extension OWSRecoverableDecryptionPlaceholder {
/// This method performs an upsert replacement of the placeholder with the provided interaction
/// Callers should not continue using the placeholder after performing a replacement.
func replaceWithInteraction(_ interaction: TSInteraction, writeTx: DBWriteTransaction) {
Logger.info("Replacing placeholder with recovered interaction: \(interaction.timestamp)")
guard let inheritedId = sqliteRowId else { return owsFailDebug("Missing rowId") }
interaction.replaceRowId(inheritedId, uniqueId: uniqueId)
interaction.replaceSortId(UInt64(inheritedId))
interaction.anyOverwritingUpdate(transaction: writeTx)
}
/// After this date, the placeholder is no longer eligible for replacement with the original content.
/// The date after which this placeholder is no longer eligible to be
/// replaced with recovered original content.
var expirationDate: Date {
var expirationInterval = RemoteConfig.current.replaceableInteractionExpiration
owsAssertDebug(expirationInterval >= 0)
@ -28,8 +17,4 @@ extension OWSRecoverableDecryptionPlaceholder {
return self.receivedAtDate.addingTimeInterval(max(0, expirationInterval))
}
var supportsReplacement: Bool {
expirationDate.isAfterNow && !wasRead
}
}