From 61a4c51f45f648757dc810458f23ce95af80abb5 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 26 Nov 2022 19:21:31 -0800 Subject: [PATCH] Partially working channel mute --- Meshtastic/Persistence/UpdateCoreData.swift | 38 --------------------- Meshtastic/Views/Messages/Contacts.swift | 19 ++++++++++- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/Meshtastic/Persistence/UpdateCoreData.swift b/Meshtastic/Persistence/UpdateCoreData.swift index 6dc061ed..47e9e982 100644 --- a/Meshtastic/Persistence/UpdateCoreData.swift +++ b/Meshtastic/Persistence/UpdateCoreData.swift @@ -105,41 +105,3 @@ public func clearCoreDataDatabase(context: NSManagedObjectContext) { } } } - -public func setChannelMute(channel: Int32, mute: Bool, context: NSManagedObjectContext) { - - let fetchChannelRequest: NSFetchRequest = NSFetchRequest.init(entityName: "ChannelEntity") - fetchChannelRequest.predicate = NSPredicate(format: "index == %lld", Int32(channel)) - do { - let fetchedChannel = try context.fetch(fetchChannelRequest) as! [ChannelEntity] - fetchedChannel[0].mute = mute - fetchedChannel[0].objectWillChange.send() - - do { - try context.save() - } catch { - context.rollback() - print("💥 Save Channel Error") - } - } catch { - print("💥 Fetch Channel Error") - } -} - -public func setUserMute(num: Int64, mute: Bool, context: NSManagedObjectContext) { - - let fetchUserRequest: NSFetchRequest = NSFetchRequest.init(entityName: "UserEntity") - fetchUserRequest.predicate = NSPredicate(format: "num == %lld", Int64(num)) - do { - let fetchedUser = try context.fetch(fetchUserRequest) as! [UserEntity] - fetchedUser[0].mute = mute - do { - try context.save() - } catch { - context.rollback() - print("💥 Save User Mute Error") - } - } catch { - print("💥 Fetch User Error") - } -} diff --git a/Meshtastic/Views/Messages/Contacts.swift b/Meshtastic/Views/Messages/Contacts.swift index a20b1841..1be82171 100644 --- a/Meshtastic/Views/Messages/Contacts.swift +++ b/Meshtastic/Views/Messages/Contacts.swift @@ -84,6 +84,17 @@ struct Contacts: View { } .frame(maxWidth: .infinity, maxHeight: 80, alignment: .leading) .contextMenu { + Button { + channel.mute = !channel.mute + do { + try context.save() + } catch { + context.rollback() + print("💥 Save Channel Mute Error") + } + } label: { + Label(channel.mute ? "Show Alerts" : "Hide Alerts", systemImage: channel.mute ? "bell" : "bell.slash") + } if channel.allPrivateMessages.count > 0 { Button(role: .destructive) { isPresentingDeleteChannelMessagesConfirm = true @@ -159,7 +170,13 @@ struct Contacts: View { .frame(maxWidth: .infinity, maxHeight: 80, alignment: .leading) .contextMenu { Button { - setUserMute(num: user.num, mute: !user.mute, context: context) + user.mute = !user.mute + do { + try context.save() + } catch { + context.rollback() + print("💥 Save User Mute Error") + } } label: { Label(user.mute ? "Show Alerts" : "Hide Alerts", systemImage: user.mute ? "bell" : "bell.slash") }