Fix more fromRecipient backup bugs.
This commit is contained in:
parent
511412e1c5
commit
da33306655
3 changed files with 41 additions and 7 deletions
|
@ -67,6 +67,18 @@ object ExportSkips {
|
|||
return log(0, "Sticker pack had an invalid packKey.")
|
||||
}
|
||||
|
||||
fun identityUpdateForSelf(sentTimestamp: Long): String {
|
||||
return log(sentTimestamp, "Identity update for ourselves.")
|
||||
}
|
||||
|
||||
fun identityDefaultForSelf(sentTimestamp: Long): String {
|
||||
return log(sentTimestamp, "Identity default update for ourselves.")
|
||||
}
|
||||
|
||||
fun identityVerifiedForSelf(sentTimestamp: Long): String {
|
||||
return log(sentTimestamp, "Identity verified update for ourselves.")
|
||||
}
|
||||
|
||||
private fun log(sentTimestamp: Long, message: String): String {
|
||||
return "[SKIP][$sentTimestamp] $message"
|
||||
}
|
||||
|
|
|
@ -166,17 +166,26 @@ class ChatItemArchiveExporter(
|
|||
}
|
||||
|
||||
MessageTypes.isIdentityUpdate(record.type) -> {
|
||||
if (record.fromRecipientId == selfRecipientId.toLong()) continue
|
||||
if (record.fromRecipientId == selfRecipientId.toLong()) {
|
||||
Log.w(TAG, ExportSkips.identityUpdateForSelf(record.dateSent))
|
||||
continue
|
||||
}
|
||||
builder.updateMessage = simpleUpdate(SimpleChatUpdate.Type.IDENTITY_UPDATE)
|
||||
}
|
||||
|
||||
MessageTypes.isIdentityVerified(record.type) -> {
|
||||
if (record.fromRecipientId == selfRecipientId.toLong()) continue
|
||||
if (record.toRecipientId == selfRecipientId.toLong()) {
|
||||
Log.w(TAG, ExportSkips.identityVerifiedForSelf(record.dateSent))
|
||||
continue
|
||||
}
|
||||
builder.updateMessage = simpleUpdate(SimpleChatUpdate.Type.IDENTITY_VERIFIED)
|
||||
}
|
||||
|
||||
MessageTypes.isIdentityDefault(record.type) -> {
|
||||
if (record.fromRecipientId == selfRecipientId.toLong()) continue
|
||||
if (record.toRecipientId == selfRecipientId.toLong()) {
|
||||
Log.w(TAG, ExportSkips.identityDefaultForSelf(record.dateSent))
|
||||
continue
|
||||
}
|
||||
builder.updateMessage = simpleUpdate(SimpleChatUpdate.Type.IDENTITY_DEFAULT)
|
||||
}
|
||||
|
||||
|
@ -434,7 +443,7 @@ private fun BackupMessageRecord.toBasicChatItemBuilder(selfRecipientId: Recipien
|
|||
// We want to ensure all outgoing messages are from ourselves.
|
||||
val fromRecipientId = when {
|
||||
direction == Direction.OUTGOING -> selfRecipientId.toLong()
|
||||
direction == Direction.DIRECTIONLESS && MessageTypes.isOutgoingMessageType(record.type) -> selfRecipientId.toLong()
|
||||
record.type.isIdentityVerifyType() -> record.toRecipientId
|
||||
else -> record.fromRecipientId
|
||||
}
|
||||
|
||||
|
@ -1329,6 +1338,11 @@ private fun Long.isDirectionlessType(): Boolean {
|
|||
MessageTypes.isGroupQuit(this)
|
||||
}
|
||||
|
||||
private fun Long.isIdentityVerifyType(): Boolean {
|
||||
return MessageTypes.isIdentityVerified(this) ||
|
||||
MessageTypes.isIdentityDefault(this)
|
||||
}
|
||||
|
||||
private fun String.e164ToLong(): Long? {
|
||||
val fixed = if (this.startsWith("+")) {
|
||||
this.substring(1)
|
||||
|
|
|
@ -468,11 +468,13 @@ class ChatItemArchiveImporter(
|
|||
private fun ChatItem.toMessageContentValues(fromRecipientId: RecipientId, chatRecipientId: RecipientId, threadId: Long): ContentValues {
|
||||
val contentValues = ContentValues()
|
||||
|
||||
val toRecipientId = if (this.outgoing != null) chatRecipientId else selfId
|
||||
|
||||
contentValues.put(MessageTable.TYPE, this.getMessageType())
|
||||
contentValues.put(MessageTable.DATE_SENT, this.dateSent)
|
||||
contentValues.put(MessageTable.DATE_SERVER, this.incoming?.dateServerSent ?: -1)
|
||||
contentValues.put(MessageTable.FROM_RECIPIENT_ID, fromRecipientId.serialize())
|
||||
contentValues.put(MessageTable.TO_RECIPIENT_ID, (if (this.outgoing != null) chatRecipientId else selfId).serialize())
|
||||
contentValues.put(MessageTable.TO_RECIPIENT_ID, toRecipientId.serialize())
|
||||
contentValues.put(MessageTable.THREAD_ID, threadId)
|
||||
contentValues.put(MessageTable.DATE_RECEIVED, this.incoming?.dateReceived ?: this.dateSent)
|
||||
contentValues.put(MessageTable.RECEIPT_TIMESTAMP, this.outgoing?.sendStatus?.maxOfOrNull { it.timestamp } ?: 0)
|
||||
|
@ -525,7 +527,7 @@ class ChatItemArchiveImporter(
|
|||
when {
|
||||
this.standardMessage != null -> contentValues.addStandardMessage(this.standardMessage)
|
||||
this.remoteDeletedMessage != null -> contentValues.put(MessageTable.REMOTE_DELETED, 1)
|
||||
this.updateMessage != null -> contentValues.addUpdateMessage(this.updateMessage)
|
||||
this.updateMessage != null -> contentValues.addUpdateMessage(this.updateMessage, fromRecipientId, toRecipientId)
|
||||
this.paymentNotification != null -> contentValues.addPaymentNotification(this, chatRecipientId)
|
||||
this.giftBadge != null -> contentValues.addGiftBadge(this.giftBadge)
|
||||
this.viewOnceMessage != null -> contentValues.addViewOnce(this.viewOnceMessage)
|
||||
|
@ -672,7 +674,7 @@ class ChatItemArchiveImporter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun ContentValues.addUpdateMessage(updateMessage: ChatUpdateMessage) {
|
||||
private fun ContentValues.addUpdateMessage(updateMessage: ChatUpdateMessage, fromRecipientId: RecipientId, toRecipientId: RecipientId) {
|
||||
var typeFlags: Long = 0
|
||||
when {
|
||||
updateMessage.simpleUpdate != null -> {
|
||||
|
@ -696,6 +698,12 @@ class ChatItemArchiveImporter(
|
|||
SimpleChatUpdate.Type.UNBLOCKED -> MessageTypes.SPECIAL_TYPE_UNBLOCKED or typeWithoutBase
|
||||
SimpleChatUpdate.Type.MESSAGE_REQUEST_ACCEPTED -> MessageTypes.SPECIAL_TYPE_MESSAGE_REQUEST_ACCEPTED or typeWithoutBase
|
||||
}
|
||||
|
||||
// Identity verification changes have to/from swapped
|
||||
if (updateMessage.simpleUpdate.type == SimpleChatUpdate.Type.IDENTITY_VERIFIED || updateMessage.simpleUpdate.type == SimpleChatUpdate.Type.IDENTITY_DEFAULT) {
|
||||
put(MessageTable.FROM_RECIPIENT_ID, toRecipientId.serialize())
|
||||
put(MessageTable.TO_RECIPIENT_ID, fromRecipientId.serialize())
|
||||
}
|
||||
}
|
||||
updateMessage.expirationTimerChange != null -> {
|
||||
typeFlags = getAsLong(MessageTable.TYPE) or MessageTypes.EXPIRATION_TIMER_UPDATE_BIT
|
||||
|
|
Loading…
Add table
Reference in a new issue