Do not store notifications in localStorage anymore
This commit is contained in:
parent
effc1f42eb
commit
39f4613719
5 changed files with 26 additions and 36 deletions
|
@ -2,8 +2,9 @@ import {formatMessage, formatTitleWithFallback, topicShortUrl} from "./utils";
|
|||
import repository from "./Repository";
|
||||
|
||||
class NotificationManager {
|
||||
notify(subscription, notification, onClickFallback) {
|
||||
if (!this.shouldNotify(subscription, notification)) {
|
||||
async notify(subscription, notification, onClickFallback) {
|
||||
const shouldNotify = await this.shouldNotify(subscription, notification);
|
||||
if (!shouldNotify) {
|
||||
return;
|
||||
}
|
||||
const message = formatMessage(notification);
|
||||
|
@ -32,9 +33,10 @@ class NotificationManager {
|
|||
}
|
||||
}
|
||||
|
||||
shouldNotify(subscription, notification) {
|
||||
async shouldNotify(subscription, notification) {
|
||||
const priority = (notification.priority) ? notification.priority : 3;
|
||||
if (priority < repository.getMinPriority()) {
|
||||
const minPriority = await repository.getMinPriority();
|
||||
if (priority < minPriority) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -35,7 +35,6 @@ class Repository {
|
|||
return {
|
||||
baseUrl: subscription.baseUrl,
|
||||
topic: subscription.topic,
|
||||
notifications: subscription.getNotifications(),
|
||||
last: subscription.last
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -5,15 +5,13 @@ class Subscription {
|
|||
this.id = topicUrl(baseUrl, topic);
|
||||
this.baseUrl = baseUrl;
|
||||
this.topic = topic;
|
||||
this.notifications = new Map(); // notification ID -> notification object
|
||||
this.last = null; // Last message ID
|
||||
}
|
||||
|
||||
addNotification(notification) {
|
||||
if (!notification.event || notification.event !== 'message' || this.notifications.has(notification.id)) {
|
||||
if (!notification.event || notification.event !== 'message') {
|
||||
return false;
|
||||
}
|
||||
this.notifications.set(notification.id, notification);
|
||||
this.last = notification.id;
|
||||
return true;
|
||||
}
|
||||
|
@ -23,22 +21,6 @@ class Subscription {
|
|||
return this;
|
||||
}
|
||||
|
||||
deleteNotification(notificationId) {
|
||||
this.notifications.delete(notificationId);
|
||||
return this;
|
||||
}
|
||||
|
||||
deleteAllNotifications() {
|
||||
for (const [id] of this.notifications) {
|
||||
this.deleteNotification(id);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
getNotifications() {
|
||||
return Array.from(this.notifications.values());
|
||||
}
|
||||
|
||||
url() {
|
||||
return topicUrl(this.baseUrl, this.topic);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue