Improve receipt message validations.

This commit is contained in:
Greyson Parrelli
2026-06-05 20:30:17 +00:00
committed by Cody Henthorne
parent d4924d2a13
commit 96f893652b
2 changed files with 13 additions and 0 deletions
@@ -7,6 +7,7 @@ import androidx.core.content.contentValuesOf
import org.signal.core.util.SqlUtil
import org.signal.core.util.delete
import org.signal.core.util.deleteAll
import org.signal.core.util.exists
import org.signal.core.util.forEach
import org.signal.core.util.logging.Log
import org.signal.core.util.readToList
@@ -127,6 +128,13 @@ class GroupReceiptTable(context: Context?, databaseHelper: SignalDatabase?) : Da
}
}
fun hasReceipt(mmsId: Long, recipientId: RecipientId): Boolean {
return readableDatabase
.exists(TABLE_NAME)
.where("$MMS_ID = ? AND $RECIPIENT_ID = ?", mmsId, recipientId)
.run()
}
fun getGroupReceiptInfo(mmsId: Long): List<GroupReceiptInfo> {
return readableDatabase
.select()
@@ -5540,6 +5540,11 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
return emptySet()
}
// Only allow updating receipts for a group message if the sender is actually a member (stories are excluded because a single story timestamp can map to multiple messages)
if (!receiptData.forIndividualChat && receiptData.storyType == StoryType.NONE && !groupReceipts.hasReceipt(receiptData.messageId, receiptAuthor)) {
return emptySet()
}
if (!receiptData.marked) {
// We set the receipt_timestamp to the max of the two values because that single column represents the timestamp of the last receipt of any type.
// That means we want to update it for each new receipt type, but we never want the time to go backwards.