diff --git a/web/src/app/Api.js b/web/src/app/Api.js index 520f110e..ff0af948 100644 --- a/web/src/app/Api.js +++ b/web/src/app/Api.js @@ -11,7 +11,7 @@ import { class Api { async poll(baseUrl, topic, since, user) { const shortUrl = topicShortUrl(baseUrl, topic); - const url = (since > 1) // FIXME Ahh, this is >1, because we do +1 when we call this ..... + const url = (since) ? topicUrlJsonPollWithSince(baseUrl, topic, since) : topicUrlJsonPoll(baseUrl, topic); const messages = []; diff --git a/web/src/app/Connection.js b/web/src/app/Connection.js index 9aedf211..a4d612e6 100644 --- a/web/src/app/Connection.js +++ b/web/src/app/Connection.js @@ -44,7 +44,7 @@ class Connection { console.log(`[Connection, ${this.shortUrl}] Unexpected message. Ignoring.`); return; } - this.since = data.time + 1; // Sigh. This works because on reconnect, we wait 5+ seconds anyway. + this.since = data.id; this.onNotification(this.subscriptionId, data); } catch (e) { console.log(`[Connection, ${this.shortUrl}] Error handling message: ${e}`); @@ -82,8 +82,8 @@ class Connection { wsUrl() { const params = []; - if (this.since > 0) { - params.push(`since=${this.since.toString()}`); + if (this.since) { + params.push(`since=${this.since}`); } if (this.user !== null) { const auth = encodeBase64Url(basicAuth(this.user.username, this.user.password)); diff --git a/web/src/app/ConnectionManager.js b/web/src/app/ConnectionManager.js index 67b41362..160d36d1 100644 --- a/web/src/app/ConnectionManager.js +++ b/web/src/app/ConnectionManager.js @@ -17,7 +17,7 @@ class ConnectionManager { const baseUrl = subscription.baseUrl; const topic = subscription.topic; const user = users.get(baseUrl); - const since = 0; + const since = subscription.last; const connection = new Connection(id, baseUrl, topic, user, since, onNotification); this.connections.set(id, connection); console.log(`[ConnectionManager] Starting new connection ${id}`); diff --git a/web/src/app/Subscription.js b/web/src/app/Subscription.js index ce436a0f..ece61df1 100644 --- a/web/src/app/Subscription.js +++ b/web/src/app/Subscription.js @@ -6,15 +6,15 @@ class Subscription { this.baseUrl = baseUrl; this.topic = topic; this.notifications = new Map(); // notification ID -> notification object - this.last = 0; + this.last = null; // Last message ID } addNotification(notification) { - if (this.notifications.has(notification.id) || notification.time < this.last) { + if (this.notifications.has(notification.id)) { return false; } this.notifications.set(notification.id, notification); - this.last = notification.time; + this.last = notification.id; return true; } diff --git a/web/src/components/App.js b/web/src/components/App.js index ca4864e1..ee42513c 100644 --- a/web/src/components/App.js +++ b/web/src/components/App.js @@ -22,7 +22,6 @@ import notificationManager from "../app/NotificationManager"; // TODO user management // TODO embed into ntfy server // TODO remember selected subscription -// TODO since= const App = () => { console.log(`[App] Rendering main view`); @@ -70,7 +69,7 @@ const App = () => { }) }; const poll = (subscription, user) => { - const since = subscription.last + 1; // FIXME, sigh ... + const since = subscription.last; api.poll(subscription.baseUrl, subscription.topic, since, user) .then(notifications => { setSubscriptions(prev => {