Do not create new threads to show error messages.

This commit is contained in:
Greyson Parrelli 2024-01-26 09:55:50 -05:00 committed by Nicholas Tinsley
parent 80c0e19692
commit 2c2735af6d
2 changed files with 30 additions and 12 deletions

View file

@ -351,15 +351,21 @@ open class MessageContentProcessor(private val context: Context) {
warn(timestamp, "Handling encryption error.") warn(timestamp, "Handling encryption error.")
val threadRecipient = if (exceptionMetadata.groupId != null) Recipient.externalPossiblyMigratedGroup(exceptionMetadata.groupId) else sender val threadRecipient = if (exceptionMetadata.groupId != null) Recipient.externalPossiblyMigratedGroup(exceptionMetadata.groupId) else sender
SignalDatabase val threadId: Long? = SignalDatabase.threads.getThreadIdFor(threadRecipient.id)
.messages
.insertBadDecryptMessage( if (threadId != null) {
recipientId = sender.id, SignalDatabase
senderDevice = exceptionMetadata.senderDevice, .messages
sentTimestamp = timestamp, .insertBadDecryptMessage(
receivedTimestamp = System.currentTimeMillis(), recipientId = sender.id,
threadId = SignalDatabase.threads.getOrCreateThreadIdFor(threadRecipient) senderDevice = exceptionMetadata.senderDevice,
) sentTimestamp = timestamp,
receivedTimestamp = System.currentTimeMillis(),
threadId = threadId
)
} else {
warn(timestamp, "Could not find a thread for the target recipient. Skipping.")
}
} }
MessageState.INVALID_VERSION -> { MessageState.INVALID_VERSION -> {

View file

@ -8,6 +8,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.squareup.wire.internal.toUnmodifiableList import com.squareup.wire.internal.toUnmodifiableList
import org.signal.core.util.PendingIntentFlags import org.signal.core.util.PendingIntentFlags
import org.signal.core.util.isAbsent
import org.signal.core.util.logging.Log import org.signal.core.util.logging.Log
import org.signal.core.util.roundedString import org.signal.core.util.roundedString
import org.signal.libsignal.metadata.InvalidMetadataMessageException import org.signal.libsignal.metadata.InvalidMetadataMessageException
@ -302,11 +303,22 @@ object MessageDecryptor {
followUpOperations += FollowUpOperation { followUpOperations += FollowUpOperation {
val groupId: GroupId? = protocolException.parseGroupId(envelope) val groupId: GroupId? = protocolException.parseGroupId(envelope)
val threadId: Long = if (groupId != null) {
val threadId: Long? = if (groupId != null) {
if (SignalDatabase.groups.getGroup(groupId).isAbsent()) {
Log.w(TAG, "${logPrefix(envelope)} No group found for $groupId! Not inserting a retry receipt.")
return@FollowUpOperation null
}
val groupRecipient: Recipient = Recipient.externalPossiblyMigratedGroup(groupId) val groupRecipient: Recipient = Recipient.externalPossiblyMigratedGroup(groupId)
SignalDatabase.threads.getOrCreateThreadIdFor(groupRecipient) SignalDatabase.threads.getThreadIdFor(groupRecipient.id)
} else { } else {
SignalDatabase.threads.getOrCreateThreadIdFor(sender) SignalDatabase.threads.getThreadIdFor(sender.id)
}
if (threadId == null) {
Log.w(TAG, "${logPrefix(envelope)} Thread does not already exist for sender ${sender.id}! We will not create one just to show a retry receipt.")
return@FollowUpOperation null
} }
ApplicationDependencies.getPendingRetryReceiptCache().insert(sender.id, senderDevice, envelope.timestamp!!, receivedTimestamp, threadId) ApplicationDependencies.getPendingRetryReceiptCache().insert(sender.id, senderDevice, envelope.timestamp!!, receivedTimestamp, threadId)