From 8983e13b21dd60f843d83c8b29c7055e2521db7b Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 26 Nov 2022 10:22:51 -0800 Subject: [PATCH] Honor user mute for dm notifications --- Meshtastic/Helpers/MeshPackets.swift | 15 +++++++++++++-- Meshtastic/Views/Messages/Contacts.swift | 4 +--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 1a842da7..aba02576 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1296,9 +1296,20 @@ func textMessageAppPacket(packet: MeshPacket, connectedNode: Int64, context: NSM if messageSaved { - // Send a DM Notification if newMessage.fromUser != nil && newMessage.toUser != nil && !(newMessage.fromUser?.mute ?? false) { - // Create an iOS Notification for the received message and schedule it immediately + // Create an iOS Notification for the received DM message and schedule it immediately + let manager = LocalNotificationManager() + manager.notifications = [ + Notification( + id: ("notification.id.\(newMessage.messageId)"), + title: "\(newMessage.fromUser?.longName ?? "Unknown")", + subtitle: "AKA \(newMessage.fromUser?.shortName ?? "???")", + content: messageText) + ] + manager.schedule() + MeshLogger.log("💬 iOS Notification Scheduled for text message from \(newMessage.fromUser?.longName ?? "Unknown")") + } else if newMessage.fromUser != nil && newMessage.toUser == nil { + // Create an iOS Notification for the received private channel message and schedule it immediately let manager = LocalNotificationManager() manager.notifications = [ Notification( diff --git a/Meshtastic/Views/Messages/Contacts.swift b/Meshtastic/Views/Messages/Contacts.swift index 99391666..a20b1841 100644 --- a/Meshtastic/Views/Messages/Contacts.swift +++ b/Meshtastic/Views/Messages/Contacts.swift @@ -161,12 +161,10 @@ struct Contacts: View { Button { setUserMute(num: user.num, mute: !user.mute, context: context) } label: { - Label(user.mute ? "Show Alerts" : "Hide Alerts", systemImage: "bell") + Label(user.mute ? "Show Alerts" : "Hide Alerts", systemImage: user.mute ? "bell" : "bell.slash") } - if user.messageList.count > 0 { Button(role: .destructive) { - print("I want to delete all the messages for \(user.longName)") isPresentingDeleteUserMessagesConfirm = true } label: { Label("Delete Messages", systemImage: "trash")