From 045bd7124af1a58bfa68efadf7fd16abce2951d7 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 22 Jul 2024 17:40:06 -0700 Subject: [PATCH] Filter user predicate --- Meshtastic/Views/Messages/UserList.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index 5c7214fe7..226d2ae9a 100644 --- a/Meshtastic/Views/Messages/UserList.swift +++ b/Meshtastic/Views/Messages/UserList.swift @@ -33,7 +33,9 @@ struct UserList: View { sortDescriptors: [NSSortDescriptor(key: "lastMessage", ascending: false), NSSortDescriptor(key: "userNode.favorite", ascending: false), NSSortDescriptor(key: "longName", ascending: true)], - animation: .default + predicate: NSPredicate( + format: "NOT (userNode.viaMqtt == YES AND userNode.hopsAway > 0)" + ), animation: .default ) private var users: FetchedResults @@ -244,15 +246,18 @@ struct UserList: View { let textSearchPredicate = NSCompoundPredicate(type: .or, subpredicates: searchPredicates) /// Create an array of predicates to hold our AND predicates var predicates: [NSPredicate] = [] - /// Mqtt + /// Mqtt and lora if !(viaLora && viaMqtt) { if viaLora { let loraPredicate = NSPredicate(format: "userNode.viaMqtt == NO") predicates.append(loraPredicate) } else { - let mqttPredicate = NSPredicate(format: "userNode.viaMqtt == YES") + let mqttPredicate = NSPredicate(format: "userNode.viaMqtt == YES AND userNode.hopsAway == 0") predicates.append(mqttPredicate) } + } else { + let mqttPredicate = NSPredicate(format: "NOT (userNode.viaMqtt == YES AND userNode.hopsAway > 0)") + predicates.append(mqttPredicate) } /// Roles if roleFilter && deviceRoles.count > 0 {