From 7d672f2d6950ae344d61186e283a885abcd5a8ee Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 28 Aug 2025 08:58:12 +0100 Subject: [PATCH] =?UTF-8?q?Geohash=20notifications:=20ensure=20triggering?= =?UTF-8?q?=20message=20appears\n\n-=20On=20zero=E2=86=92alive=20sampling,?= =?UTF-8?q?=20pre-populate=20geoTimelines[gh]=20with=20the=20triggering=20?= =?UTF-8?q?message\n-=20Dedup=20on=20per-geohash=20timeline=20and=20UI=20m?= =?UTF-8?q?essages=20by=20message=20ID=20to=20avoid=20duplicates=20after?= =?UTF-8?q?=20subscribe\n-=20Keeps=20participant=20update,=20block/self=20?= =?UTF-8?q?checks,=20and=20cooldown=20intact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bitchat/ViewModels/ChatViewModel.swift | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 9578468a..56a5672b 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -1834,6 +1834,30 @@ class ChatViewModel: ObservableObject, BitchatDelegate { }() Task { @MainActor in self.lastGeoNotificationAt[gh] = now + // Pre-populate the target geohash timeline so the triggering message appears when user opens it + var arr = self.geoTimelines[gh] ?? [] + let senderSuffix = String(event.pubkey.suffix(4)) + let nick = self.geoNicknames[event.pubkey.lowercased()] + let senderName = (nick?.isEmpty == false ? nick! : "anon") + "#" + senderSuffix + let ts = Date(timeIntervalSince1970: TimeInterval(event.created_at)) + let mentions = self.parseMentions(from: content) + let msg = BitchatMessage( + id: event.id, + sender: senderName, + content: content, + timestamp: ts, + isRelay: false, + originalSender: nil, + isPrivate: false, + recipientNickname: nil, + senderPeerID: "nostr:\(event.pubkey.prefix(TransportConfig.nostrShortKeyDisplayLength))", + mentions: mentions.isEmpty ? nil : mentions + ) + if !arr.contains(where: { $0.id == msg.id }) { + arr.append(msg) + if arr.count > self.geoTimelineCap { arr = Array(arr.suffix(self.geoTimelineCap)) } + self.geoTimelines[gh] = arr + } NotificationService.shared.sendGeohashActivityNotification(geohash: gh, bodyPreview: preview) } } @@ -5708,9 +5732,11 @@ class ChatViewModel: ObservableObject, BitchatDelegate { // Removed background nudge notification for generic "new chats!" - // Append via batching buffer (skip empty content) + // Append via batching buffer (skip empty content) with simple dedup by ID if !finalMessage.content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { - enqueuePublic(finalMessage) + if !messages.contains(where: { $0.id == finalMessage.id }) { + enqueuePublic(finalMessage) + } } }