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));