2021-12-24 23:41:18 -08:00
|
|
|
//
|
2022-01-01 08:03:46 -08:00
|
|
|
// UserMessageList.swift
|
|
|
|
|
// MeshtasticClient
|
|
|
|
|
//
|
|
|
|
|
// Created by Garth Vander Houwen on 12/24/21.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import CoreData
|
|
|
|
|
|
|
|
|
|
struct UserMessageList: View {
|
|
|
|
|
|
|
|
|
|
@Environment(\.managedObjectContext) var context
|
|
|
|
|
@EnvironmentObject var bleManager: BLEManager
|
2022-02-22 09:08:06 -10:00
|
|
|
@EnvironmentObject var userSettings: UserSettings
|
2022-01-01 08:03:46 -08:00
|
|
|
|
|
|
|
|
enum Field: Hashable {
|
|
|
|
|
case messageText
|
|
|
|
|
}
|
|
|
|
|
// Keyboard State
|
|
|
|
|
@State var typingMessage: String = ""
|
|
|
|
|
@State private var totalBytes = 0
|
|
|
|
|
var maxbytes = 228
|
|
|
|
|
@State var lastTypingMessage = ""
|
|
|
|
|
@FocusState var focusedField: Field?
|
|
|
|
|
|
2022-01-09 08:49:22 -08:00
|
|
|
@ObservedObject var user: UserEntity
|
2022-01-01 08:03:46 -08:00
|
|
|
|
|
|
|
|
@State var showDeleteMessageAlert = false
|
|
|
|
|
@State private var deleteMessageId: Int64 = 0
|
2022-01-01 22:55:25 -08:00
|
|
|
@State private var replyMessageId: Int64 = 0
|
2022-02-17 18:07:41 -08:00
|
|
|
@State private var sendPositionWithMessage: Bool = false
|
2022-01-01 15:33:53 -08:00
|
|
|
|
2022-06-04 09:53:59 -07:00
|
|
|
@State private var messageCount = 0
|
2022-06-06 22:24:35 -07:00
|
|
|
@State private var refreshId = UUID()
|
2022-01-01 08:03:46 -08:00
|
|
|
|
|
|
|
|
var body: some View {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
2022-01-05 06:37:29 -08:00
|
|
|
let firmwareVersion = bleManager.lastConnnectionVersion
|
2022-02-22 18:06:50 -10:00
|
|
|
let minimumVersion = "1.2.52"
|
2022-01-05 00:06:31 -08:00
|
|
|
let hasTapbackSupport = minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedAscending || minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedSame
|
|
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
VStack {
|
2022-01-01 21:21:04 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
ScrollViewReader { scrollView in
|
|
|
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
|
|
2022-06-04 07:41:52 -07:00
|
|
|
if user.messageList.count > 0 {
|
2022-06-04 09:53:59 -07:00
|
|
|
|
2022-06-04 07:41:52 -07:00
|
|
|
ForEach( user.messageList ) { (message: MessageEntity) in
|
2022-01-01 15:33:53 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
let currentUser: Bool = (bleManager.connectedPeripheral == nil) ? false : ((bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num == message.fromUser?.num) ? true : false )
|
2022-01-01 15:33:53 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
if message.toUser!.num == Int64(bleManager.broadcastNodeNum) || ((bleManager.connectedPeripheral) != nil && bleManager.connectedPeripheral.num == message.fromUser?.num) ? true : true {
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-05 08:31:30 -08:00
|
|
|
if message.replyID > 0 {
|
|
|
|
|
|
2022-06-04 09:53:59 -07:00
|
|
|
let messageReply = user.messageList.first(where: { $0.messageId == message.replyID })
|
2022-01-06 08:41:44 -08:00
|
|
|
|
2022-01-05 08:31:30 -08:00
|
|
|
HStack {
|
2022-02-18 19:01:14 -08:00
|
|
|
|
2022-01-06 08:41:44 -08:00
|
|
|
Text(messageReply?.messagePayload ?? "EMPTY MESSAGE").foregroundColor(.blue).font(.caption2)
|
2022-01-05 08:31:30 -08:00
|
|
|
.padding(10)
|
|
|
|
|
.overlay(
|
|
|
|
|
RoundedRectangle(cornerRadius: 18)
|
|
|
|
|
.stroke(Color.blue, lineWidth: 0.5)
|
|
|
|
|
)
|
|
|
|
|
Image(systemName: "arrowshape.turn.up.left.fill")
|
|
|
|
|
.symbolRenderingMode(.hierarchical)
|
|
|
|
|
.imageScale(.large).foregroundColor(.blue)
|
|
|
|
|
.padding(.trailing)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
HStack (alignment: .top) {
|
|
|
|
|
|
|
|
|
|
if currentUser { Spacer(minLength:50) }
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
if !currentUser {
|
2022-01-02 23:28:51 -08:00
|
|
|
CircleText(text: message.fromUser?.shortName ?? "???", color: currentUser ? .accentColor : Color(.darkGray), circleSize: 36, fontSize: 16).padding(.all, 5)
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VStack(alignment: currentUser ? .trailing : .leading) {
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
Text(message.messagePayload ?? "EMPTY MESSAGE")
|
|
|
|
|
.padding(10)
|
|
|
|
|
.foregroundColor(.white)
|
|
|
|
|
.background(currentUser ? Color.blue : Color(.darkGray))
|
|
|
|
|
.cornerRadius(15)
|
2022-01-01 21:21:04 -08:00
|
|
|
.contextMenu {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
if hasTapbackSupport {
|
|
|
|
|
|
|
|
|
|
Menu("Tapback response") {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "❤️", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent ❤️ Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("❤️ Tapback Failed") }
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Heart")
|
|
|
|
|
let image = "❤️".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "👍", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent 👍 Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("👍 Tapback Failed")}
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Thumbs Up")
|
|
|
|
|
let image = "👍".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "👎", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent 👎 Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("👎 Tapback Failed") }
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Thumbs Down")
|
|
|
|
|
let image = "👎".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "🤣", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent 🤣 Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("🤣 Tapback Failed") }
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
}) {
|
|
|
|
|
Text("HaHa")
|
|
|
|
|
let image = "🤣".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
|
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "‼️", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent ‼️ Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("‼️ Tapback Failed") }
|
|
|
|
|
|
|
|
|
|
}) {
|
|
|
|
|
Text("Exclamation Mark")
|
|
|
|
|
let image = "‼️".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "❓", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent ❓ Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("❓ Tapback Failed") }
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Question Mark")
|
|
|
|
|
let image = "❓".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: "💩", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
print("Sent 💩 Tapback")
|
2022-01-06 08:41:44 -08:00
|
|
|
self.context.refresh(user, mergeChanges: true)
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
} else { print("💩 Tapback Failed") }
|
|
|
|
|
|
|
|
|
|
}) {
|
|
|
|
|
Text("Poop")
|
|
|
|
|
let image = "💩".image()
|
|
|
|
|
Image(uiImage: image!)
|
|
|
|
|
}
|
2022-01-01 21:21:04 -08:00
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-05 00:06:31 -08:00
|
|
|
self.replyMessageId = message.messageId
|
|
|
|
|
self.focusedField = .messageText
|
|
|
|
|
|
|
|
|
|
print("I want to reply to \(message.messageId)")
|
2022-01-01 21:21:04 -08:00
|
|
|
}) {
|
2022-01-05 00:06:31 -08:00
|
|
|
Text("Reply")
|
|
|
|
|
Image(systemName: "arrowshape.turn.up.left.2.fill")
|
2022-01-01 21:21:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Button(action: {
|
2022-01-01 21:44:47 -08:00
|
|
|
UIPasteboard.general.string = message.messagePayload
|
2022-01-01 21:21:04 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Copy")
|
|
|
|
|
Image(systemName: "doc.on.doc")
|
|
|
|
|
}
|
2022-02-04 02:26:58 -08:00
|
|
|
Menu("Message Details") {
|
|
|
|
|
|
|
|
|
|
VStack {
|
|
|
|
|
|
2022-02-23 23:05:47 -10:00
|
|
|
let messageDate = Date(timeIntervalSince1970: TimeInterval(message.messageTimestamp))
|
2022-02-04 02:26:58 -08:00
|
|
|
|
2022-02-23 23:05:47 -10:00
|
|
|
Text("Sent \(messageDate, style: .date) \(messageDate, style: .time)").font(.caption2).foregroundColor(.gray)
|
2022-02-04 02:26:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VStack {
|
|
|
|
|
|
|
|
|
|
Text("Received ACK: \(message.receivedACK ? "✔️" : "")")
|
|
|
|
|
|
|
|
|
|
}
|
2022-02-23 23:05:47 -10:00
|
|
|
if message.receivedACK {
|
|
|
|
|
VStack {
|
|
|
|
|
|
|
|
|
|
let ackDate = Date(timeIntervalSince1970: TimeInterval(message.ackTimestamp))
|
|
|
|
|
Text("ACK \(ackDate, style: .date) \(ackDate, style: .time)").font(.caption2).foregroundColor(.gray)
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-13 20:09:42 -07:00
|
|
|
if message.ackSNR != 0 {
|
|
|
|
|
VStack {
|
|
|
|
|
|
|
|
|
|
Text("ACK SNR \(String(message.ackSNR))")
|
|
|
|
|
.font(.caption2)
|
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-04 02:26:58 -08:00
|
|
|
}
|
2022-01-01 21:21:04 -08:00
|
|
|
Divider()
|
|
|
|
|
Button(role: .destructive, action: {
|
2022-01-01 21:44:47 -08:00
|
|
|
self.showDeleteMessageAlert = true
|
|
|
|
|
self.deleteMessageId = message.messageId
|
|
|
|
|
print(deleteMessageId)
|
2022-01-01 21:21:04 -08:00
|
|
|
}) {
|
|
|
|
|
Text("Delete")
|
|
|
|
|
Image(systemName: "trash")
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
if hasTapbackSupport {
|
|
|
|
|
|
2022-01-04 22:57:33 -08:00
|
|
|
let tapbacks = message.value(forKey: "tapbacks") as! [MessageEntity]
|
2022-01-06 08:41:44 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
|
|
|
|
|
if tapbacks.count > 0 {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
VStack (alignment: .trailing) {
|
|
|
|
|
|
|
|
|
|
HStack {
|
2022-01-04 22:57:33 -08:00
|
|
|
|
2022-01-05 00:06:31 -08:00
|
|
|
ForEach( tapbacks ) { (tapback: MessageEntity) in
|
|
|
|
|
|
|
|
|
|
VStack {
|
|
|
|
|
|
|
|
|
|
let image = tapback.messagePayload!.image(fontSize: 20)
|
|
|
|
|
Image(uiImage: image!).font(.caption)
|
|
|
|
|
Text("\(tapback.fromUser?.shortName ?? "???")")
|
|
|
|
|
.font(.caption2)
|
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
|
.fixedSize()
|
|
|
|
|
.padding(.bottom, 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-04 22:57:33 -08:00
|
|
|
}
|
2022-01-05 00:06:31 -08:00
|
|
|
.padding(10)
|
|
|
|
|
.overlay(
|
|
|
|
|
RoundedRectangle(cornerRadius: 18)
|
|
|
|
|
.stroke(Color.gray, lineWidth: 1)
|
|
|
|
|
)
|
2022-01-04 22:57:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-05 00:06:31 -08:00
|
|
|
|
2022-01-04 22:57:33 -08:00
|
|
|
HStack {
|
2022-01-01 15:45:00 -08:00
|
|
|
|
2022-03-14 20:14:27 -07:00
|
|
|
if message.receivedACK {
|
2022-02-04 02:26:58 -08:00
|
|
|
|
2022-03-14 20:14:27 -07:00
|
|
|
Text("Acknowledged").font(.caption2).foregroundColor(.gray)
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-04 02:26:58 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
2022-02-04 02:26:58 -08:00
|
|
|
.padding(.bottom)
|
2022-06-04 09:53:59 -07:00
|
|
|
.id(user.messageList.firstIndex(of: message))
|
2022-01-02 10:05:13 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
if !currentUser {
|
|
|
|
|
Spacer(minLength:50)
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
2022-06-04 09:53:59 -07:00
|
|
|
.id(message.messageId)
|
2022-01-02 10:05:13 -08:00
|
|
|
.padding([.leading, .trailing])
|
2022-01-01 15:45:00 -08:00
|
|
|
.frame(maxWidth: .infinity)
|
2022-01-01 21:44:47 -08:00
|
|
|
.alert(isPresented: $showDeleteMessageAlert) {
|
|
|
|
|
Alert(title: Text("Are you sure you want to delete this message?"), message: Text("This action is permanent."),
|
|
|
|
|
primaryButton: .destructive(Text("Delete")) {
|
|
|
|
|
print("OK button tapped")
|
|
|
|
|
if deleteMessageId > 0 {
|
|
|
|
|
|
2022-06-04 09:53:59 -07:00
|
|
|
let message = user.messageList.first(where: { $0.messageId == deleteMessageId })
|
2022-01-01 21:44:47 -08:00
|
|
|
|
|
|
|
|
context.delete(message!)
|
|
|
|
|
do {
|
|
|
|
|
try context.save()
|
|
|
|
|
|
|
|
|
|
deleteMessageId = 0
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
print("Failed to delete message \(deleteMessageId)")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
|
)
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 21:44:47 -08:00
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
.listRowSeparator(.hidden)
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
|
|
|
|
.onAppear(perform: {
|
2022-01-01 15:33:53 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
self.bleManager.context = context
|
2022-02-22 09:08:06 -10:00
|
|
|
self.bleManager.userSettings = userSettings
|
2022-01-01 19:08:36 -08:00
|
|
|
|
2022-06-04 09:53:59 -07:00
|
|
|
messageCount = user.messageList.count
|
2022-06-06 22:24:35 -07:00
|
|
|
refreshId = UUID()
|
2022-03-07 21:30:18 -08:00
|
|
|
|
2022-06-04 09:53:59 -07:00
|
|
|
})
|
|
|
|
|
.onChange(of: messageCount, perform: { value in
|
|
|
|
|
//scrollView.scrollTo(user.messageList.firstIndex(of: user.messageList.last! ), anchor: .bottom)
|
|
|
|
|
scrollView.scrollTo(user.messageList.last!.messageId)
|
|
|
|
|
})
|
|
|
|
|
.onChange(of: user.messageList, perform: { messages in
|
|
|
|
|
|
2022-06-06 22:24:35 -07:00
|
|
|
refreshId = UUID()
|
2022-06-04 09:53:59 -07:00
|
|
|
messageCount = messages.count
|
2022-01-02 10:05:13 -08:00
|
|
|
})
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
|
|
|
|
|
HStack(alignment: .top) {
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
ZStack {
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
let kbType = UIKeyboardType(rawValue: UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0)
|
|
|
|
|
TextEditor(text: $typingMessage)
|
|
|
|
|
.onChange(of: typingMessage, perform: { value in
|
|
|
|
|
|
|
|
|
|
let size = value.utf8.count
|
|
|
|
|
totalBytes = size
|
|
|
|
|
if totalBytes <= maxbytes {
|
|
|
|
|
// Allow the user to type
|
|
|
|
|
lastTypingMessage = typingMessage
|
|
|
|
|
} else {
|
|
|
|
|
// Set the message back and remove the bytes over the count
|
|
|
|
|
self.typingMessage = lastTypingMessage
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
})
|
|
|
|
|
.keyboardType(kbType!)
|
|
|
|
|
.toolbar {
|
|
|
|
|
ToolbarItemGroup(placement: .keyboard) {
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
Button("Dismiss Keyboard") {
|
|
|
|
|
focusedField = nil
|
|
|
|
|
}
|
|
|
|
|
.font(.subheadline)
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
Spacer()
|
2022-02-17 18:07:41 -08:00
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
let userLongName = bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral.longName : "Unknown"
|
|
|
|
|
sendPositionWithMessage = true
|
2022-02-18 06:22:02 -08:00
|
|
|
if user.num == bleManager.broadcastNodeNum {
|
|
|
|
|
|
2022-02-23 23:05:47 -10:00
|
|
|
if userSettings.meshtasticUsername.count > 0 {
|
|
|
|
|
|
|
|
|
|
typingMessage = "📍 " + userSettings.meshtasticUsername + " has shared their position with the mesh from node " + userLongName
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
typingMessage = "📍 " + userLongName + " has shared their position with the mesh."
|
|
|
|
|
|
|
|
|
|
}
|
2022-02-18 06:22:02 -08:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2022-02-23 23:05:47 -10:00
|
|
|
if userSettings.meshtasticUsername.count > 0 {
|
|
|
|
|
|
|
|
|
|
typingMessage = "📍 " + userSettings.meshtasticUsername + " has shared their position with you from node " + userLongName
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
typingMessage = "📍 " + userLongName + " has shared their position with you."
|
|
|
|
|
}
|
2022-02-18 06:22:02 -08:00
|
|
|
}
|
2022-02-17 18:07:41 -08:00
|
|
|
} label: {
|
2022-02-18 06:22:02 -08:00
|
|
|
Image(systemName: "mappin.and.ellipse")
|
|
|
|
|
.symbolRenderingMode(.hierarchical)
|
|
|
|
|
.imageScale(.large).foregroundColor(.accentColor)
|
2022-02-17 18:07:41 -08:00
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
ProgressView("Bytes: \(totalBytes) / \(maxbytes)", value: Double(totalBytes), total: Double(maxbytes))
|
|
|
|
|
.frame(width: 130)
|
|
|
|
|
.padding(5)
|
|
|
|
|
.font(.subheadline)
|
|
|
|
|
.accentColor(.accentColor)
|
|
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
.padding(.horizontal, 8)
|
|
|
|
|
.focused($focusedField, equals: .messageText)
|
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
|
.frame(minHeight: 100, maxHeight: 160)
|
|
|
|
|
|
|
|
|
|
Text(typingMessage).opacity(0).padding(.all, 0)
|
2022-01-01 08:03:46 -08:00
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
}
|
|
|
|
|
.overlay(RoundedRectangle(cornerRadius: 20).stroke(.tertiary, lineWidth: 1))
|
|
|
|
|
.padding(.bottom, 15)
|
|
|
|
|
|
|
|
|
|
Button(action: {
|
2022-03-29 21:16:15 -07:00
|
|
|
if bleManager.sendMessage(message: typingMessage, toUserNum: user.num, isEmoji: false, replyID: replyMessageId) {
|
2022-01-01 15:45:00 -08:00
|
|
|
typingMessage = ""
|
|
|
|
|
focusedField = nil
|
2022-01-01 22:55:25 -08:00
|
|
|
replyMessageId = 0
|
2022-02-17 18:07:41 -08:00
|
|
|
if sendPositionWithMessage {
|
|
|
|
|
if bleManager.sendPosition(destNum: user.num, wantResponse: false) {
|
|
|
|
|
print("Position Sent")
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
|
|
|
|
|
2022-01-01 15:45:00 -08:00
|
|
|
}) {
|
|
|
|
|
Image(systemName: "arrow.up.circle.fill").font(.largeTitle).foregroundColor(.blue)
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
2022-01-01 15:45:00 -08:00
|
|
|
.padding(.all, 15)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 08:03:46 -08:00
|
|
|
.navigationViewStyle(.stack)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
|
.toolbar {
|
|
|
|
|
ToolbarItem(placement: .principal) {
|
|
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
|
|
2022-01-02 23:28:51 -08:00
|
|
|
CircleText(text: user.shortName ?? "???", color: .blue, circleSize: 42, fontSize: 20).fixedSize()
|
|
|
|
|
Text(user.longName ?? "Unknown").font(.headline).fixedSize()
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
|
|
|
ZStack {
|
|
|
|
|
|
|
|
|
|
ConnectedDevice(
|
|
|
|
|
bluetoothOn: bleManager.isSwitchedOn,
|
|
|
|
|
deviceConnected: bleManager.connectedPeripheral != nil,
|
2022-05-27 19:18:33 -07:00
|
|
|
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.lastFourCode : "????")
|
2022-01-01 08:03:46 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|