1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-05 04:33:14 +02:00
This commit is contained in:
Philipp Heckel 2022-12-08 20:50:48 -05:00
parent 2e1ddc9ae1
commit 92bf7ebc52
11 changed files with 237 additions and 37 deletions

View file

@ -18,17 +18,43 @@ class SubscriptionManager {
}
async add(baseUrl, topic) {
const id = topicUrl(baseUrl, topic);
const existingSubscription = await this.get(id);
if (existingSubscription) {
return existingSubscription;
}
const subscription = {
id: topicUrl(baseUrl, topic),
baseUrl: baseUrl,
topic: topic,
mutedUntil: 0,
last: null
last: null,
remoteId: null
};
await db.subscriptions.put(subscription);
return subscription;
}
async syncFromRemote(remoteSubscriptions) {
// Add remote subscriptions
let remoteIds = [];
for (let i = 0; i < remoteSubscriptions.length; i++) {
const remote = remoteSubscriptions[i];
const local = await this.add(remote.base_url, remote.topic);
await this.setRemoteId(local.id, remote.id);
remoteIds.push(remote.id);
}
// Remove local subscriptions that do not exist remotely
const localSubscriptions = await db.subscriptions.toArray();
for (let i = 0; i < localSubscriptions.length; i++) {
const local = localSubscriptions[i];
if (local.remoteId && !remoteIds.includes(local.remoteId)) {
await this.remove(local.id);
}
}
}
async updateState(subscriptionId, state) {
db.subscriptions.update(subscriptionId, { state: state });
}
@ -139,6 +165,12 @@ class SubscriptionManager {
});
}
async setRemoteId(subscriptionId, remoteId) {
await db.subscriptions.update(subscriptionId, {
remoteId: remoteId
});
}
async pruneNotifications(thresholdTimestamp) {
await db.notifications
.where("time").below(thresholdTimestamp)