From 0b0a49c2016d12e623579fce7397e078168d7449 Mon Sep 17 00:00:00 2001 From: HikeMap User Date: Wed, 31 Dec 2025 10:47:52 -0600 Subject: [PATCH] Fix geocache message notifications for cross-device alerts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed notification not triggering when adding message from another device - Now notifies ALL devices (including your own) when near a cache with new message - Added null checks for messages array to prevent errors - Notifications work for messages from same user on different devices This fixes the issue where adding a message from desktop wouldn't notify your phone even when nearby. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- geocaches.json | 10 ++++++++++ index.html | 13 ++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/geocaches.json b/geocaches.json index b6366f5..ee1856f 100644 --- a/geocaches.json +++ b/geocaches.json @@ -47,6 +47,16 @@ "author": "Riker", "text": "Stupid little cousin ibby dibby...", "timestamp": 1767133204544 + }, + { + "author": "Presley", + "text": "BARK! god damnit BARK!", + "timestamp": 1767199495387 + }, + { + "author": "test", + "text": "test", + "timestamp": 1767199518737 } ], "createdAt": 1767127362829, diff --git a/index.html b/index.html index 9ae959c..545144b 100644 --- a/index.html +++ b/index.html @@ -2552,19 +2552,22 @@ break; case 'geocacheUpdate': - // Another user added or updated a geocache + // Another user or device added or updated a geocache if (data.geocache) { const existingIndex = geocaches.findIndex(g => g.id === data.geocache.id); if (existingIndex >= 0) { - // Check if this is a new message from another user + // Check if this is a new message const oldCache = geocaches[existingIndex]; - const newMessagesCount = data.geocache.messages.length - oldCache.messages.length; + const oldMessageCount = oldCache.messages ? oldCache.messages.length : 0; + const newMessageCount = data.geocache.messages ? data.geocache.messages.length : 0; + const newMessagesCount = newMessageCount - oldMessageCount; // Update existing geocache geocaches[existingIndex] = data.geocache; - // Send notification if new message added by another user and we're nearby - if (newMessagesCount > 0 && userLocation) { + // Send notification if new message added and we're nearby + // This will notify even if it's from your own account on another device + if (newMessagesCount > 0 && userLocation && pushSubscription) { const distance = L.latLng(userLocation.lat, userLocation.lng) .distanceTo(L.latLng(data.geocache.lat, data.geocache.lng));