1
0
Fork 0
forked from mirrors/ntfy

Switch to since=ID

This commit is contained in:
Philipp Heckel 2022-02-27 19:29:17 -05:00
parent cda9dfa9d0
commit 0909354a6c
5 changed files with 9 additions and 10 deletions

View file

@ -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 = [];

View file

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

View file

@ -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}`);

View file

@ -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;
}

View file

@ -22,7 +22,6 @@ import notificationManager from "../app/NotificationManager";
// TODO user management
// TODO embed into ntfy server
// TODO remember selected subscription
// TODO since=<ID>
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 => {