mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-27 12:12:28 +01:00
Switch to since=ID
This commit is contained in:
parent
cda9dfa9d0
commit
0909354a6c
5 changed files with 9 additions and 10 deletions
|
@ -11,7 +11,7 @@ import {
|
||||||
class Api {
|
class Api {
|
||||||
async poll(baseUrl, topic, since, user) {
|
async poll(baseUrl, topic, since, user) {
|
||||||
const shortUrl = topicShortUrl(baseUrl, topic);
|
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)
|
? topicUrlJsonPollWithSince(baseUrl, topic, since)
|
||||||
: topicUrlJsonPoll(baseUrl, topic);
|
: topicUrlJsonPoll(baseUrl, topic);
|
||||||
const messages = [];
|
const messages = [];
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Connection {
|
||||||
console.log(`[Connection, ${this.shortUrl}] Unexpected message. Ignoring.`);
|
console.log(`[Connection, ${this.shortUrl}] Unexpected message. Ignoring.`);
|
||||||
return;
|
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);
|
this.onNotification(this.subscriptionId, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`[Connection, ${this.shortUrl}] Error handling message: ${e}`);
|
console.log(`[Connection, ${this.shortUrl}] Error handling message: ${e}`);
|
||||||
|
@ -82,8 +82,8 @@ class Connection {
|
||||||
|
|
||||||
wsUrl() {
|
wsUrl() {
|
||||||
const params = [];
|
const params = [];
|
||||||
if (this.since > 0) {
|
if (this.since) {
|
||||||
params.push(`since=${this.since.toString()}`);
|
params.push(`since=${this.since}`);
|
||||||
}
|
}
|
||||||
if (this.user !== null) {
|
if (this.user !== null) {
|
||||||
const auth = encodeBase64Url(basicAuth(this.user.username, this.user.password));
|
const auth = encodeBase64Url(basicAuth(this.user.username, this.user.password));
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ConnectionManager {
|
||||||
const baseUrl = subscription.baseUrl;
|
const baseUrl = subscription.baseUrl;
|
||||||
const topic = subscription.topic;
|
const topic = subscription.topic;
|
||||||
const user = users.get(baseUrl);
|
const user = users.get(baseUrl);
|
||||||
const since = 0;
|
const since = subscription.last;
|
||||||
const connection = new Connection(id, baseUrl, topic, user, since, onNotification);
|
const connection = new Connection(id, baseUrl, topic, user, since, onNotification);
|
||||||
this.connections.set(id, connection);
|
this.connections.set(id, connection);
|
||||||
console.log(`[ConnectionManager] Starting new connection ${id}`);
|
console.log(`[ConnectionManager] Starting new connection ${id}`);
|
||||||
|
|
|
@ -6,15 +6,15 @@ class Subscription {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
this.notifications = new Map(); // notification ID -> notification object
|
this.notifications = new Map(); // notification ID -> notification object
|
||||||
this.last = 0;
|
this.last = null; // Last message ID
|
||||||
}
|
}
|
||||||
|
|
||||||
addNotification(notification) {
|
addNotification(notification) {
|
||||||
if (this.notifications.has(notification.id) || notification.time < this.last) {
|
if (this.notifications.has(notification.id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.notifications.set(notification.id, notification);
|
this.notifications.set(notification.id, notification);
|
||||||
this.last = notification.time;
|
this.last = notification.id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import notificationManager from "../app/NotificationManager";
|
||||||
// TODO user management
|
// TODO user management
|
||||||
// TODO embed into ntfy server
|
// TODO embed into ntfy server
|
||||||
// TODO remember selected subscription
|
// TODO remember selected subscription
|
||||||
// TODO since=<ID>
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
console.log(`[App] Rendering main view`);
|
console.log(`[App] Rendering main view`);
|
||||||
|
@ -70,7 +69,7 @@ const App = () => {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
const poll = (subscription, user) => {
|
const poll = (subscription, user) => {
|
||||||
const since = subscription.last + 1; // FIXME, sigh ...
|
const since = subscription.last;
|
||||||
api.poll(subscription.baseUrl, subscription.topic, since, user)
|
api.poll(subscription.baseUrl, subscription.topic, since, user)
|
||||||
.then(notifications => {
|
.then(notifications => {
|
||||||
setSubscriptions(prev => {
|
setSubscriptions(prev => {
|
||||||
|
|
Loading…
Reference in a new issue