diff --git a/MeshtasticClient/Model/MessageData.swift b/MeshtasticClient/Model/MessageData.swift index 2164bbfd..c0edf8db 100644 --- a/MeshtasticClient/Model/MessageData.swift +++ b/MeshtasticClient/Model/MessageData.swift @@ -37,4 +37,16 @@ class MessageData: ObservableObject { } } } + func save() { + DispatchQueue.global(qos: .background).async { [weak self] in + guard let messages = self?.messages else { fatalError("Self out of scope") } + guard let data = try? JSONEncoder().encode(messages) else { fatalError("Error encoding data") } + do { + let outfile = Self.fileURL + try data.write(to: outfile) + } catch { + fatalError("Can't write to file") + } + } + } } diff --git a/MeshtasticClient/Views/Helpers/MessageBubble.swift b/MeshtasticClient/Views/Helpers/MessageBubble.swift index d73b875c..f77d7bce 100644 --- a/MeshtasticClient/Views/Helpers/MessageBubble.swift +++ b/MeshtasticClient/Views/Helpers/MessageBubble.swift @@ -7,29 +7,26 @@ struct MessageBubble: View { var shortName: String var body: some View { - VStack { - HStack (alignment: .top) { - - CircleText(text: shortName, color: isCurrentUser ? Color.blue : Color(.darkGray)).padding(.all, 5) - VStack (alignment: .leading) { - Text(contentMessage) - .textSelection(.enabled) - .padding(10) - .foregroundColor(.white) - .background(isCurrentUser ? Color.blue : Color(.darkGray)) - .cornerRadius(10) - HStack (spacing: 4) { - let messageDate = Date(timeIntervalSince1970: TimeInterval(time)) - - Text(messageDate, style: .date).font(.caption2).foregroundColor(.gray) - Text(messageDate, style: .time).font(.caption2).foregroundColor(.gray) - } - .padding(.bottom, 10) - } - Spacer() - } + HStack (alignment: .top) { - }.padding(.bottom, 1) + CircleText(text: shortName, color: isCurrentUser ? Color.blue : Color(.darkGray)).padding(.all, 5) + VStack (alignment: .leading) { + Text(contentMessage) + .textSelection(.enabled) + .padding(10) + .foregroundColor(.white) + .background(isCurrentUser ? Color.blue : Color(.darkGray)) + .cornerRadius(10) + HStack (spacing: 4) { + let messageDate = Date(timeIntervalSince1970: TimeInterval(time)) + + Text(messageDate, style: .date).font(.caption2).foregroundColor(.gray) + Text(messageDate, style: .time).font(.caption2).foregroundColor(.gray) + } + .padding(.bottom, 10) + } + Spacer() + } } }