diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 01cda76e..d07bb2ba 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1026,10 +1026,7 @@ func adminAppPacket (packet: MeshPacket, context: NSManagedObjectContext) { else if adminMessage.payloadVariant == AdminMessage.OneOf_PayloadVariant.getChannelResponse(adminMessage.getChannelResponse) { - if let channel = try? Channel(serializedData: packet.decoded.payload) { - print("got a channel over the admin channel") - //channelPacket(channel: channel, fromNum: Int64(packet.from), context: context) - } + channelPacket(channel: adminMessage.getChannelResponse, fromNum: Int64(packet.from), context: context) } } diff --git a/Meshtastic/Views/Messages/Contacts.swift b/Meshtastic/Views/Messages/Contacts.swift index d53c365f..241a694e 100644 --- a/Meshtastic/Views/Messages/Contacts.swift +++ b/Meshtastic/Views/Messages/Contacts.swift @@ -20,7 +20,8 @@ struct Contacts: View { private var users: FetchedResults @State var node: NodeInfoEntity? = nil - @State private var selection: UserEntity? = nil // Nothing selected by default. + @State private var userSelection: UserEntity? = nil // Nothing selected by default. + @State private var channelSelection: ChannelEntity? = nil // Nothing selected by default. @State private var isPresentingDeleteChannelMessagesConfirm: Bool = false @State private var isPresentingDeleteUserMessagesConfirm: Bool = false @State private var isPresentingTraceRouteSentAlert = false @@ -113,6 +114,7 @@ struct Contacts: View { if channel.allPrivateMessages.count > 0 { Button(role: .destructive) { isPresentingDeleteChannelMessagesConfirm = true + channelSelection = channel } label: { Label("Delete Messages", systemImage: "trash") } @@ -121,22 +123,12 @@ struct Contacts: View { .confirmationDialog( "This conversation will be deleted.", isPresented: $isPresentingDeleteChannelMessagesConfirm, - titleVisibility: .visible ) { - Button(role: .destructive) { - do { - for message in channel.allPrivateMessages { - context.delete(message) - } - try context.save() - context.refresh(node!.myInfo!, mergeChanges: true) - } catch let error as NSError { - print("Error: \(error.localizedDescription)") - } - //deleteChannelMessages(channel: channel, context: context) - + deleteChannelMessages(channel: channelSelection!, context: context) + context.refresh(node!.myInfo!, mergeChanges: true) + channelSelection = nil } label: { Text("delete") } @@ -217,6 +209,7 @@ struct Contacts: View { if user.messageList.count > 0 { Button(role: .destructive) { isPresentingDeleteUserMessagesConfirm = true + userSelection = user } label: { Label("Delete Messages", systemImage: "trash") } @@ -238,7 +231,7 @@ struct Contacts: View { titleVisibility: .visible ) { Button(role: .destructive) { - deleteUserMessages(user: user, context: context) + deleteUserMessages(user: userSelection!, context: context) context.refresh(node!.user!, mergeChanges: true) } label: { Text("delete") @@ -283,7 +276,7 @@ struct Contacts: View { } } detail: { - if let user = selection { + if let user = userSelection { UserMessageList(user:user) } else { diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index b4109f99..52a4d8ec 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -258,8 +258,8 @@ struct Channels: View { channelName = "" hasChanges = false // Would rather send a getChannel but I can't seem serialize it properly yet - //bleManager.getChannel(channel: channel, fromUser: node!.user!, toUser: node!.user!) - bleManager.sendWantConfig() + bleManager.getChannel(channel: channel, fromUser: node!.user!, toUser: node!.user!) + //bleManager.sendWantConfig() } } label: { Label("save", systemImage: "square.and.arrow.down")