mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-23 10:15:57 +00:00
fix loading chat, contact connection status info (#277)
This commit is contained in:
committed by
GitHub
parent
7883ca7657
commit
eeea33c7cb
@@ -20,6 +20,16 @@ struct ContentView: View {
|
||||
} catch {
|
||||
fatalError("Failed to start or load chats: \(error)")
|
||||
}
|
||||
|
||||
DispatchQueue.global().async {
|
||||
while(true) {
|
||||
do {
|
||||
try processReceivedMsg(chatModel, chatRecvMsg())
|
||||
} catch {
|
||||
print("error receiving message: ", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WelcomeView()
|
||||
|
||||
@@ -237,9 +237,19 @@ final class Chat: ObservableObject, Identifiable {
|
||||
var statusString: String {
|
||||
get {
|
||||
switch self {
|
||||
case .connected: return "Connected to contact's server"
|
||||
case let .error(err): return "Connecting to contact's server… (error: \(err))"
|
||||
default: return "Connecting to contact's server…"
|
||||
case .connected: return "Server connected"
|
||||
case let .error(err): return "Connecting server… (error: \(err))"
|
||||
default: return "Connecting server…"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var statusExplanation: String {
|
||||
get {
|
||||
switch self {
|
||||
case .connected: return "You are connected to the server you use to receve messages from this contact."
|
||||
case let .error(err): return "Trying to connect to the server you use to receve messages from this contact (error: \(err))."
|
||||
default: return "Trying to connect to the server you use to receve messages from this contact."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,6 @@ enum TerminalItem: Identifiable {
|
||||
|
||||
func chatSendCmd(_ cmd: ChatCommand) throws -> ChatResponse {
|
||||
var c = cmd.cmdString.cString(using: .utf8)!
|
||||
print("command", cmd.cmdString)
|
||||
// TODO some mechanism to update model without passing it - maybe Publisher / Subscriber?
|
||||
// DispatchQueue.main.async {
|
||||
// termId += 1
|
||||
|
||||
@@ -25,16 +25,6 @@ struct SimpleXApp: App {
|
||||
print(url)
|
||||
}
|
||||
.onAppear() {
|
||||
DispatchQueue.global().async {
|
||||
while(true) {
|
||||
do {
|
||||
try processReceivedMsg(chatModel, chatRecvMsg())
|
||||
} catch {
|
||||
print("error receiving message: ", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
chatModel.currentUser = try apiGetActiveUser()
|
||||
} catch {
|
||||
|
||||
@@ -9,7 +9,12 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ChatInfoView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@ObservedObject var chat: Chat
|
||||
@Binding var showChatInfo: Bool
|
||||
@State private var showDeleteContactAlert = false
|
||||
@State private var alertContact: Contact?
|
||||
@State private var showNetworkStatusInfo = false
|
||||
|
||||
var body: some View {
|
||||
VStack{
|
||||
@@ -22,10 +27,36 @@ struct ChatInfoView: View {
|
||||
Text(chat.chatInfo.fullName).font(.title)
|
||||
.padding(.bottom)
|
||||
|
||||
if case .direct = chat.chatInfo {
|
||||
HStack {
|
||||
serverImage()
|
||||
Text(chat.serverInfo.networkStatus.statusString)
|
||||
if case let .direct(contact) = chat.chatInfo {
|
||||
VStack {
|
||||
HStack {
|
||||
Button {
|
||||
showNetworkStatusInfo.toggle()
|
||||
} label: {
|
||||
serverImage()
|
||||
Text(chat.serverInfo.networkStatus.statusString)
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
}
|
||||
if showNetworkStatusInfo {
|
||||
Text(chat.serverInfo.networkStatus.statusExplanation)
|
||||
.font(.subheadline)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.horizontal, 64)
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
Button(role: .destructive) {
|
||||
alertContact = contact
|
||||
showDeleteContactAlert = true
|
||||
} label: {
|
||||
Label("Delete contact", systemImage: "trash")
|
||||
}
|
||||
.padding()
|
||||
.alert(isPresented: $showDeleteContactAlert) {
|
||||
deleteContactAlert(alertContact!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,12 +68,32 @@ struct ChatInfoView: View {
|
||||
return Image(systemName: status.imageName)
|
||||
.foregroundColor(status == .connected ? .green : .secondary)
|
||||
}
|
||||
|
||||
private func deleteContactAlert(_ contact: Contact) -> Alert {
|
||||
Alert(
|
||||
title: Text("Delete contact?"),
|
||||
message: Text("Contact and all messages will be deleted"),
|
||||
primaryButton: .destructive(Text("Delete")) {
|
||||
do {
|
||||
try apiDeleteChat(type: .direct, id: contact.apiId)
|
||||
chatModel.removeChat(contact.id)
|
||||
showChatInfo = false
|
||||
} catch let error {
|
||||
print("Error: \(error)")
|
||||
}
|
||||
alertContact = nil
|
||||
}, secondaryButton: .cancel() {
|
||||
alertContact = nil
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct ChatInfoView_Previews: PreviewProvider {
|
||||
var chatInfo = sampleDirectChatInfo
|
||||
|
||||
static var previews: some View {
|
||||
ChatInfoView(chat: Chat(chatInfo: sampleDirectChatInfo, chatItems: []))
|
||||
@State var showChatInfo = true
|
||||
return ChatInfoView(chat: Chat(chatInfo: sampleDirectChatInfo, chatItems: []), showChatInfo: $showChatInfo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ struct ChatView: View {
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
.sheet(isPresented: $showChatInfo) {
|
||||
ChatInfoView(chat: chat)
|
||||
ChatInfoView(chat: chat, showChatInfo: $showChatInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user