2022-05-29 08:06:56 +01:00
|
|
|
//
|
|
|
|
// IntegrityErrorItemView.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by Evgeny on 28/05/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-05-31 07:55:13 +01:00
|
|
|
import SimpleXChat
|
2022-05-29 08:06:56 +01:00
|
|
|
|
|
|
|
struct IntegrityErrorItemView: View {
|
2023-10-31 09:44:57 +00:00
|
|
|
@ObservedObject var chat: Chat
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2023-04-16 12:35:45 +02:00
|
|
|
var msgError: MsgErrorType
|
2022-05-29 08:06:56 +01:00
|
|
|
var chatItem: ChatItem
|
|
|
|
|
2023-04-16 12:35:45 +02:00
|
|
|
var body: some View {
|
2023-10-31 09:44:57 +00:00
|
|
|
CIMsgError(chat: chat, chatItem: chatItem) {
|
2023-04-16 12:35:45 +02:00
|
|
|
switch msgError {
|
|
|
|
case .msgSkipped:
|
|
|
|
AlertManager.shared.showAlertMsg(
|
|
|
|
title: "Skipped messages",
|
|
|
|
message: """
|
|
|
|
It can happen when:
|
|
|
|
1. The messages expired in the sending client after 2 days or on the server after 30 days.
|
|
|
|
2. Message decryption failed, because you or your contact used old database backup.
|
|
|
|
3. The connection was compromised.
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
case .msgBadHash:
|
|
|
|
AlertManager.shared.showAlert(Alert(
|
|
|
|
title: Text("Bad message hash"),
|
|
|
|
message: Text("The hash of the previous message is different.") + Text("\n") +
|
|
|
|
Text(decryptErrorReason) + Text("\n") +
|
|
|
|
Text("Please report it to the developers.")
|
|
|
|
))
|
|
|
|
case .msgBadId: msgBadIdAlert()
|
|
|
|
case .msgDuplicate: msgBadIdAlert()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func msgBadIdAlert() {
|
|
|
|
AlertManager.shared.showAlert(Alert(
|
|
|
|
title: Text("Bad message ID"),
|
|
|
|
message: Text("""
|
|
|
|
The ID of the next message is incorrect (less or equal to the previous).
|
|
|
|
It can happen because of some bug or when the connection is compromised.
|
|
|
|
""") + Text("\n") +
|
|
|
|
Text("Please report it to the developers.")
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CIMsgError: View {
|
2023-10-31 09:44:57 +00:00
|
|
|
@ObservedObject var chat: Chat
|
2024-07-03 22:42:13 +01:00
|
|
|
@EnvironmentObject var theme: AppTheme
|
2023-04-16 12:35:45 +02:00
|
|
|
var chatItem: ChatItem
|
|
|
|
var onTap: () -> Void
|
|
|
|
|
2022-05-29 08:06:56 +01:00
|
|
|
var body: some View {
|
|
|
|
HStack(alignment: .bottom, spacing: 0) {
|
|
|
|
Text(chatItem.content.text)
|
|
|
|
.foregroundColor(.red)
|
|
|
|
.italic()
|
2024-07-03 22:42:13 +01:00
|
|
|
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary)
|
2022-05-29 08:06:56 +01:00
|
|
|
.padding(.horizontal, 12)
|
|
|
|
}
|
|
|
|
.padding(.leading, 12)
|
|
|
|
.padding(.vertical, 6)
|
|
|
|
.background(Color(uiColor: .tertiarySystemGroupedBackground))
|
|
|
|
.textSelection(.disabled)
|
2023-04-16 12:35:45 +02:00
|
|
|
.onTapGesture(perform: onTap)
|
2022-05-29 08:06:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IntegrityErrorItemView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2023-10-31 09:44:57 +00:00
|
|
|
IntegrityErrorItemView(chat: Chat.sampleData, msgError: .msgBadHash, chatItem: ChatItem.getIntegrityErrorSample())
|
2022-05-29 08:06:56 +01:00
|
|
|
}
|
|
|
|
}
|