Improve incoming group message processing.

This commit is contained in:
Cody Henthorne
2026-02-23 11:37:11 -05:00
parent 68137cb66f
commit 66f0470960
9 changed files with 222 additions and 49 deletions

View File

@@ -313,18 +313,12 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) :
* @return local db group revision or -1 if not present.
*/
fun getGroupV2Revision(groupId: GroupId.V2): Int {
readableDatabase
.select()
return readableDatabase
.select(V2_REVISION)
.from(TABLE_NAME)
.where("$GROUP_ID = ?", groupId.toString())
.run()
.use { cursor ->
return if (cursor.moveToNext()) {
cursor.getInt(cursor.getColumnIndexOrThrow(V2_REVISION))
} else {
-1
}
}
.readToSingleInt(-1)
}
fun isUnknownGroup(groupId: GroupId): Boolean {

View File

@@ -2800,7 +2800,8 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
retrieved: IncomingMessage,
candidateThreadId: Long = -1,
editedMessage: MmsMessageRecord? = null,
notifyObservers: Boolean = true
notifyObservers: Boolean = true,
skipThreadUpdate: Boolean = false
): Optional<InsertResult> {
val type = retrieved.toMessageType()
@@ -2901,7 +2902,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
messageRanges = retrieved.messageRanges,
contentValues = contentValues,
insertListener = null,
updateThread = updateThread,
updateThread = updateThread && !skipThreadUpdate,
unarchive = true,
poll = retrieved.poll,
pollTerminate = retrieved.messageExtras?.pollTerminate,
@@ -2971,7 +2972,8 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
threadId = threadId,
threadWasNewlyCreated = threadIdResult.newlyCreated,
insertedAttachments = insertedAttachments,
quoteAttachmentId = quoteAttachments.firstOrNull()?.let { insertedAttachments?.get(it) }
quoteAttachmentId = quoteAttachments.firstOrNull()?.let { insertedAttachments?.get(it) },
needsThreadUpdate = updateThread && skipThreadUpdate
)
)
}
@@ -3576,8 +3578,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
val contentValuesThreadId = contentValues.getAsLong(THREAD_ID)
if (updateThread) {
threads.setLastScrolled(contentValuesThreadId, 0)
threads.update(threadId, unarchive)
threads.updateForMessageInsert(threadId, unarchive)
}
if (pinnedMessage != null && pinnedMessage.pinDurationInSeconds != PIN_FOREVER) {
@@ -6093,7 +6094,8 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
val threadId: Long,
val threadWasNewlyCreated: Boolean,
val insertedAttachments: Map<Attachment, AttachmentId>? = null,
val quoteAttachmentId: AttachmentId? = null
val quoteAttachmentId: AttachmentId? = null,
val needsThreadUpdate: Boolean = false
)
data class MessageReceiptUpdate(

View File

@@ -1686,6 +1686,11 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
.run()
}
fun updateForMessageInsert(threadId: Long, unarchive: Boolean) {
setLastScrolled(threadId, 0)
update(threadId, unarchive)
}
fun update(threadId: Long, unarchive: Boolean, syncThreadDelete: Boolean = true): Boolean {
return update(
threadId = threadId,