fix loading chat, contact connection status info (#277)
This commit is contained in:
1 parent
7883ca7657
commit
eeea33c7cb
6 files changed
+80
-20
No files matched your search
@@ -20,6 +20,16 @@ struct ContentView: View {
|
|||||||
} catch {
|
} catch {
|
||||||
fatalError("Failed to start or load chats: \(error)")
|
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 {
|
} else {
|
||||||
WelcomeView()
|
WelcomeView()
|
||||||
|
|||||||
@@ -237,9 +237,19 @@ final class Chat: ObservableObject, Identifiable {
|
|||||||
var statusString: String {
|
var statusString: String {
|
||||||
get {
|
get {
|
||||||
switch self {
|
switch self {
|
||||||
case .connected: return "Connected to contact's server"
|
case .connected: return "Server connected"
|
||||||
case let .error(err): return "Connecting to contact's server… (error: \(err))"
|
case let .error(err): return "Connecting server… (error: \(err))"
|
||||||
default: return "Connecting to contact's server…"
|
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 {
|
func chatSendCmd(_ cmd: ChatCommand) throws -> ChatResponse {
|
||||||
var c = cmd.cmdString.cString(using: .utf8)!
|
var c = cmd.cmdString.cString(using: .utf8)!
|
||||||
print("command", cmd.cmdString)
|
|
||||||
// TODO some mechanism to update model without passing it - maybe Publisher / Subscriber?
|
// TODO some mechanism to update model without passing it - maybe Publisher / Subscriber?
|
||||||
// DispatchQueue.main.async {
|
// DispatchQueue.main.async {
|
||||||
// termId += 1
|
// termId += 1
|
||||||
|
|||||||
@@ -25,16 +25,6 @@ struct SimpleXApp: App {
|
|||||||
print(url)
|
print(url)
|
||||||
}
|
}
|
||||||
.onAppear() {
|
.onAppear() {
|
||||||
DispatchQueue.global().async {
|
|
||||||
while(true) {
|
|
||||||
do {
|
|
||||||
try processReceivedMsg(chatModel, chatRecvMsg())
|
|
||||||
} catch {
|
|
||||||
print("error receiving message: ", error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
chatModel.currentUser = try apiGetActiveUser()
|
chatModel.currentUser = try apiGetActiveUser()
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -9,7 +9,12 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ChatInfoView: View {
|
struct ChatInfoView: View {
|
||||||
|
@EnvironmentObject var chatModel: ChatModel
|
||||||
@ObservedObject var chat: Chat
|
@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 {
|
var body: some View {
|
||||||
VStack{
|
VStack{
|
||||||
@@ -22,10 +27,36 @@ struct ChatInfoView: View {
|
|||||||
Text(chat.chatInfo.fullName).font(.title)
|
Text(chat.chatInfo.fullName).font(.title)
|
||||||
.padding(.bottom)
|
.padding(.bottom)
|
||||||
|
|
||||||
if case .direct = chat.chatInfo {
|
if case let .direct(contact) = chat.chatInfo {
|
||||||
HStack {
|
VStack {
|
||||||
serverImage()
|
HStack {
|
||||||
Text(chat.serverInfo.networkStatus.statusString)
|
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)
|
return Image(systemName: status.imageName)
|
||||||
.foregroundColor(status == .connected ? .green : .secondary)
|
.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 {
|
struct ChatInfoView_Previews: PreviewProvider {
|
||||||
var chatInfo = sampleDirectChatInfo
|
var chatInfo = sampleDirectChatInfo
|
||||||
|
|
||||||
static var previews: some View {
|
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)
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showChatInfo) {
|
.sheet(isPresented: $showChatInfo) {
|
||||||
ChatInfoView(chat: chat)
|
ChatInfoView(chat: chat, showChatInfo: $showChatInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user