Remove mui/styles, Settings page, make minPriority functional, ahh so ugly

This commit is contained in:
Philipp Heckel 2022-03-01 16:22:47 -05:00
parent f23c7a2dbf
commit 8036aa2942
9 changed files with 265 additions and 60 deletions

View file

@ -1,7 +1,11 @@
import {formatMessage, formatTitleWithFallback, topicShortUrl} from "./utils";
import repository from "./Repository";
class NotificationManager {
notify(subscription, notification, onClickFallback) {
if (!this.shouldNotify(subscription, notification)) {
return;
}
const message = formatMessage(notification);
const title = formatTitleWithFallback(notification, topicShortUrl(subscription.baseUrl, subscription.topic));
const n = new Notification(title, {
@ -27,6 +31,14 @@ class NotificationManager {
});
}
}
shouldNotify(subscription, notification) {
const priority = (notification.priority) ? notification.priority : 3;
if (priority < repository.getMinPriority()) {
return false;
}
return true;
}
}
const notificationManager = new NotificationManager();

View file

@ -87,6 +87,24 @@ class Repository {
console.log(`[Repository] Saving selected subscription ${selectedSubscriptionId} to localStorage`);
localStorage.setItem('selectedSubscriptionId', selectedSubscriptionId);
}
setMinPriority(minPriority) {
localStorage.setItem('minPriority', minPriority.toString());
}
getMinPriority() {
const minPriority = localStorage.getItem('minPriority');
return (minPriority) ? Number(minPriority) : 1;
}
setDeleteAfter(deleteAfter) {
localStorage.setItem('deleteAfter', deleteAfter.toString());
}
getDeleteAfter() {
const deleteAfter = localStorage.getItem('deleteAfter');
return (deleteAfter) ? Number(deleteAfter) : 604800; // Default is one week
}
}
const repository = new Repository();

View file

@ -10,7 +10,7 @@ class Subscription {
}
addNotification(notification) {
if (this.notifications.has(notification.id)) {
if (!notification.event || notification.event !== 'message' || this.notifications.has(notification.id)) {
return false;
}
this.notifications.set(notification.id, notification);