Skip messages that aren't in the right place.

This commit is contained in:
Greyson Parrelli
2025-01-28 10:30:58 -05:00
parent 1b2a62ae09
commit 2e89b8acee
5 changed files with 28 additions and 1 deletions

View File

@@ -79,6 +79,14 @@ object ExportSkips {
return log(sentTimestamp, "Identity verified update for ourselves.")
}
fun fromRecipientIsNotAnIndividual(sentTimestamp: Long): String {
return log(sentTimestamp, "The fromRecipient does not represent an individual person.")
}
fun oneOnOneMessageInTheWrongChat(sentTimestamp: Long): String {
return log(sentTimestamp, "A 1:1 message is located in the wrong chat.")
}
private fun log(sentTimestamp: Long, message: String): String {
return "[SKIP][$sentTimestamp] $message"
}

View File

@@ -1523,7 +1523,8 @@ data class ArchivedMediaObject(val mediaId: String, val cdn: Int)
class ExportState(val backupTime: Long, val mediaBackupEnabled: Boolean) {
val recipientIds: MutableSet<Long> = hashSetOf()
val threadIds: MutableSet<Long> = hashSetOf()
val localToRemoteCustomChatColors: MutableMap<Long, Int> = hashMapOf()
val contactRecipientIds: MutableSet<Long> = hashSetOf()
val threadIdToRecipientId: MutableMap<Long, Long> = hashMapOf()
}
class ImportState(val mediaRootBackupKey: MediaRootBackupKey) {

View File

@@ -427,6 +427,10 @@ private fun simpleUpdate(type: SimpleChatUpdate.Type): ChatUpdateMessage {
private fun BackupMessageRecord.toBasicChatItemBuilder(selfRecipientId: RecipientId, isGroupThread: Boolean, groupReceipts: List<GroupReceiptTable.GroupReceiptInfo>?, exportState: ExportState, backupStartTime: Long): ChatItem.Builder? {
val record = this
if (this.threadId !in exportState.threadIds) {
return null
}
val direction = when {
record.type.isDirectionlessType() && !record.remoteDeleted -> {
Direction.DIRECTIONLESS
@@ -450,6 +454,17 @@ private fun BackupMessageRecord.toBasicChatItemBuilder(selfRecipientId: Recipien
else -> record.fromRecipientId
}
if (!exportState.contactRecipientIds.contains(fromRecipientId)) {
Log.w(TAG, ExportSkips.fromRecipientIsNotAnIndividual(this.dateSent))
return null
}
val threadRecipientId = exportState.threadIdToRecipientId[record.threadId]!!
if (exportState.contactRecipientIds.contains(threadRecipientId) && fromRecipientId != threadRecipientId && fromRecipientId != selfRecipientId.toLong()) {
Log.w(TAG, ExportSkips.oneOnOneMessageInTheWrongChat(this.dateSent))
return null
}
val builder = ChatItem.Builder().apply {
chatId = record.threadId
authorId = fromRecipientId

View File

@@ -32,6 +32,7 @@ object ChatArchiveProcessor {
for (chat in reader) {
if (exportState.recipientIds.contains(chat.recipientId)) {
exportState.threadIds.add(chat.id)
exportState.threadIdToRecipientId[chat.id] = chat.recipientId
emitter.emit(Frame(chat = chat))
} else {
Log.w(TAG, "dropping thread for deleted recipient ${chat.recipientId}")

View File

@@ -38,6 +38,7 @@ object RecipientArchiveProcessor {
val releaseChannelId = signalStore.releaseChannelValues.releaseChannelRecipientId
if (releaseChannelId != null) {
exportState.recipientIds.add(releaseChannelId.toLong())
exportState.contactRecipientIds.add(releaseChannelId.toLong())
emitter.emit(
Frame(
recipient = ArchiveRecipient(
@@ -54,6 +55,7 @@ object RecipientArchiveProcessor {
for (recipient in reader) {
if (recipient != null) {
exportState.recipientIds.add(recipient.id)
exportState.contactRecipientIds.add(recipient.id)
emitter.emit(Frame(recipient = recipient))
}
}