2023-08-29 22:12:51 -07:00
|
|
|
//
|
|
|
|
|
// UserList.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Copyright(c) Garth Vander Houwen 8/29/23.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import CoreData
|
2024-06-03 02:17:55 -07:00
|
|
|
import OSLog
|
2023-09-17 19:42:03 -07:00
|
|
|
import TipKit
|
2023-08-29 22:12:51 -07:00
|
|
|
|
|
|
|
|
struct UserList: View {
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2023-09-04 22:51:30 -07:00
|
|
|
@Environment(\.managedObjectContext) var context
|
Transports Interface to Support TCP for all Platforms and Serial on Mac (#1341)
* Initial implementation of transports
* Initial LogRadio implementation
* Fixes for Settings view (caused by debug commenting)
* Refinement of the object and actor model
* Connect view text and tab updates
* Fix mac catalyst and tests
* Warning and logging clean-up
* In progress commit
* Serial Transport and Reconnect draft work
* Serial transport and reconnection draft work
* Quick fix for BLE - still more work to do
* interim commit
* More in progress changes
* Minor improvements
* Pretty good initial implementation
* Bump version beyond the app store
* Fix for disconnection swipeAction
* Tweaks to TCPConnection implementation
* Retry for NONCE_ONLY_DB
* Revert json string change
* Simplified some of the API + "Anti-discovery"
* Tweaks for devices leaving the discovery process
* Bump version
* iOS26 Tweaks
* Tweaks and bug fixes
* Add link with slash sf symbol
* update symbol image on connect view
* BLE disconnect handling
* Log privacy attributes
* Onboarding and minor fixes.
* change database to nodes, add emoji to tcp logs
* Error handling improvements
* More logging emojis
* Suppressed unnecessary errors on disconnect
* Heartbeat emoji
* Add bluetooth symbol
* add privacy attributes to [TCP] logs, add custom bluetooth logo
* Improve routing logs
* Emoji for connect logs
* Heartbeat emoji
* Add CBCentralManagerScanOptionAllowDuplicatesKey options to central for bluetooth
* fix nav errors by switching from observableobject to state
* Update connection indicator icon
* fix for BLE disconnects
* Connection process fixes
* More fixes/tweaks to connection process
* Strict concurrency
* Fix some warnings, remove wifi warning
* delete stale keys
* interim commit
* Update privacy for log, fix wrong space
* fix a couple of linting items
* Switch to targeted
* interim commit
* BLE Signal strenth on connect view
* Remove BLE RSSI from long press menu
* Modem lights
* minor spacing tweak
* Additional BLE logging and a scanning fix.
* Discovery and BLE RSSI improvements
* Background suspension
* Update isConnected to enable UI during db load
* update protobufs
* Replace config if statements with switches, Fix unknown module config logging, make dark mode modem circle stroke color white so they are visible
* Additional logging cleanup
* hast
* Set unmessagable to true if the longname has the unmessagable emoji
* Connect error handling improvements
* Admin popup list icon and activity lights updates
* Revert use of .toolbar back to .navigationBarItems
* More public logging
* Better BLE error handling
* Node DB progress meter
* minor tweak to activity light interaction timing
* Fix comment linting, remove stale keys
* Remove stale keys
* Easy linting fixes
* Two more simple linting fixes
* clean up meshtasticapp
* More public logging
* Replay config
* Logging
* Fix for unselected node on Settings
* Tweak to progress meter based on device idiom
* Update protos
* Session replay redaction of messages
* Serial fix for old devices, and a let statement
* Mask text too
* Fix typo
* BLE poweredOff is now an auto-reconnectable error
* Update logging
* Fix for peerRemovedPairingInformation
* Logging for BLE peripheral:didUpdateValueFor errors.
* Fix for inconsistent swipe disconnect behavior
* periperal:didUpdateValueFor error handling
* Fix for BLEConnection continuation guarding
* BLEConnection actor deadlock on disconnect
* Heartbeat nonce
* Fix for swipe disconnect and task cancellation
* Fix for swipe actions not honoring .disabled()
* Tell BLETransport when BLEConnection is cancelled
* Update navigation logging
* Logging updates
* Bump version to 2.7.0
* Organize into folders and heartbeat stuff
* Minor improvements to manual TCP connection
* Auto-connect toggle
* Possible BLE bug, still waiting to see in logs
* Concurrency tweaks
* Concurrency improvements
* requestDeviceMetadata fix. fixes remote admin
* Minor typo fixes
* "All" button for log filters: category and level
* More robust continuation handling for BLE
* @FetchRequest based ChannelMessageList
* Update info.plist and device hardware file
* Move auto connect toggle to app settings and debug mode, tint properly with the accent color
* Add label to auto connect toggle
* Update log for node info received from ourselves over the mesh
* Remove unused scrollViewProxy
* Update Meshtastic/Views/Onboarding/DeviceOnboarding.swift
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update target for connect view
* Properly Set datadog environment
* Comment out ble manager
* Adjust cyclomatic complexity thresholds in .swiftlint.yml
* Linting fixes, delete ble manager
* Make session replay debug only
---------
Co-authored-by: jake-b <jake-b@users.noreply.github.com>
Co-authored-by: jake <jake@jakes-Mac-mini.local>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-27 08:09:02 -07:00
|
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
2024-08-15 16:31:58 -07:00
|
|
|
@State private var editingFilters = false
|
|
|
|
|
@State private var showingHelp = false
|
2024-08-12 16:46:25 -07:00
|
|
|
@State private var showingTrustConfirm: Bool = false
|
2025-09-07 12:57:38 -07:00
|
|
|
@StateObject private var filters: NodeFilterParameters = NodeFilterParameters()
|
2024-07-14 01:34:54 -05:00
|
|
|
@Binding var node: NodeInfoEntity?
|
|
|
|
|
@Binding var userSelection: UserEntity?
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2023-08-29 22:12:51 -07:00
|
|
|
var body: some View {
|
2023-09-16 08:48:36 -07:00
|
|
|
VStack {
|
2025-10-05 17:51:18 -07:00
|
|
|
FilteredUserList(withFilters: filters, node: $node, userSelection: $userSelection)
|
2024-08-15 16:31:58 -07:00
|
|
|
.sheet(isPresented: $editingFilters) {
|
2025-09-07 12:57:38 -07:00
|
|
|
NodeListFilter(filterTitle: "Contact Filters", filters: filters)
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
2024-08-15 16:31:58 -07:00
|
|
|
.sheet(isPresented: $showingHelp) {
|
|
|
|
|
DirectMessagesHelp()
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
2024-08-15 16:31:58 -07:00
|
|
|
.safeAreaInset(edge: .bottom, alignment: .leading) {
|
2024-04-02 11:16:32 -07:00
|
|
|
HStack {
|
|
|
|
|
Button(action: {
|
|
|
|
|
withAnimation {
|
2024-08-15 16:31:58 -07:00
|
|
|
showingHelp = !showingHelp
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
|
|
|
|
}) {
|
2024-08-15 16:31:58 -07:00
|
|
|
Image(systemName: !editingFilters ? "questionmark.circle" : "questionmark.circle.fill")
|
|
|
|
|
.padding(.vertical, 5)
|
|
|
|
|
}
|
|
|
|
|
.tint(Color(UIColor.secondarySystemBackground))
|
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
|
Spacer()
|
|
|
|
|
Button(action: {
|
|
|
|
|
withAnimation {
|
|
|
|
|
editingFilters = !editingFilters
|
|
|
|
|
}
|
|
|
|
|
}) {
|
|
|
|
|
Image(systemName: !editingFilters ? "line.3.horizontal.decrease.circle" : "line.3.horizontal.decrease.circle.fill")
|
2024-04-02 11:16:32 -07:00
|
|
|
.padding(.vertical, 5)
|
|
|
|
|
}
|
|
|
|
|
.tint(Color(UIColor.secondarySystemBackground))
|
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
|
.buttonStyle(.borderedProminent)
|
|
|
|
|
}
|
|
|
|
|
.controlSize(.regular)
|
|
|
|
|
.padding(5)
|
|
|
|
|
}
|
|
|
|
|
.padding(.bottom, 5)
|
2025-09-07 12:57:38 -07:00
|
|
|
.searchable(text: $filters.searchText, placement: .navigationBarDrawer(displayMode: .always), prompt: "Find a contact")
|
2025-10-05 17:51:18 -07:00
|
|
|
.autocorrectionDisabled(true)
|
2025-09-07 12:57:38 -07:00
|
|
|
.scrollDismissesKeyboard(.immediately)
|
2023-08-29 22:12:51 -07:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
}
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2025-10-05 17:51:18 -07:00
|
|
|
fileprivate struct FilteredUserList: View {
|
|
|
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
|
|
|
@Environment(\.managedObjectContext) var context
|
|
|
|
|
|
|
|
|
|
@FetchRequest private var users: FetchedResults<UserEntity>
|
|
|
|
|
@Binding var userSelection: UserEntity?
|
|
|
|
|
@Binding var node: NodeInfoEntity?
|
|
|
|
|
|
|
|
|
|
@State private var isPresentingDeleteUserMessagesConfirm: Bool = false
|
|
|
|
|
@State private var userToDeleteMessages: UserEntity?
|
|
|
|
|
|
|
|
|
|
init(withFilters: NodeFilterParameters, node: Binding<NodeInfoEntity?>, userSelection: Binding<UserEntity?>) {
|
|
|
|
|
let request: NSFetchRequest<UserEntity> = UserEntity.fetchRequest()
|
|
|
|
|
request.sortDescriptors = [
|
|
|
|
|
NSSortDescriptor(key: "lastMessage", ascending: false),
|
|
|
|
|
NSSortDescriptor(key: "userNode.favorite", ascending: false),
|
|
|
|
|
NSSortDescriptor(key: "pkiEncrypted", ascending: false),
|
|
|
|
|
NSSortDescriptor(key: "userNode.lastHeard", ascending: false),
|
|
|
|
|
NSSortDescriptor(key: "longName", ascending: true)
|
|
|
|
|
]
|
|
|
|
|
request.predicate = withFilters.buildPredicate()
|
|
|
|
|
self._users = FetchRequest(fetchRequest: request)
|
|
|
|
|
self._node = node
|
|
|
|
|
self._userSelection = userSelection
|
|
|
|
|
}
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2025-10-05 17:51:18 -07:00
|
|
|
var body: some View {
|
|
|
|
|
let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMdd", options: 0, locale: Locale.current)
|
|
|
|
|
let dateFormatString = (localeDateFormat ?? "MM/dd/YY")
|
|
|
|
|
|
|
|
|
|
List(users, selection: $userSelection) { user in
|
2025-10-17 18:16:00 -07:00
|
|
|
let mostRecent = user.mostRecentMessage
|
|
|
|
|
let hasMessages = mostRecent != nil
|
|
|
|
|
let hasUnreadMessages = user.unreadMessages > 0
|
2025-10-05 17:51:18 -07:00
|
|
|
let lastMessageTime = Date(timeIntervalSince1970: TimeInterval(Int64((mostRecent?.messageTimestamp ?? 0 ))))
|
|
|
|
|
let lastMessageDay = Calendar.current.dateComponents([.day], from: lastMessageTime).day ?? 0
|
|
|
|
|
let currentDay = Calendar.current.dateComponents([.day], from: Date()).day ?? 0
|
|
|
|
|
if user.num != accessoryManager.activeDeviceNum ?? 0 {
|
|
|
|
|
NavigationLink(value: user) {
|
|
|
|
|
ZStack {
|
|
|
|
|
Image(systemName: "circle.fill")
|
2025-10-17 18:16:00 -07:00
|
|
|
.opacity(hasUnreadMessages ? 1 : 0)
|
2025-10-05 17:51:18 -07:00
|
|
|
.font(.system(size: 10))
|
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
|
.brightness(0.2)
|
|
|
|
|
}
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2025-10-05 17:51:18 -07:00
|
|
|
CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num))))
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2025-10-05 17:51:18 -07:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
HStack {
|
|
|
|
|
if user.pkiEncrypted {
|
|
|
|
|
if !user.keyMatch {
|
|
|
|
|
/// Public Key on the User and the Public Key on the Last Message don't match
|
|
|
|
|
Image(systemName: "key.slash")
|
|
|
|
|
.foregroundColor(.red)
|
|
|
|
|
} else {
|
|
|
|
|
Image(systemName: "lock.fill")
|
|
|
|
|
.foregroundColor(.green)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Image(systemName: "lock.open.fill")
|
|
|
|
|
.foregroundColor(.yellow)
|
|
|
|
|
}
|
|
|
|
|
Text(user.longName ?? "Unknown".localized)
|
|
|
|
|
.font(.headline)
|
|
|
|
|
.allowsTightening(true)
|
|
|
|
|
Spacer()
|
|
|
|
|
if user.userNode?.favorite ?? false {
|
|
|
|
|
Image(systemName: "star.fill")
|
|
|
|
|
.foregroundColor(.yellow)
|
|
|
|
|
}
|
2025-10-17 18:16:00 -07:00
|
|
|
if hasMessages {
|
2025-10-05 17:51:18 -07:00
|
|
|
if lastMessageDay == currentDay {
|
|
|
|
|
Text(lastMessageTime, style: .time )
|
|
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
} else if lastMessageDay == (currentDay - 1) {
|
|
|
|
|
Text("Yesterday")
|
|
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
} else if lastMessageDay < (currentDay - 1) && lastMessageDay > (currentDay - 5) {
|
|
|
|
|
Text(lastMessageTime.formattedDate(format: dateFormatString))
|
|
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
} else if lastMessageDay < (currentDay - 1800) {
|
|
|
|
|
Text(lastMessageTime.formattedDate(format: dateFormatString))
|
|
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-17 18:16:00 -07:00
|
|
|
|
|
|
|
|
if hasMessages {
|
2025-10-05 17:51:18 -07:00
|
|
|
HStack(alignment: .top) {
|
|
|
|
|
Text("\(mostRecent != nil ? mostRecent!.messagePayload! : " ")")
|
|
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.frame(height: 62)
|
|
|
|
|
.alignmentGuide(.listRowSeparatorLeading) {
|
|
|
|
|
$0[.leading]
|
|
|
|
|
}
|
|
|
|
|
.contextMenu {
|
|
|
|
|
Button {
|
|
|
|
|
if node != nil && !(user.userNode?.favorite ?? false) {
|
|
|
|
|
user.userNode?.favorite = !(user.userNode?.favorite ?? false)
|
|
|
|
|
Task {
|
|
|
|
|
try await accessoryManager.setFavoriteNode(node: user.userNode!, connectedNodeNum: Int64(node!.num))
|
|
|
|
|
Logger.data.info("Favorited a node")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
user.userNode?.favorite = !(user.userNode?.favorite ?? false)
|
|
|
|
|
Task {
|
|
|
|
|
try await accessoryManager.removeFavoriteNode(node: user.userNode!, connectedNodeNum: Int64(node!.num))
|
|
|
|
|
Logger.data.info("Unfavorited a node")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
context.refresh(user, mergeChanges: true)
|
|
|
|
|
do {
|
|
|
|
|
try context.save()
|
|
|
|
|
} catch {
|
|
|
|
|
context.rollback()
|
|
|
|
|
Logger.data.error("Save Node Favorite Error")
|
|
|
|
|
}
|
|
|
|
|
} label: {
|
|
|
|
|
Label((user.userNode?.favorite ?? false) ? "Un-Favorite" : "Favorite", systemImage: (user.userNode?.favorite ?? false) ? "star.slash.fill" : "star.fill")
|
|
|
|
|
}
|
|
|
|
|
Button {
|
|
|
|
|
user.mute = !user.mute
|
|
|
|
|
do {
|
|
|
|
|
try context.save()
|
|
|
|
|
} catch {
|
|
|
|
|
context.rollback()
|
|
|
|
|
Logger.data.error("Save User Mute Error")
|
|
|
|
|
}
|
|
|
|
|
} label: {
|
|
|
|
|
Label(user.mute ? "Show Alerts" : "Hide Alerts", systemImage: user.mute ? "bell" : "bell.slash")
|
|
|
|
|
}
|
2025-10-17 18:16:00 -07:00
|
|
|
if hasMessages {
|
2025-10-05 17:51:18 -07:00
|
|
|
Button(role: .destructive) {
|
|
|
|
|
isPresentingDeleteUserMessagesConfirm = true
|
|
|
|
|
userToDeleteMessages = user
|
|
|
|
|
} label: {
|
|
|
|
|
Label("Delete Messages", systemImage: "trash")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.confirmationDialog(
|
|
|
|
|
"This conversation will be deleted.",
|
|
|
|
|
isPresented: $isPresentingDeleteUserMessagesConfirm,
|
|
|
|
|
titleVisibility: .visible
|
|
|
|
|
) {
|
|
|
|
|
Button(role: .destructive) {
|
|
|
|
|
deleteUserMessages(user: userToDeleteMessages!, context: context)
|
|
|
|
|
context.refresh(node!.user!, mergeChanges: true)
|
|
|
|
|
} label: {
|
|
|
|
|
Text("Delete")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.listStyle(.plain)
|
|
|
|
|
.navigationTitle(String.localizedStringWithFormat("Contacts (%@)".localized, String(users.count)))
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-07 12:57:38 -07:00
|
|
|
fileprivate extension NodeFilterParameters {
|
|
|
|
|
func buildPredicate() -> NSPredicate? {
|
2024-04-02 11:16:32 -07:00
|
|
|
var predicates: [NSPredicate] = []
|
2025-06-10 13:35:48 -07:00
|
|
|
// Search text predicates
|
|
|
|
|
if !searchText.isEmpty {
|
|
|
|
|
let searchPredicates = ["userId", "numString", "hwModel", "hwDisplayName", "longName", "shortName"].map { property in
|
|
|
|
|
return NSPredicate(format: "%K CONTAINS[c] %@", property, searchText)
|
|
|
|
|
}
|
|
|
|
|
let textSearchPredicate = NSCompoundPredicate(type: .or, subpredicates: searchPredicates)
|
|
|
|
|
predicates.append(textSearchPredicate)
|
|
|
|
|
}
|
|
|
|
|
// Mqtt and lora
|
2024-04-02 11:16:32 -07:00
|
|
|
if !(viaLora && viaMqtt) {
|
|
|
|
|
if viaLora {
|
|
|
|
|
let loraPredicate = NSPredicate(format: "userNode.viaMqtt == NO")
|
|
|
|
|
predicates.append(loraPredicate)
|
|
|
|
|
} else {
|
2025-06-10 22:57:00 -07:00
|
|
|
let mqttPredicate = NSPredicate(format: "userNode.viaMqtt == YES")
|
2024-04-02 11:16:32 -07:00
|
|
|
predicates.append(mqttPredicate)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Roles
|
2024-06-29 16:19:56 -07:00
|
|
|
if roleFilter && deviceRoles.count > 0 {
|
|
|
|
|
var rolesArray: [NSPredicate] = []
|
|
|
|
|
for dr in deviceRoles {
|
2024-06-29 19:25:14 -07:00
|
|
|
let deviceRolePredicate = NSPredicate(format: "role == %i", Int32(dr))
|
2024-06-29 16:19:56 -07:00
|
|
|
rolesArray.append(deviceRolePredicate)
|
|
|
|
|
}
|
|
|
|
|
let compoundPredicate = NSCompoundPredicate(type: .or, subpredicates: rolesArray)
|
|
|
|
|
predicates.append(compoundPredicate)
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Hops Away
|
2025-06-10 22:47:18 -07:00
|
|
|
if hopsAway == 0 {
|
2024-07-02 08:01:13 -07:00
|
|
|
let hopsAwayPredicate = NSPredicate(format: "userNode.hopsAway == %i", Int32(hopsAway))
|
|
|
|
|
predicates.append(hopsAwayPredicate)
|
|
|
|
|
} else if hopsAway > -1.0 {
|
|
|
|
|
let hopsAwayPredicate = NSPredicate(format: "userNode.hopsAway > 0 AND userNode.hopsAway <= %i", Int32(hopsAway))
|
|
|
|
|
predicates.append(hopsAwayPredicate)
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Online
|
2024-04-02 11:16:32 -07:00
|
|
|
if isOnline {
|
2024-08-25 09:50:01 -07:00
|
|
|
let isOnlinePredicate = NSPredicate(format: "userNode.lastHeard >= %@", Calendar.current.date(byAdding: .minute, value: -120, to: Date())! as NSDate)
|
2024-04-02 11:16:32 -07:00
|
|
|
predicates.append(isOnlinePredicate)
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Encrypted
|
2024-08-12 19:51:34 -07:00
|
|
|
if isPkiEncrypted {
|
|
|
|
|
let isPkiEncryptedPredicate = NSPredicate(format: "pkiEncrypted == YES")
|
|
|
|
|
predicates.append(isPkiEncryptedPredicate)
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Favorites
|
2024-04-02 11:16:32 -07:00
|
|
|
if isFavorite {
|
|
|
|
|
let isFavoritePredicate = NSPredicate(format: "userNode.favorite == YES")
|
|
|
|
|
predicates.append(isFavoritePredicate)
|
|
|
|
|
}
|
2025-06-10 13:35:48 -07:00
|
|
|
// Distance
|
2024-04-02 11:16:32 -07:00
|
|
|
if distanceFilter {
|
2025-10-05 17:51:18 -07:00
|
|
|
if let pointOfInterest = LocationsHandler.currentLocation {
|
|
|
|
|
if pointOfInterest.latitude != LocationsHandler.DefaultLocation.latitude && pointOfInterest.longitude != LocationsHandler.DefaultLocation.longitude {
|
|
|
|
|
let d: Double = maxDistance * 1.1
|
|
|
|
|
let r: Double = 6371009
|
|
|
|
|
let meanLatitidue = pointOfInterest.latitude * .pi / 180
|
|
|
|
|
let deltaLatitude = d / r * 180 / .pi
|
|
|
|
|
let deltaLongitude = d / (r * cos(meanLatitidue)) * 180 / .pi
|
|
|
|
|
let minLatitude: Double = pointOfInterest.latitude - deltaLatitude
|
|
|
|
|
let maxLatitude: Double = pointOfInterest.latitude + deltaLatitude
|
|
|
|
|
let minLongitude: Double = pointOfInterest.longitude - deltaLongitude
|
|
|
|
|
let maxLongitude: Double = pointOfInterest.longitude + deltaLongitude
|
|
|
|
|
let distancePredicate = NSPredicate(format: "(SUBQUERY(userNode.positions, $position, $position.latest == TRUE && (%lf <= ($position.longitudeI / 1e7)) AND (($position.longitudeI / 1e7) <= %lf) AND (%lf <= ($position.latitudeI / 1e7)) AND (($position.latitudeI / 1e7) <= %lf))).@count > 0", minLongitude, maxLongitude, minLatitude, maxLatitude)
|
|
|
|
|
predicates.append(distancePredicate)
|
|
|
|
|
}
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-10 23:12:57 -07:00
|
|
|
// Always apply unmessagable and connected node filters
|
2025-07-05 10:49:10 -07:00
|
|
|
// Show unmessagable nodes only if they have messages, otherwise hide them
|
2025-07-07 21:57:04 -07:00
|
|
|
let unmessagablePredicate = NSPredicate(format: "unmessagable == NO")
|
|
|
|
|
let hasMessagesPredicate = NSPredicate(format: "receivedMessages.@count > 0 OR sentMessages.@count > 0")
|
|
|
|
|
let isUnmessagablePredicate = NSCompoundPredicate(type: .or, subpredicates: [unmessagablePredicate, hasMessagesPredicate])
|
2025-06-10 22:47:18 -07:00
|
|
|
predicates.append(isUnmessagablePredicate)
|
2025-06-11 09:55:29 -07:00
|
|
|
let isIgnoredPredicate = NSPredicate(format: "userNode.ignored == NO")
|
|
|
|
|
predicates.append(isIgnoredPredicate)
|
2025-06-11 06:49:09 -07:00
|
|
|
let isConnectedNodePredicate = NSPredicate(format: "NOT (numString CONTAINS %@)", String(UserDefaults.preferredPeripheralNum))
|
2025-06-10 23:12:57 -07:00
|
|
|
predicates.append(isConnectedNodePredicate)
|
2025-10-17 18:16:00 -07:00
|
|
|
|
2025-06-10 13:35:48 -07:00
|
|
|
// Combine all predicates
|
|
|
|
|
let finalPredicate = predicates.isEmpty ? NSPredicate(value: true) : NSCompoundPredicate(type: .and, subpredicates: predicates)
|
2025-09-07 12:57:38 -07:00
|
|
|
return finalPredicate
|
2024-04-02 11:16:32 -07:00
|
|
|
}
|
2023-08-29 22:12:51 -07:00
|
|
|
}
|