mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: do not create decryption error chat items for earlier messages (#2189)
* core: do not create decryption error chat items for earlier messages * do not report earlier error, mobile items, fix tests
This commit is contained in:
committed by
GitHub
parent
393238f47c
commit
5b4c183466
@@ -1466,10 +1466,10 @@ data class ChatItem (
|
||||
file = null
|
||||
)
|
||||
|
||||
fun invalidJSON(json: String): ChatItem =
|
||||
fun invalidJSON(chatDir: CIDirection?, meta: CIMeta?, json: String): ChatItem =
|
||||
ChatItem(
|
||||
chatDir = CIDirection.DirectSnd(),
|
||||
meta = CIMeta.invalidJSON(),
|
||||
chatDir = chatDir ?: CIDirection.DirectSnd(),
|
||||
meta = meta ?: CIMeta.invalidJSON(),
|
||||
content = CIContent.InvalidJSON(json),
|
||||
quotedItem = null,
|
||||
file = null
|
||||
@@ -1681,13 +1681,11 @@ sealed class CIContent: ItemContent {
|
||||
@Serializable
|
||||
enum class MsgDecryptError {
|
||||
@SerialName("ratchetHeader") RatchetHeader,
|
||||
@SerialName("earlier") Earlier,
|
||||
@SerialName("tooManySkipped") TooManySkipped;
|
||||
|
||||
val text: String get() = when (this) {
|
||||
RatchetHeader -> generalGetString(R.string.decryption_error_permanent)
|
||||
Earlier -> generalGetString(R.string.decryption_error)
|
||||
TooManySkipped -> generalGetString(R.string.decryption_error_permanent)
|
||||
RatchetHeader -> generalGetString(R.string.decryption_error)
|
||||
TooManySkipped -> generalGetString(R.string.decryption_error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3011,9 +3011,15 @@ private fun parseChatData(chat: JsonElement): Chat {
|
||||
?: ChatInfo.InvalidJSON(json.encodeToString(chat.jsonObject["chatInfo"]))
|
||||
val chatStats = decodeObject(Chat.ChatStats.serializer(), chat.jsonObject["chatStats"])!!
|
||||
val chatItems: List<ChatItem> = chat.jsonObject["chatItems"]!!.jsonArray.map {
|
||||
decodeObject(ChatItem.serializer(), it) ?: ChatItem.invalidJSON(json.encodeToString(it))
|
||||
decodeObject(ChatItem.serializer(), it) ?: parseChatItem(it)
|
||||
}
|
||||
return Chat(chatInfo, chatItems, chatStats)
|
||||
return Chat(chatInfo, chatItems, chatStats)
|
||||
}
|
||||
|
||||
private fun parseChatItem(j: JsonElement): ChatItem {
|
||||
val chatDir: CIDirection? = decodeObject(CIDirection.serializer(), j.jsonObject["chatDir"])
|
||||
val meta: CIMeta? = decodeObject(CIMeta.serializer(), j.jsonObject["meta"])
|
||||
return ChatItem.invalidJSON(chatDir, meta, json.encodeToString(j))
|
||||
}
|
||||
|
||||
private fun <T> decodeObject(deserializer: DeserializationStrategy<T>, obj: JsonElement?): T? =
|
||||
|
||||
-2
@@ -15,8 +15,6 @@ fun CIRcvDecryptionError(msgDecryptError: MsgDecryptError, msgCount: UInt, ci: C
|
||||
MsgDecryptError.RatchetHeader -> String.format(generalGetString(R.string.alert_text_decryption_error_header), msgCount.toLong()) + "\n" +
|
||||
generalGetString(R.string.alert_text_fragment_encryption_out_of_sync_old_database) + "\n" +
|
||||
generalGetString(R.string.alert_text_fragment_permanent_error_reconnect)
|
||||
MsgDecryptError.Earlier -> String.format(generalGetString(R.string.alert_text_decryption_error_earlier), msgCount.toLong()) + "\n" +
|
||||
generalGetString(R.string.alert_text_fragment_encryption_out_of_sync_old_database)
|
||||
MsgDecryptError.TooManySkipped -> String.format(generalGetString(R.string.alert_text_decryption_error_too_many_skipped), msgCount.toLong()) + "\n" +
|
||||
generalGetString(R.string.alert_text_fragment_encryption_out_of_sync_old_database) + "\n" +
|
||||
generalGetString(R.string.alert_text_fragment_permanent_error_reconnect)
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
<string name="moderated_description">moderated</string>
|
||||
<string name="invalid_chat">invalid chat</string>
|
||||
<string name="invalid_data">invalid data</string>
|
||||
<string name="decryption_error_permanent">Permanent decryption error</string>
|
||||
<string name="decryption_error">Decryption error</string>
|
||||
|
||||
<!-- PendingContactConnection - ChatModel.kt -->
|
||||
@@ -749,7 +748,6 @@
|
||||
<string name="alert_title_msg_bad_id">Bad message ID</string>
|
||||
<string name="alert_text_msg_bad_id">The ID of the next message is incorrect (less or equal to the previous).\nIt can happen because of some bug or when the connection is compromised.</string>
|
||||
<string name="alert_text_decryption_error_header"><xliff:g id="message count" example="1">%1$d</xliff:g> messages failed to decrypt.</string>
|
||||
<string name="alert_text_decryption_error_earlier"><xliff:g id="message count" example="1">%1$d</xliff:g> messages failed to decrypt and won\'t be shown.</string>
|
||||
<string name="alert_text_decryption_error_too_many_skipped"><xliff:g id="message count" example="1">%1$d</xliff:g> messages skipped.</string>
|
||||
<string name="alert_text_fragment_encryption_out_of_sync_old_database">It can happen when you or your connection used the old database backup.</string>
|
||||
<string name="alert_text_fragment_permanent_error_reconnect">This error is permanent for this connection, please re-connect.</string>
|
||||
|
||||
Reference in New Issue
Block a user