From fe098cdae9923c7be32efa4cf17502ac137afd97 Mon Sep 17 00:00:00 2001 From: jack Date: Sun, 24 Aug 2025 17:16:31 +0200 Subject: [PATCH] UI: fix DM autoscroll IDs by using dm:| for private chat item IDs and preserve anchors, ensuring scrollTo targets exist when opening/switching/new messages --- bitchat/Views/ContentView.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index ec1ddd1f..ffaf79c1 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -291,13 +291,17 @@ struct ContentView: View { // Build stable UI IDs with a context key to avoid ID collisions when switching channels #if os(iOS) let contextKey: String = { + if let peer = privatePeer { return "dm:\\(peer)" } switch locationManager.selectedChannel { case .mesh: return "mesh" - case .location(let ch): return "geo:\(ch.geohash)" + case .location(let ch): return "geo:\\(ch.geohash)" } }() #else - let contextKey: String = "mesh" + let contextKey: String = { + if let peer = privatePeer { return "dm:\\(peer)" } + return "mesh" + }() #endif let items = windowedMessages.map { (uiID: "\(contextKey)|\($0.id)", message: $0) } @@ -396,13 +400,17 @@ struct ContentView: View { let step = 200 #if os(iOS) let contextKey: String = { + if let peer = privatePeer { return "dm:\\(peer)" } switch locationManager.selectedChannel { case .mesh: return "mesh" - case .location(let ch): return "geo:\(ch.geohash)" + case .location(let ch): return "geo:\\(ch.geohash)" } }() #else - let contextKey: String = "mesh" + let contextKey: String = { + if let peer = privatePeer { return "dm:\\(peer)" } + return "mesh" + }() #endif let preserveID = "\(contextKey)|\(message.id)" if let peer = privatePeer {