Meshtastic-Apple/Meshtastic/Views/Messages/MessageContextMenuItems.swift
Garth Vander Houwen f5ad2454bb
2.7.1 Working Changes 2 (#1393)
* Bump version

* Offset for map controls on the mesh map

* Only mark messages as read if they are unread (#1388)

* Only mark messages as read if they are unread

* More cheap optimizations

* Fix map control positions on the route recorder

* Add seperate state variable for delete all channel messges button since the channelSelection is being used for navigation

* Use a seperate state variable to track what user messages are being deleted for as userSelection is being used for navigation

* Get the ringtone if external notifications is enabled

* Fix RTTTL typo

* Dont show modem lights popover if we are on macOS 26 cause it crashes

* Fix annoying connect bottom background bug

* Update mesh map detents

* Move divider inside of the hstack keyboard toolbar

* Update Meshtastic/Helpers/MeshPackets.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove extra environment variable that is not getting used

* Fix ack time for 24hour locales, only hide TLS setting for the public MQTT broker

* Icon Composer Icon (#1374)

* Icon Composer Icon

* Tweaks to icon

---------

Co-authored-by: Jake-B <jake-b@users.noreply.github.com>

* Move if statement out of if statement

* Update Meshtastic/Views/Helpers/RXTXIndicatorView.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: jake-b <1012393+jake-b@users.noreply.github.com>
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
2025-09-12 23:03:38 -07:00

127 lines
3.4 KiB
Swift

import SwiftUI
import CoreData
import OSLog
struct MessageContextMenuItems: View {
@Environment(\.managedObjectContext) var context
@EnvironmentObject var accessoryManager: AccessoryManager
let message: MessageEntity
let tapBackDestination: MessageDestination
let isCurrentUser: Bool
@Binding var isShowingDeleteConfirmation: Bool
let onReply: () -> Void
var body: some View {
VStack {
if message.pkiEncrypted {
Label("Encrypted", systemImage: "lock")
}
Text("Channel") + Text(": \(message.channel)")
}
Menu("Tapback") {
ForEach(Tapbacks.allCases) { tb in
Button {
Task {
do {
try await accessoryManager.sendMessage(
message: tb.emojiString,
toUserNum: tapBackDestination.userNum,
channel: tapBackDestination.channelNum,
isEmoji: true,
replyID: message.messageId
)
Task { @MainActor in
self.context.refresh(tapBackDestination.managedObject, mergeChanges: true)
}
} catch {
Logger.services.warning("Failed to send tapback.")
}
}
} label: {
Text(tb.description)
Image(uiImage: tb.emojiString.image()!)
}
}
}
Button(action: onReply) {
Text("Reply")
Image(systemName: "arrowshape.turn.up.left")
}
Button {
UIPasteboard.general.string = message.messagePayload
} label: {
Text("Copy")
Image(systemName: "doc.on.doc")
}
Menu("Message Details") {
VStack {
let messageDate = Date(timeIntervalSince1970: TimeInterval(message.messageTimestamp))
Text("\(messageDate.formattedDate(format: MessageText.dateFormatString))").foregroundColor(.gray)
}
if !isCurrentUser && !(message.fromUser?.userNode?.viaMqtt ?? false) && message.fromUser?.userNode?.hopsAway ?? -1 == 0 {
VStack {
Text("SNR \(String(format: "%.2f", message.snr)) dB")
Text("RSSI \(String(format: "%.2f", message.rssi)) dBm")
}
} else if !isCurrentUser && !(message.fromUser?.userNode?.viaMqtt ?? false) {
VStack {
Text("Hops Away \(message.fromUser?.userNode?.hopsAway ?? 0)")
}
}
if isCurrentUser && message.receivedACK {
VStack {
Text("Received Ack") + Text(": \(message.receivedACK ? "✔️" : "")")
Text("Recipient Ack") + Text(": \(message.realACK ? "✔️" : "")")
}
} else if isCurrentUser && message.ackError == 0 {
// Empty Error
Text("Waiting")
} else if isCurrentUser && message.ackError > 0 {
let ackErrorVal = RoutingError(rawValue: Int(message.ackError))
Text("\(ackErrorVal?.display ?? "Empty Ack Error")")
.fixedSize(horizontal: false, vertical: true)
}
if isCurrentUser {
VStack {
let ackDate = Date(timeIntervalSince1970: TimeInterval(message.ackTimestamp))
let sixMonthsAgo = Calendar.current.date(byAdding: .month, value: -6, to: Date())
if ackDate >= sixMonthsAgo! {
Text("Ack Time: \(ackDate.formattedDate(format: MessageText.timeFormatString))")
.foregroundColor(.gray)
}
}
}
if message.ackSNR != 0 {
VStack {
Text("Ack SNR: \(String(format: "%.2f", message.ackSNR)) dB")
.font(.caption2)
.foregroundColor(.gray)
}
}
}
Divider()
Button(role: .destructive) {
isShowingDeleteConfirmation = true
} label: {
Text("Delete")
Image(systemName: "trash")
}
}
}
private extension MessageDestination {
var managedObject: NSManagedObject {
switch self {
case let .user(user): return user
case let .channel(channel): return channel
}
}
}