mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Partially working channel mute
This commit is contained in:
parent
1a20990b9f
commit
61a4c51f45
2 changed files with 18 additions and 39 deletions
|
|
@ -105,41 +105,3 @@ public func clearCoreDataDatabase(context: NSManagedObjectContext) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func setChannelMute(channel: Int32, mute: Bool, context: NSManagedObjectContext) {
|
||||
|
||||
let fetchChannelRequest: NSFetchRequest<NSFetchRequestResult> = 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<NSFetchRequestResult> = 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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue