mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-12 05:07:56 +00:00
* ios: snapshot tests render all previews at fixed dates * ios: previews of your servers and terminal render without errors * ios: snapshots fill the screen height for lists, skip device migration * ios: snapshots show the sample user, secondary chat preview has items * ios: snapshots skip previews of live prices, profiles and console * ci: references of all iOS previews * ci: snapshot docs state window height, exclusions and timing * ios: snapshots skip previews with a blinking caret or a spinner * ios: snapshots end editing and stop animations, restoring 8 previews * ci: references of the restored cursor and spinner previews * ios: chat item previews clip items to bubbles as the chat view does * ci: references of chat item previews with bubbles
105 lines
3.6 KiB
Swift
105 lines
3.6 KiB
Swift
//
|
|
// IntegrityErrorItemView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 28/05/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
// Spec: spec/client/chat-view.md
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
// Spec: spec/client/chat-view.md#IntegrityErrorItemView
|
|
struct IntegrityErrorItemView: View {
|
|
@ObservedObject var chat: Chat
|
|
@EnvironmentObject var theme: AppTheme
|
|
var msgError: MsgErrorType
|
|
var chatItem: ChatItem
|
|
|
|
var body: some View {
|
|
CIMsgError(chat: chat, chatItem: chatItem) {
|
|
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.") + textNewLine +
|
|
Text(decryptErrorReason) + textNewLine +
|
|
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.
|
|
""") + textNewLine +
|
|
Text("Please report it to the developers.")
|
|
))
|
|
}
|
|
}
|
|
|
|
struct CIMsgError: View {
|
|
@ObservedObject var chat: Chat
|
|
@EnvironmentObject var theme: AppTheme
|
|
var chatItem: ChatItem
|
|
var onTap: () -> Void
|
|
|
|
var body: some View {
|
|
HStack(alignment: .bottom, spacing: 0) {
|
|
Text(chatItem.content.text)
|
|
.foregroundColor(.red)
|
|
.italic()
|
|
CIMetaView(chat: chat, chatItem: chatItem, metaColor: theme.colors.secondary)
|
|
.padding(.horizontal, 12)
|
|
}
|
|
.padding(.leading, 12)
|
|
.padding(.vertical, 6)
|
|
.background { chatItemFrameColor(chatItem, theme).modifier(ChatTailPadding()) }
|
|
.textSelection(.disabled)
|
|
.simultaneousGesture(TapGesture().onEnded(onTap))
|
|
}
|
|
}
|
|
|
|
struct RcvMsgErrorItemView: View {
|
|
@ObservedObject var chat: Chat
|
|
var rcvMsgError: RcvMsgError
|
|
var chatItem: ChatItem
|
|
|
|
var body: some View {
|
|
CIMsgError(chat: chat, chatItem: chatItem) {
|
|
let message: LocalizedStringKey = switch rcvMsgError {
|
|
case let .dropped(attempts): "The app removed this message after \(attempts) attempts to receive it."
|
|
case let .parseError(parseError): "\(parseError)"
|
|
}
|
|
AlertManager.shared.showAlertMsg(
|
|
title: "Message error",
|
|
message: message
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct IntegrityErrorItemView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
let ci = previewDated(ChatItem.getIntegrityErrorSample())
|
|
IntegrityErrorItemView(chat: Chat.sampleData, msgError: .msgBadHash, chatItem: ci).modifier(ChatItemClipped(ci, tailVisible: true))
|
|
}
|
|
}
|