mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-05 04:33:14 +02:00
blerp
This commit is contained in:
parent
2e1ddc9ae1
commit
92bf7ebc52
11 changed files with 237 additions and 37 deletions
web/src/app
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue